Enumeration string mapping template class. More...

#include "murl_enum.h"

Classes

struct  Item
 Definition of an Enum initialization item. More...
 

Public Types

using ValueType = EnumType
 The template parameter value type.
 

Public Member Functions

 Enum (const Item *items, const UInt32 numberOfElements)
 Constructor taking an array of enum items. More...
 
 Enum (const String &name, const Item *items, const UInt32 numberOfElements)
 Constructor taking an enumeration name and an array of enum items. More...
 
 Enum (const String &name, EnumContainer &container, const Item *items, const UInt32 numberOfElements)
 Constructor taking an array of enum items and a container. More...
 
 Enum (const Enum &other)
 Copy constructor. More...
 
 ~Enum ()
 Destructor.
 
Enumoperator= (const Enum &other)
 Assignment operator. More...
 
const StringGetName () const
 Get the name of the enumerator. More...
 
EnumType GetDefaultValue () const
 Get the default enumeration value. More...
 
UInt32 GetCount () const
 Get the total number of enumeration entries. More...
 
Bool IsEnumValueAvailable (EnumType value) const
 Check if an enumeration value is available. More...
 
Bool IsEnumNameAvailable (const String &name) const
 Check if an enumeration name is available. More...
 
SInt32 GetEnumIndexByValue (EnumType value) const
 Get the zero-based index of an enumeration value. More...
 
SInt32 GetEnumIndexByValue (EnumType value, UInt32 hash) const
 Get the zero-based index of an enumeration value. More...
 
SInt32 GetEnumIndexByName (const String &name) const
 Get the zero-based index of an enumeration name. More...
 
SInt32 GetEnumIndexByName (const String &name, UInt32 hash) const
 Get the zero-based index of an enumeration name. More...
 
const StringGetEnumNameByIndex (UInt32 index) const
 Get the enumeration name at a given index. More...
 
EnumType GetEnumValueByIndex (UInt32 index) const
 Get the enumeration value at a given index. More...
 
const StringGetEnumNameByValue (EnumType value, Bool &error, Bool clearError) const
 Get the enumeration name for a given enumeration value. More...
 
const StringGetEnumNameByValue (EnumType value, Bool &error) const
 Get the enumeration name for a given enumeration value. More...
 
const StringGetEnumNameByValue (EnumType value) const
 Get the enumeration name for a given enumeration value. More...
 
EnumType GetEnumValueByName (const String &name, Bool &error, Bool clearError) const
 Get the enumeration value for a given enumeration name. More...
 
EnumType GetEnumValueByName (const String &name, Bool &error) const
 Get the enumeration value for a given enumeration name. More...
 
EnumType GetEnumValueByName (const String &name) const
 Get the enumeration value for a given enumeration name. More...
 
const StringGetEnumNameByValue (EnumType value, UInt32 hash, Bool &error, Bool clearError) const
 Get the enumeration name for a given enumeration value, using a precomputed hash value. More...
 
const StringGetEnumNameByValue (EnumType value, UInt32 hash, Bool &error) const
 Get the enumeration name for a given enumeration value, using a precomputed hash value. More...
 
const StringGetEnumNameByValue (EnumType value, UInt32 hash) const
 Get the enumeration name for a given enumeration value, using a precomputed hash value. More...
 
EnumType GetEnumValueByName (const String &name, UInt32 hash, Bool &error, Bool clearError) const
 Get the enumeration value for a given enumeration name, using a precomputed hash value. More...
 
EnumType GetEnumValueByName (const String &name, UInt32 hash, Bool &error) const
 Get the enumeration value for a given enumeration name, using a precomputed hash value. More...
 
EnumType GetEnumValueByName (const String &name, UInt32 hash) const
 Get the enumeration value for a given enumeration name, using a precomputed hash value. More...
 
const Map< String, UInt32 > & GetItemsByName () const
 Get the enumeration values by name map. More...
 
const Map< UInt32, String > & GetItemsByValue () const
 Get the names by enumeration value map. More...
 
 operator const Enum< SInt32 > & () const
 Conversion operator. More...
 

Protected Attributes

Map< String, UInt32mItemsByName
 The enumeration values by name map.
 
Map< UInt32, StringmItemsByValue
 The names by enumeration value map.
 
EnumType mDefaultValue
 The default enumeration value.
 
String mName
 The name of the enumerator.
 
EnumContainermEnumContainer
 The optional container.
 

Detailed Description

template<class EnumType>
class Murl::Enum< EnumType >

Enumeration string mapping template class.

Constructor & Destructor Documentation

◆ Enum() [1/4]

template<class EnumType >
Murl::Enum< EnumType >::Enum ( const Item items,
const UInt32  numberOfElements 
)
inline

Constructor taking an array of enum items.

Parameters
itemsPointer to an array of initialization items. If the item's mName has a null pointer, the mValue is the default value.
numberOfElementsThe number of elements in the array. The macro NUMBER_OF_ARRAY_ELEMENTS can be used to determine the number.

◆ Enum() [2/4]

template<class EnumType >
Murl::Enum< EnumType >::Enum ( const String name,
const Item items,
const UInt32  numberOfElements 
)
inline

Constructor taking an enumeration name and an array of enum items.

Parameters
nameThe enumeration's name.
itemsPointer to an array of initialization items. If the item's mName has a null pointer, the mValue is the default value.
numberOfElementsThe number of elements in the array. The macro NUMBER_OF_ARRAY_ELEMENTS can be used to determine the number.

◆ Enum() [3/4]

template<class EnumType >
Murl::Enum< EnumType >::Enum ( const String name,
EnumContainer container,
const Item items,
const UInt32  numberOfElements 
)
inline

Constructor taking an array of enum items and a container.

Parameters
nameThe enumeration's name.
containerThe container to add this enumeration to.
itemsPointer to an array of initialization items. If the item's mName has a null pointer, the mValue is the default value.
numberOfElementsThe number of elements in the array. The macro NUMBER_OF_ARRAY_ELEMENTS can be used to determine the number.

References Murl::EnumContainer::Add().

◆ Enum() [4/4]

template<class EnumType >
Murl::Enum< EnumType >::Enum ( const Enum< EnumType > &  other)
inline

Copy constructor.

Parameters
otherThe enumeration to copy.

Member Function Documentation

◆ operator=()

template<class EnumType >
Enum& Murl::Enum< EnumType >::operator= ( const Enum< EnumType > &  other)
inline

◆ GetName()

template<class EnumType >
const String& Murl::Enum< EnumType >::GetName ( ) const
inline

Get the name of the enumerator.

Returns
The name of the enumerator.

References Murl::Enum< EnumType >::mName.

◆ GetDefaultValue()

template<class EnumType >
EnumType Murl::Enum< EnumType >::GetDefaultValue ( ) const
inline

Get the default enumeration value.

Returns
The default value.

References Murl::Enum< EnumType >::mDefaultValue.

◆ GetCount()

template<class EnumType >
UInt32 Murl::Enum< EnumType >::GetCount ( ) const
inline

Get the total number of enumeration entries.

Returns
The number of entries.

References Murl::Enum< EnumType >::mItemsByName.

◆ IsEnumValueAvailable()

template<class EnumType >
Bool Murl::Enum< EnumType >::IsEnumValueAvailable ( EnumType  value) const
inline

Check if an enumeration value is available.

Parameters
valueThe enumeration value to check.
Returns
true if the enumeration value is available.

References Murl::Enum< EnumType >::mItemsByValue.

◆ IsEnumNameAvailable()

template<class EnumType >
Bool Murl::Enum< EnumType >::IsEnumNameAvailable ( const String name) const
inline

Check if an enumeration name is available.

Parameters
nameThe enumeration name to check.
Returns
true if the enumeration name is available.

References Murl::Enum< EnumType >::mItemsByName.

◆ GetEnumIndexByValue() [1/2]

template<class EnumType >
SInt32 Murl::Enum< EnumType >::GetEnumIndexByValue ( EnumType  value) const
inline

Get the zero-based index of an enumeration value.

Parameters
valueThe enumeration value to check.
Returns
The index in the range from 0 to GetCount()-1, or -1 if not found.

References Murl::Enum< EnumType >::mItemsByValue.

◆ GetEnumIndexByValue() [2/2]

template<class EnumType >
SInt32 Murl::Enum< EnumType >::GetEnumIndexByValue ( EnumType  value,
UInt32  hash 
) const
inline

Get the zero-based index of an enumeration value.

Parameters
valueThe enumeration value to check.
hashThe precomputed hash value.
Returns
The index in the range from 0 to GetCount()-1, or -1 if not found.

References Murl::Enum< EnumType >::mItemsByValue.

◆ GetEnumIndexByName() [1/2]

template<class EnumType >
SInt32 Murl::Enum< EnumType >::GetEnumIndexByName ( const String name) const
inline

Get the zero-based index of an enumeration name.

Parameters
nameThe enumeration name to check.
Returns
The index in the range from 0 to GetCount()-1, or -1 if not found.

References Murl::Enum< EnumType >::mItemsByName.

◆ GetEnumIndexByName() [2/2]

template<class EnumType >
SInt32 Murl::Enum< EnumType >::GetEnumIndexByName ( const String name,
UInt32  hash 
) const
inline

Get the zero-based index of an enumeration name.

Parameters
nameThe enumeration name to check.
hashThe precomputed hash value.
Returns
The index in the range from 0 to GetCount()-1, or -1 if not found.

References Murl::Enum< EnumType >::mItemsByName.

◆ GetEnumNameByIndex()

template<class EnumType >
const String& Murl::Enum< EnumType >::GetEnumNameByIndex ( UInt32  index) const
inline

Get the enumeration name at a given index.

Parameters
indexThe index to query, in the range from 0 to GetCount()-1.
Returns
The enumeration name, or an empty string if index is out of range.

References Murl::Enum< EnumType >::mItemsByValue, and Murl::Util::StaticEmptyString().

◆ GetEnumValueByIndex()

template<class EnumType >
EnumType Murl::Enum< EnumType >::GetEnumValueByIndex ( UInt32  index) const
inline

Get the enumeration value at a given index.

Parameters
indexThe index to query, in the range from 0 to GetCount()-1.
Returns
The enumeration value, or the default value if index is out of range.

References Murl::Enum< EnumType >::mDefaultValue, and Murl::Enum< EnumType >::mItemsByName.

◆ GetEnumNameByValue() [1/6]

template<class EnumType >
const String& Murl::Enum< EnumType >::GetEnumNameByValue ( EnumType  value,
Bool error,
Bool  clearError 
) const
inline

Get the enumeration name for a given enumeration value.

Parameters
valueThe enumeration value to look up.
errorThe error return value is set to true if the value is not found.
clearErrorIf false, the error parameter is left in its given state if no error occurred.
Returns
The string of the enumeration value or an empty string if the value is not found.

References Murl::Enum< EnumType >::mItemsByValue, and Murl::Util::StaticEmptyString().

Referenced by Murl::Enum< EnumType >::GetEnumNameByValue().

◆ GetEnumNameByValue() [2/6]

template<class EnumType >
const String& Murl::Enum< EnumType >::GetEnumNameByValue ( EnumType  value,
Bool error 
) const
inline

Get the enumeration name for a given enumeration value.

Parameters
valueThe enumeration value to look up.
errorThe error return value is set to true if the value is not found, or false if OK.
Returns
The string of the enumeration value or an empty string if the value is not found.

References Murl::Enum< EnumType >::GetEnumNameByValue().

◆ GetEnumNameByValue() [3/6]

template<class EnumType >
const String& Murl::Enum< EnumType >::GetEnumNameByValue ( EnumType  value) const
inline

Get the enumeration name for a given enumeration value.

Parameters
valueThe enumeration value to look up.
Returns
The string of the enumeration value or an empty string if the value is not found.

References Murl::Enum< EnumType >::GetEnumNameByValue().

◆ GetEnumValueByName() [1/6]

template<class EnumType >
EnumType Murl::Enum< EnumType >::GetEnumValueByName ( const String name,
Bool error,
Bool  clearError 
) const
inline

Get the enumeration value for a given enumeration name.

Parameters
nameThe name string to look up.
errorThe error return value is set to true if the name is not found.
clearErrorIf false, the error parameter is left in its given state if no error occurred.
Returns
The enumeration value of the string or the default value if the string is not found.

References Murl::Enum< EnumType >::mDefaultValue, and Murl::Enum< EnumType >::mItemsByName.

Referenced by Murl::IAttributes::GetEnumBitsToSetByIndex(), Murl::IAttributes::GetEnumValueByIndex(), Murl::Enum< EnumType >::GetEnumValueByName(), and Murl::IAttributes::GetEnumValuesByIndex().

◆ GetEnumValueByName() [2/6]

template<class EnumType >
EnumType Murl::Enum< EnumType >::GetEnumValueByName ( const String name,
Bool error 
) const
inline

Get the enumeration value for a given enumeration name.

Parameters
nameThe name string to look up.
errorThe error return value is set to true if the value is not found, or false if OK.
Returns
The enumeration value of the string or the default value if the string is not found.

References Murl::Enum< EnumType >::GetEnumValueByName().

◆ GetEnumValueByName() [3/6]

template<class EnumType >
EnumType Murl::Enum< EnumType >::GetEnumValueByName ( const String name) const
inline

Get the enumeration value for a given enumeration name.

Parameters
nameThe name string to look up.
Returns
The enumeration value of the string or the default value if the string is not found.

References Murl::Enum< EnumType >::GetEnumValueByName().

◆ GetEnumNameByValue() [4/6]

template<class EnumType >
const String& Murl::Enum< EnumType >::GetEnumNameByValue ( EnumType  value,
UInt32  hash,
Bool error,
Bool  clearError 
) const
inline

Get the enumeration name for a given enumeration value, using a precomputed hash value.

Parameters
valueThe enumeration value to look up.
hashThe precomputed hash value.
errorThe error return value is set to true if the value is not found.
clearErrorIf false, the error parameter is left in its given state if no error occurred.
Returns
The string of the enumeration value or an empty string if the value is not found.

References Murl::Enum< EnumType >::mItemsByValue, and Murl::Util::StaticEmptyString().

◆ GetEnumNameByValue() [5/6]

template<class EnumType >
const String& Murl::Enum< EnumType >::GetEnumNameByValue ( EnumType  value,
UInt32  hash,
Bool error 
) const
inline

Get the enumeration name for a given enumeration value, using a precomputed hash value.

Parameters
valueThe enumeration value to look up.
hashThe precomputed hash value.
errorThe error return value is set to true if the value is not found, or false if OK.
Returns
The string of the enumeration value or an empty string if the value is not found.

References Murl::Enum< EnumType >::GetEnumNameByValue().

◆ GetEnumNameByValue() [6/6]

template<class EnumType >
const String& Murl::Enum< EnumType >::GetEnumNameByValue ( EnumType  value,
UInt32  hash 
) const
inline

Get the enumeration name for a given enumeration value, using a precomputed hash value.

Parameters
valueThe enumeration value to look up.
hashThe precomputed hash value.
Returns
The string of the enumeration value or an empty string if the value is not found.

References Murl::Enum< EnumType >::GetEnumNameByValue().

◆ GetEnumValueByName() [4/6]

template<class EnumType >
EnumType Murl::Enum< EnumType >::GetEnumValueByName ( const String name,
UInt32  hash,
Bool error,
Bool  clearError 
) const
inline

Get the enumeration value for a given enumeration name, using a precomputed hash value.

Parameters
nameThe name string to look up.
hashThe precomputed hash value.
errorThe error return value is set to true if the name is not found.
clearErrorIf false, the error parameter is left in its given state if no error occurred.
Returns
The enumeration value of the string or the default value if the string is not found.

References Murl::Enum< EnumType >::mDefaultValue, and Murl::Enum< EnumType >::mItemsByName.

◆ GetEnumValueByName() [5/6]

template<class EnumType >
EnumType Murl::Enum< EnumType >::GetEnumValueByName ( const String name,
UInt32  hash,
Bool error 
) const
inline

Get the enumeration value for a given enumeration name, using a precomputed hash value.

Parameters
nameThe name string to look up.
hashThe precomputed hash value.
errorThe error return value is set to true if the value is not found, or false if OK.
Returns
The enumeration value of the string or the default value if the string is not found.

References Murl::Enum< EnumType >::GetEnumValueByName().

◆ GetEnumValueByName() [6/6]

template<class EnumType >
EnumType Murl::Enum< EnumType >::GetEnumValueByName ( const String name,
UInt32  hash 
) const
inline

Get the enumeration value for a given enumeration name, using a precomputed hash value.

Parameters
nameThe name string to look up.
hashThe precomputed hash value.
Returns
The enumeration value of the string or the default value if the string is not found.

References Murl::Enum< EnumType >::GetEnumValueByName().

◆ GetItemsByName()

template<class EnumType >
const Map<String, UInt32>& Murl::Enum< EnumType >::GetItemsByName ( ) const
inline

Get the enumeration values by name map.

Returns
The enumeration values by name map.

References Murl::Enum< EnumType >::mItemsByName.

◆ GetItemsByValue()

template<class EnumType >
const Map<UInt32, String>& Murl::Enum< EnumType >::GetItemsByValue ( ) const
inline

Get the names by enumeration value map.

Returns
The names by enumeration value map.

References Murl::Enum< EnumType >::mItemsByValue.

◆ operator const Enum< SInt32 > &()

template<class EnumType >
Murl::Enum< EnumType >::operator const Enum< SInt32 > & ( ) const
inline

Conversion operator.

Returns
This Enum instance with SInt32 specialization.

The documentation for this class was generated from the following file:
  • murl_enum.h


Copyright © 2011-2024 Spraylight GmbH.