Inherits totally_ordered< TfEnum >.
|
| TfEnum () |
| Default constructor assigns integer value zero. More...
|
|
template<class T > |
| TfEnum (T value, std::enable_if_t< std::is_enum< T >::value > *=0) |
| Initializes value to enum variable value of enum type T . More...
|
|
| TfEnum (const std::type_info &ti, int value) |
| Initializes value to integral value value with enum type ti . More...
|
|
bool | operator== (const TfEnum &t) const |
| True if *this and t have both the same type and value. More...
|
|
bool | operator< (const TfEnum &t) const |
| Less than comparison. More...
|
|
template<class T > |
std::enable_if_t< std::is_enum< T >::value, bool > | operator== (T value) const |
| True if *this has been assigned with value . More...
|
|
template<class T > |
std::enable_if_t< std::is_enum< T >::value, bool > | operator!= (T value) const |
| False if *this has been assigned with value . More...
|
|
template<class T > |
bool | IsA () const |
| True if *this has been assigned any enumerated value of type T . More...
|
|
bool | IsA (const std::type_info &t) const |
| True if *this has been assigned any enumerated value of type T with typeid(T)==t . More...
|
|
const std::type_info & | GetType () const |
| Returns the type of the enum value, as an std::type_info . More...
|
|
const int & | GetValueAsInt () const |
| Returns the integral value of the enum value. More...
|
|
template<typename T > |
T | GetValue () const |
| Returns the enum value for the enum type T . More...
|
|
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value || std::is_enum<T>::value>::type> |
| operator T () const |
| Conversion operator for enum and integral types only. More...
|
|
|
static TF_API void | _AddName (TfEnum val, const std::string &valName, const std::string &displayName="") |
| Associates a name with an enumerated value. More...
|
|
static void | AddName (TfEnum val, const std::string &valName, const std::string &displayName="") |
| Associates a name with an enumerated value. More...
|
|
template<typename T > |
static TfEnum | IntegralEnum (T value) |
|
|
The methods in this group can be used to retrieve corresponding names and values.
The correspondences are set up with the TF_ADD_ENUM_NAME() macro.
|
static TF_API std::string | GetName (TfEnum val) |
| Returns the name associated with an enumerated value. More...
|
|
static TF_API std::string | GetFullName (TfEnum val) |
| Returns the fully-qualified name for an enumerated value. More...
|
|
static TF_API std::string | GetDisplayName (TfEnum val) |
| Returns the display name for an enumerated value. More...
|
|
static std::vector< std::string > | GetAllNames (TfEnum val) |
| Returns a vector of all the names associated with an enum type. More...
|
|
static TF_API std::vector< std::string > | GetAllNames (const std::type_info &ti) |
|
template<class T > |
static std::vector< std::string > | GetAllNames () |
| Returns a vector of all the names associated with an enum type. More...
|
|
static TF_API const std::type_info * | GetTypeFromName (const std::string &typeName) |
| Returns the typeid for a given enum type name. More...
|
|
template<class T > |
static T | GetValueFromName (const std::string &name, bool *foundIt=NULL) |
| Returns the enumerated value for a name. More...
|
|
static TF_API TfEnum | GetValueFromName (const std::type_info &ti, const std::string &name, bool *foundIt=NULL) |
| Returns the enumerated value for a name. More...
|
|
static TF_API TfEnum | GetValueFromFullName (const std::string &fullname, bool *foundIt=NULL) |
| Returns the enumerated value for a fully-qualified name. More...
|
|
static TF_API bool | IsKnownEnumType (const std::string &typeName) |
| Returns true if typeName is a known enum type. More...
|
|
An enum class that records both enum type and enum value.
Run-Time Typing
A TfEnum
can hold an enum variable of any enum type, while still being able to distinguish between various enum types. Here is an example:
enum Monsters { SULLEY = 0, MIKE, ROZ };
enum Fish { NEMO = 0, FATHER, DORY };
t2 = NEMO;
t1 == MIKE;
t2 == NEMO;
t1 == t2;
t1 == SULLEY;
Even though NEMO
and SULLEY
both are represented with integral value zero, t1
and t2
compare false. A TfEnum
can be passed by value, assigned, etc. just like a regular Enum
variable. A TfEnum
can also hold a plain integer, which will compare false against any other enum variable.
Associating Names with Enumerated Values
The TfEnum
class can also be used to represent enumerated values as strings. This can be useful for storing enum values in files for later retrieval.
Use the TF_ADD_ENUM_NAME()
macro to set up and enable strings for the values of an enum. Once this is done, several static TfEnum
methods may be used to look up names corresponding to enum values and vice-versa.
For example, see TfRegistryManager
to understand the use of the TF_REGISTRY_FUNCTION()
macro below:
Enum Registration Macro
enum Season {
SPRING,
SUMMER = 3,
AUTUMN,
WINTER
};
}
bool found;
Season s1 = TfEnum::GetValueFromName<Season>("AUTUMN", &found);
Season s2 = TfEnum::GetValueFromName<Season>("MONDAY", &found);
Definition at line 139 of file enum.h.
static std::vector<std::string> GetAllNames |
( |
TfEnum |
val | ) |
|
|
inlinestatic |
Returns a vector of all the names associated with an enum type.
This returns a vector of all the names associated with the enum that contains the type val
. The names are not fully qualified. For example, TfEnum::GetAllNames(WINTER)
would return a vector containing "SPRING", "SUMMER", "AUTUMN", and "WINTER".
If there are no such names registered, an empty vector is returned.
Definition at line 295 of file enum.h.
static std::vector<std::string> GetAllNames |
( |
| ) |
|
|
inlinestatic |
Returns a vector of all the names associated with an enum type.
This returns a vector of all the names associated with the enum type T
. The names are not fully qualified. For example, TfEnum::GetAllNames<Season>()
would return a vector containing "SPRING", "SUMMER", "AUTUMN", and "WINTER".
If there are no such names registered, an empty vector is returned.
Definition at line 311 of file enum.h.
static TF_API TfEnum GetValueFromFullName |
( |
const std::string & |
fullname, |
|
|
bool * |
foundIt = NULL |
|
) |
| |
|
static |
Returns the enumerated value for a fully-qualified name.
This takes a fully-qualified enumerated value name (e.g., "Season::WINTER"
) and returns the associated value. If there is no such name, this returns -1. Since -1 can sometimes be a valid value, the foundIt
flag pointer, if not NULL
, is set to true
if the name was found and false
otherwise. Also, since this is not a templated function, it has to return a generic value type, so we use TfEnum
.