A bidirectional string-integer mapping. More...
#include <Enumeration.h>
Classes | |
class | Object |
Public Member Functions | |
bool | contains (const char *value) const |
Checks if a string is included in the enumeration. More... | |
Enumeration () | |
Constructs an empty Enumeration object. More... | |
Enumeration (const char **list, const char *valStr) | |
Constructs an Enumeration using val within list. More... | |
Enumeration (const char *valStr) | |
Constructs an Enumeration with a single element. More... | |
Enumeration (const Enumeration &other) | |
Standard copy constructor. More... | |
const char * | getCStr () const |
Return the value as C string. More... | |
std::vector< std::string > | getEnumVector () const |
get all possible enum values as vector of strings More... | |
int | getInt () const |
Return value as integer. More... | |
bool | hasEnums () const |
returns true if the enum list is non-empty, false otherwise More... | |
bool | isCustom () const |
Returns true if any of the items is a user-defined string. More... | |
bool | isValid () const |
Returns true if the instance is in a usable state. More... | |
bool | isValue (const char *value) const |
Checks if the property is set to a certain string value. More... | |
int | maxValue () const |
Returns the highest usable integer value for this enum. More... | |
Enumeration & | operator= (const Enumeration &other) |
Assignment operator. More... | |
bool | operator== (const char *other) const |
true iff our string representation matches other More... | |
bool | operator== (const Enumeration &other) const |
true iff our string representation matches other's More... | |
void | setEnums (const char **plEnums) |
Sets the enumeration string list The list is a NULL terminated array of pointers to const char* strings. More... | |
void | setEnums (const std::vector< std::string > &values) |
Set all enum values as vector of strings. More... | |
void | setValue (const char *value) |
Set the enum using a C string. More... | |
void | setValue (const std::string &value) |
Overload of setValue(const char *value) More... | |
void | setValue (long value, bool checkRange=false) |
Set the enum using a long. More... | |
~Enumeration () | |
Standard destructor. More... | |
Protected Member Functions | |
int | countItems () const |
Number of items. More... | |
Friends | |
class | PropertyEnumeration |
A bidirectional string-integer mapping.
This is mainly intended for two purposes: working around the difficulty in C++ of sharing enumerations between different source files, namespaces, etc. and as the data type stored by App::PropertyEnumeration
Internally, Enumeration maintains
If built with FC_DEBUG defined, some boundaries of passed in pointers will be checked. Otherwise, the caller has the responsibility of checking the limits of given indices.
Enumeration::Enumeration | ( | ) |
Constructs an empty Enumeration object.
Enumeration::Enumeration | ( | const Enumeration & | other | ) |
Standard copy constructor.
Enumeration::Enumeration | ( | const char * | valStr | ) |
Constructs an Enumeration with a single element.
References setValue().
Enumeration::Enumeration | ( | const char ** | list, |
const char * | valStr | ||
) |
Constructs an Enumeration using val within list.
References setValue().
Enumeration::~Enumeration | ( | ) |
Standard destructor.
bool Enumeration::contains | ( | const char * | value | ) | const |
Checks if a string is included in the enumeration.
References isValid().
Referenced by App::FeatureTest::execute().
|
protected |
Number of items.
Referenced by getCStr(), getInt(), isValid(), and setValue().
const char * Enumeration::getCStr | ( | ) | const |
Return the value as C string.
Returns NULL if the enumeration is invalid.
References countItems(), and isValid().
Referenced by App::FeatureTest::execute(), operator==(), and setEnums().
std::vector< std::string > Enumeration::getEnumVector | ( | ) | const |
get all possible enum values as vector of strings
Referenced by App::FeatureTest::execute().
int Enumeration::getInt | ( | ) | const |
Return value as integer.
Returns -1 if the Enumeration isn't valid
References countItems(), and isValid().
Referenced by isValue().
bool Enumeration::hasEnums | ( | ) | const |
returns true if the enum list is non-empty, false otherwise
Referenced by Fem::FemPostScalarClipFilter::execute(), and Fem::FemPostWarpVectorFilter::execute().
bool Enumeration::isCustom | ( | ) | const |
Returns true if any of the items is a user-defined string.
bool Enumeration::isValid | ( | void | ) | const |
Returns true if the instance is in a usable state.
References countItems().
Referenced by contains(), getCStr(), getInt(), and setEnums().
bool Enumeration::isValue | ( | const char * | value | ) | const |
Checks if the property is set to a certain string value.
References getInt().
Referenced by App::FeatureTest::execute(), and TechDraw::DrawProjGroup::usedProjectionType().
int Enumeration::maxValue | ( | ) | const |
Returns the highest usable integer value for this enum.
Returns -1 if the enumeration is not valid according to isValid()
Enumeration & Enumeration::operator= | ( | const Enumeration & | other | ) |
Assignment operator.
bool Enumeration::operator== | ( | const char * | other | ) | const |
true iff our string representation matches other
Returns false if Enumeration is not valid.
References getCStr().
bool Enumeration::operator== | ( | const Enumeration & | other | ) | const |
true iff our string representation matches other's
Returns false if either Enumeration is not valid.
void Enumeration::setEnums | ( | const char ** | plEnums | ) |
Sets the enumeration string list The list is a NULL terminated array of pointers to const char* strings.
If Enumeration was already valid, will attempt to preserve the string-representation value of the Enumeration
Enumeration does not take ownership of the passed object
References getCStr(), isValid(), and setValue().
Referenced by App::FeatureTest::execute(), Fem::FemPostScalarClipFilter::execute(), Fem::FemPostWarpVectorFilter::execute(), and setEnums().
void Enumeration::setEnums | ( | const std::vector< std::string > & | values | ) |
Set all enum values as vector of strings.
This method causes the Enumeration to dynamically allocate it's own array of C Strings, which will be deleted by the destructor or subsequent calls to setEnums(). So, it is important to make sure the Enumeration stays in scope as long as values returned by getCStr are in use.
If Enumeration was already valid, will attempt to preserve the string-representation value of the Enumeration
References getCStr(), isValid(), setEnums(), and setValue().
void Enumeration::setValue | ( | const char * | value | ) |
Set the enum using a C string.
Referenced by Enumeration(), App::FeatureTest::execute(), setEnums(), and TechDraw::DrawProjGroup::usedProjectionType().
void App::Enumeration::setValue | ( | const std::string & | value | ) |
void Enumeration::setValue | ( | long | value, |
bool | checkRange = false |
||
) |
Set the enum using a long.
if checkRange is set to true, throws Base::ValueError when values are set out of range
Checks for boundaries via assert()
References countItems().
|
friend |