24 #ifndef PXR_BASE_TF_PY_ENUM_H
25 #define PXR_BASE_TF_PY_ENUM_H
45 #include <hboost/python/class.hpp>
46 #include <hboost/python/converter/from_python.hpp>
47 #include <hboost/python/converter/registered.hpp>
48 #include <hboost/python/converter/rvalue_from_python_data.hpp>
49 #include <hboost/python/list.hpp>
50 #include <hboost/python/object.hpp>
51 #include <hboost/python/operators.hpp>
52 #include <hboost/python/refcount.hpp>
53 #include <hboost/python/scope.hpp>
54 #include <hboost/python/to_python_converter.hpp>
55 #include <hboost/python/tuple.hpp>
92 hboost::python::to_python_converter<T, _EnumToPython<T> >();
99 struct _EnumFromPython {
102 (&convertible, &construct, hboost::python::type_id<T>());
104 static void *convertible(PyObject *
obj) {
114 return i != o2e.
end() ? obj : 0;
116 return (i != o2e.
end() && i->second.IsA<
T>()) ? obj : 0;
118 static void construct(PyObject *
src, hboost::python::converter::
119 rvalue_from_python_stage1_data *
data) {
121 ((hboost::python::converter::
122 rvalue_from_python_storage<T> *)data)->storage.bytes;
123 new (
storage)
T(_GetEnumValue(src, (
T *)0));
129 template <
typename U>
130 static U _GetEnumValue(PyObject *src, U *) {
139 template <
typename T>
140 struct _EnumToPython {
147 size_t operator()(PyObject *o)
const {
148 return reinterpret_cast<size_t>(o);
166 :
public Tf_PyEnum, hboost::totally_ordered<Tf_PyEnumWrapper>
173 return value.GetValueAsInt();
186 return self.value.GetValueAsInt() == other;
273 template <
typename T>
287 name =
"AutoGenerated_" + name +
"_" +
298 return hboost::python::
304 template <
typename T>
378 typedef hboost::python::class_<
390 using namespace hboost::python;
392 const bool explicitName = !
name.empty();
401 if (baseName == enumName)
411 if (!baseName.empty())
420 if (!baseName.empty()) {
423 baseName += enumName;
427 _EnumPyClassType enumClass(enumName.c_str(), no_init);
429 enumClass.staticmethod(
"GetValueFromName");
430 enumClass.setattr(
"_baseName", baseName);
437 _ExportValues(baseName.empty(), enumClass);
443 if (!
type.IsUnknown())
444 type.DefinePythonClass(enumClass);
452 void _ExportValues(
bool cleanNames, _EnumPyClassType &enumClass) {
453 hboost::python::list valueList;
455 std::vector<std::string>
names = TfEnum::GetAllNames<T>();
457 bool success =
false;
458 TfEnum enumValue = TfEnum::GetValueFromName<T>(*
name, &success);
477 hboost::python::scope
s(enumClass);
481 hboost::python::scope
s;
485 valueList.append(pyValue);
489 enumClass.setattr(
"allValues", hboost::python::tuple(valueList));
496 #endif // PXR_BASE_TF_PY_ENUM_H
vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
TfPyWrapEnum(std::string const &name=std::string())
GLuint const GLchar * name
Tf_PyEnumWrapper(std::string const &n, TfEnum const &val)
GLuint const GLfloat * val
TF_API std::string TfStringGetSuffix(const std::string &name, char delimiter= '.')
internal::named_arg< T, char > arg(string_view name, const T &arg)
TF_API void RegisterValue(TfEnum const &e, hboost::python::object const &obj)
ARCH_API std::string ArchGetDemangled(const std::string &typeName)
std::string GetFullName() const
Tf_TypedPyEnumWrapper(std::string const &n, TfEnum const &val)
Tto convert(const Tfrom &source)
friend TfEnum operator|(Tf_PyEnumWrapper const &lhs, Tf_PyEnumWrapper const &rhs)
friend bool operator<(Tf_PyEnumWrapper const &lhs, Tf_PyEnumWrapper const &rhs)
friend TfEnum operator^(Tf_PyEnumWrapper const &lhs, Tf_PyEnumWrapper const &rhs)
TF_API std::string Tf_PyCleanEnumName(std::string name)
friend bool operator==(Tf_PyEnumWrapper const &self, long other)
GLint GLenum GLsizei GLint GLsizei const void * data
const std::type_info & GetType() const
Returns the type of the enum value, as an std::type_info.
void RegisterEnumConversions()
static TF_API This & GetInstance()
GLuint const GLuint * names
static TF_API std::string GetFullName(TfEnum val)
TF_API_TEMPLATE_CLASS(TfSingleton< Tf_PyEnumRegistry >)
const int & GetValueAsInt() const
Returns the integral value of the enum value.
GLuint GLuint GLsizei GLenum type
friend TfEnum operator&(Tf_PyEnumWrapper const &lhs, Tf_PyEnumWrapper const &rhs)
friend TfEnum operator~(Tf_PyEnumWrapper const &rhs)
GLsizei const GLchar *const * string
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
static TF_API std::string GetDisplayName(TfEnum val)
#define PXR_NAMESPACE_CLOSE_SCOPE
TF_API void TfPyThrowTypeError(std::string const &msg)
TF_API void Tf_PyEnumAddAttribute(hboost::python::scope &s, const std::string &name, const hboost::python::object &value)
getOption("OpenEXR.storage") storage
std::string GetDisplayName() const
static hboost::python::object GetValueFromName(const std::string &name)
#define TF_FOR_ALL(iter, c)
std::string GetName() const
TF_API std::string TfStringGetBeforeSuffix(const std::string &name, char delimiter= '.')
std::enable_if<!std::is_enum< T >::value, std::string >::type TfStringify(const T &v)
TF_API std::string Tf_PyEnumRepr(hboost::python::object const &self)
bool IsA() const
True if *this has been assigned any enumerated value of type T.
GLsizei const GLfloat * value
TF_API std::string TfStringReplace(const std::string &source, const std::string &from, const std::string &to)