A bidirectional string-integer mapping. More...

#include <Enumeration.h>

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 (void) const
 Return the value as C string. More...
 
const char ** getEnums (void) const
 get pointer to the enum list More...
 
std::vector< std::string > getEnumVector (void) const
 get all possible enum values as vector of strings More...
 
int getInt (void) const
 Return value as integer. More...
 
bool isValid (void) 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 (void) const
 Returns the highest usable integer value for this enum. More...
 
Enumerationoperator= (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

void findMaxVal (void)
 Updates _maxVal. More...
 
bool isCustom (void) const
 Returns true if instance was not initialized via static string list. More...
 
void tearDown (void)
 De-allocates memory used in _EnumArray. More...
 

Friends

class App::PropertyEnumeration
 

Detailed Description

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

  1. Either a const pointer to an array of C-style strings, or a vector of C++ std::strings
  2. An integer index into that array/vector representing the string representing the instance's value.

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.

Constructor & Destructor Documentation

◆ Enumeration() [1/4]

Enumeration::Enumeration ( )

Constructs an empty Enumeration object.

◆ Enumeration() [2/4]

Enumeration::Enumeration ( const Enumeration other)

Standard copy constructor.

References getEnumVector(), and setEnums().

◆ Enumeration() [3/4]

Enumeration::Enumeration ( const char *  valStr)

Constructs an Enumeration with a single element.

◆ Enumeration() [4/4]

Enumeration::Enumeration ( const char **  list,
const char *  valStr 
)

Constructs an Enumeration using val within list.

References findMaxVal(), and setValue().

◆ ~Enumeration()

Enumeration::~Enumeration ( )

Standard destructor.

References tearDown().

Member Function Documentation

◆ contains()

bool Enumeration::contains ( const char *  value) const

Checks if a string is included in the enumeration.

References getEnums().

◆ findMaxVal()

void Enumeration::findMaxVal ( void  )
protected

Updates _maxVal.

Referenced by Enumeration(), and setEnums().

◆ getCStr()

const char * Enumeration::getCStr ( void  ) const

Return the value as C string.

Returns NULL if the enumeration is invalid.

References isValid().

Referenced by operator==(), and setEnums().

◆ getEnums()

const char ** Enumeration::getEnums ( void  ) const

get pointer to the enum list

Referenced by contains().

◆ getEnumVector()

std::vector< std::string > Enumeration::getEnumVector ( void  ) const

get all possible enum values as vector of strings

Referenced by Enumeration(), and operator=().

◆ getInt()

int Enumeration::getInt ( void  ) const

Return value as integer.

Returns -1 if the Enumeration isn't valid

References isValid().

Referenced by isValue().

◆ isCustom()

bool App::Enumeration::isCustom ( void  ) const
protected

Returns true if instance was not initialized via static string list.

◆ isValid()

bool Enumeration::isValid ( void  ) const

Returns true if the instance is in a usable state.

Referenced by getCStr(), getInt(), and setEnums().

◆ isValue()

bool Enumeration::isValue ( const char *  value) const

Checks if the property is set to a certain string value.

References getInt().

Referenced by TechDraw::DrawProjGroup::usedProjectionType().

◆ maxValue()

int App::Enumeration::maxValue ( void  ) const

Returns the highest usable integer value for this enum.

Returns -1 if the enumeration is not valid according to isValid()

◆ operator=()

Enumeration & Enumeration::operator= ( const Enumeration other)

Assignment operator.

References getEnumVector(), and setEnums().

◆ operator==() [1/2]

bool Enumeration::operator== ( const char *  other) const

true iff our string representation matches other

Returns false if Enumeration is not valid.

References getCStr().

◆ operator==() [2/2]

bool Enumeration::operator== ( const Enumeration other) const

true iff our string representation matches other's

Returns false if either Enumeration is not valid.

References getCStr().

◆ setEnums() [1/2]

void Enumeration::setEnums ( const char **  plEnums)

Sets the enumeration string list The list is a NULL terminated array of pointers to const char* strings.

const char enums[] = {"Black","White","Other",NULL}

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 findMaxVal(), getCStr(), isValid(), setValue(), and tearDown().

Referenced by Enumeration(), and operator=().

◆ setEnums() [2/2]

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(), setValue(), and tearDown().

◆ setValue() [1/3]

void Enumeration::setValue ( const char *  value)

◆ setValue() [2/3]

void App::Enumeration::setValue ( const std::string &  value)

◆ setValue() [3/3]

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()

◆ tearDown()

void Enumeration::tearDown ( void  )
protected

De-allocates memory used in _EnumArray.

Important to not call this unless this Enumeration owns array.

Referenced by setEnums(), PathTests.TestPathHelix.TestPathHelix::test03(), PathTests.TestPathHelix.TestPathHelix::test04(), and ~Enumeration().

Friends And Related Function Documentation

◆ App::PropertyEnumeration


The documentation for this class was generated from the following files:
  • src/App/Enumeration.h
  • src/App/Enumeration.cpp