7 #ifndef PXR_BASE_TF_ENUM_H
8 #define PXR_BASE_TF_ENUM_H
25 #include <type_traits>
124 : _typeInfo(&typeid(
int)), _value(0)
132 : _typeInfo(&typeid(
T)), _value(
int(value))
142 : _typeInfo(&ti), _value(value)
148 return t._value == _value &&
155 return !(*
this ==
t);
163 return _typeInfo->before(*t._typeInfo) ||
164 (!t._typeInfo->before(*_typeInfo) && _value < t._value);
189 return int(value) == _value && IsA<T>();
196 return int(value) != _value || !IsA<T>();
221 bool IsA(
const std::type_info&
t)
const {
246 template <
typename T>
249 _FatalGetValueError(
typeid(
T));
255 template <
typename T,
256 typename =
typename std::enable_if<
325 static const std::type_info *
GetTypeFromName(
const std::string& typeName);
343 const std::string &
name,
344 bool *foundIt = NULL);
357 bool *foundIt = NULL);
375 char const *displayName);
384 const std::string &displayName=
"")
386 _AddName(val, valName.c_str(), displayName.c_str());
389 template <
typename T>
392 e._typeInfo = &
typeid(
T);
393 e._value =
int(value);
400 : _typeInfo(&typeid(
int)), _value(value)
406 : _typeInfo(&typeid(size_t)), _value(static_cast<
int>(value))
411 void _FatalGetValueError(std::type_info
const& typeInfo)
const;
413 const std::type_info* _typeInfo;
420 template <
class HashState,
class Enum>
425 h.Append(e.GetValueAsInt());
457 #define TF_ADD_ENUM_NAME(VAL, ...) \
458 TfEnum::_AddName(VAL, TF_PP_STRINGIZE(VAL), \
459 TfEnum::_NameIdent(__VA_ARGS__));
463 #endif // PXR_BASE_TF_ENUM_H
static TF_API bool IsKnownEnumType(const std::string &typeName)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
typename std::enable_if< B, T >::type enable_if_t
Define Imath::enable_if_t to be std for C++14, equivalent for C++11.
TfEnum(const std::type_info &ti, int value)
TfCStrHashWrapper TfHashAsCStr(char const *cstr)
bool operator>(const TfEnum &t) const
friend std::enable_if_t< std::is_enum< T >::value, bool > operator!=(T val, TfEnum const &e)
Compare a literal enum value val of enum type T with TfEnum e.
static std::vector< std::string > GetAllNames(TfEnum val)
bool operator>=(const TfEnum &t) const
TfEnum()
Default constructor assigns integer value zero.
GLsizei const GLfloat * value
static TF_API const std::type_info * GetTypeFromName(const std::string &typeName)
bool operator<=(const TfEnum &t) const
std::enable_if_t< std::is_same< Enum, TfEnum >::value > TfHashAppend(HashState &h, Enum const &e)
GLint GLint GLsizei GLint GLenum GLenum type
static char const * _NameIdent(char const *str=nullptr)
static std::vector< std::string > GetAllNames()
const std::type_info & GetType() const
Returns the type of the enum value, as an std::type_info.
static TF_API std::string GetFullName(TfEnum val)
const int & GetValueAsInt() const
Returns the integral value of the enum value.
GLuint const GLchar * name
static void AddName(TfEnum val, const std::string &valName, const std::string &displayName="")
bool IsA(const std::type_info &t) const
TfEnum(T value, std::enable_if_t< std::is_enum< T >::value > *=0)
Initializes value to enum variable value of enum type T.
static TF_API TfEnum GetValueFromFullName(const std::string &fullname, bool *foundIt=NULL)
GLfloat GLfloat GLfloat GLfloat h
friend std::enable_if_t< std::is_enum< T >::value, bool > operator==(T val, TfEnum const &e)
Compare a literal enum value val of enum type T with TfEnum e.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
TF_API std::ostream & operator<<(std::ostream &out, const TfEnum &e)
static TF_API std::string GetDisplayName(TfEnum val)
bool operator==(const TfEnum &t) const
True if *this and t have both the same type and value.
#define PXR_NAMESPACE_CLOSE_SCOPE
std::enable_if_t< std::is_enum< T >::value, bool > operator==(T value) const
True if *this has been assigned with value.
static TF_API std::string GetName(TfEnum val)
PXR_NAMESPACE_OPEN_SCOPE bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
static TfEnum IntegralEnum(T value)
static T GetValueFromName(const std::string &name, bool *foundIt=NULL)
bool IsA() const
True if *this has been assigned any enumerated value of type T.
bool operator!=(const TfEnum &t) const
bool operator<(const TfEnum &t) const
static TF_API void _AddName(TfEnum val, char const *valName, char const *displayName)
std::enable_if_t< std::is_enum< T >::value, bool > operator!=(T value) const
False if *this has been assigned with value.