The EnumType is designed to satisfy the requirements of C++ style enumerations. In this way an Enumeration object can be used to describe an enumeration, i.e. its elements, as well as holding its value, which must be in the range described by its elements.
Following methods are provided for elements management:
void addElement (const Element* e);
Add a new element to the enumeration list. This element should have the index set. Take care that the Element object must be created with new.
void addNewValue (const String& pValue);
Add a new value to the enumeration list. This function sets the element index to the last element’s index incremented by one.
int deleteElement (const String& pValue);
int deleteIndex (int pIndex);
Both of these methods can be used to remove an element from an enumeration. The difference between them is the way the element is searched for: by its value or by its index.
const void setValue (const String& pValue);
const void setValue (int pValue);
const void setValue (Element* pValue);
You can set a value of an enumeration using one of these three methods. In case the specified element is not found in the enumeration this method will throw an Exception, so it is better to place this methods in a try...catch block.
EnumType provides various methods to get the value inside. You can get the value as an element, as a string, or you can get the index of the value.
const Element* getValueElement () const;
You can use this method to get the value element of an enumeration. This is a pointer to the value member, so do not try to change or to delete this pointer.
String value () const;
operator const char* ();
const char* operator () (void);
These methods and operators return the actual value of an enumeration as a string.
int indexOfMyValue () const;
You can use this method to get the actual value as index.
With the following methods you can get information on the possible elements of an enumeration.
String getValueAtIndex (int pIndex);
Returns the value of the element with the specified index. The value is returned as a string.
Element* getElementAtIndex (int pIndex);
Use this method to get a pointer to the specified element. Changes on this pointer affect the element inside the enumeration.
int getIndexForValue (const String& pValue);
This method returns the index of an element specified by its value.