App::Enumeration Class Reference

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...
 
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

int countItems () const
 Number of items. More...
 

Friends

class 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.

◆ Enumeration() [3/4]

Enumeration::Enumeration ( const char *  valStr)

Constructs an Enumeration with a single element.

References setValue().

◆ Enumeration() [4/4]

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

Constructs an Enumeration using val within list.

References setValue().

◆ ~Enumeration()

Enumeration::~Enumeration ( )

Standard destructor.

Member Function Documentation

◆ contains()

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

Checks if a string is included in the enumeration.

References isValid().

Referenced by App::FeatureTest::execute().

◆ countItems()

int Enumeration::countItems ( ) const
protected

Number of items.

Referenced by getCStr(), getInt(), isValid(), and setValue().

◆ getCStr()

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

◆ getEnumVector()

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

get all possible enum values as vector of strings

Referenced by App::FeatureTest::execute().

◆ getInt()

int Enumeration::getInt ( ) const

Return value as integer.

Returns -1 if the Enumeration isn't valid

References countItems(), and isValid().

Referenced by isValue().

◆ hasEnums()

bool Enumeration::hasEnums ( ) const

returns true if the enum list is non-empty, false otherwise

Referenced by Fem::FemPostScalarClipFilter::execute(), and Fem::FemPostWarpVectorFilter::execute().

◆ isCustom()

bool Enumeration::isCustom ( ) const

Returns true if any of the items is a user-defined string.

◆ isValid()

bool Enumeration::isValid ( void  ) const

Returns true if the instance is in a usable state.

References countItems().

Referenced by contains(), 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 App::FeatureTest::execute(), and TechDraw::DrawProjGroup::usedProjectionType().

◆ maxValue()

int Enumeration::maxValue ( ) 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.

◆ 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.

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

Referenced by App::FeatureTest::execute(), Fem::FemPostScalarClipFilter::execute(), Fem::FemPostWarpVectorFilter::execute(), and setEnums().

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

◆ setValue() [1/3]

void Enumeration::setValue ( const char *  value)

◆ setValue() [2/3]

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

Overload of setValue(const char *value)

References setValue().

Referenced by setValue().

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

References countItems().

Friends And Related Function Documentation

◆ PropertyEnumeration


The documentation for this class was generated from the following files: