ML Reference
ml::EnumField Class Reference

#include <mlFields.h>

Inheritance diagram for ml::EnumField:
ml::Field ml::TypedEnumField< EnumType >

Classes

struct  EnumEntry
 Defines the entry for one enum value. More...

Public Member Functions

 EnumField (const std::string &name, const std::string enumerationItemNames[], size_t numEnumerationItems)
 Implements the runtime type system interface for this class.
 EnumField (const std::string &name, const char *const *enumerationItemNames, size_t numEnumerationItems)
 EnumField (const std::string &name, const std::vector< std::string > &enumerationItemNames)
 ~EnumField () override=default
 Destroys this field and releases internally allocated memory.
void setStringValue (const std::string &value) override
void setStringValueDefaulted (const std::string &value)
void setEnumValue (int enumValue)
 Sets field value to enumValue.
void updateEnumValue (int enumValue)
std::string getStringValue () const override
int getEnumValue () const
 Returns the current enum value as integer.
const EnumEntrygetEnumEntryAtIndex (size_t index) const
size_t getNumEnumerationItems () const
 Returns the number of registered enum values defined in constructor.
void setValue (int enumValue)
 Same as setEnumValue().
void updateValue (int enumValue)
 Same as updateEnumValue().
int getValue () const
 Same as getEnumValue().
Public Member Functions inherited from ml::Field
 Field (const std::string &name=std::string())
 Constructor: Creates a field with name.
virtual ~Field ()
 Destructor: Destroys a field and removes all connection to fields and sensors.
FieldContainergetFieldContainer () const
 Returns the field container of the field (which may be NULL).
const std::string & getName () const
 Returns the name of field.
void setName (const std::string &name)
 Sets the name of field. Should be called only once after or while construction.
std::string getFullName () const
bool isOutputOnly () const
 Returns whether this field is marked as a pure output field.
void setOutputOnly (bool outputOnly=true)
 Marks this field as a pure output field that is only changed by its module.
virtual MLint isValidValue ()
void copyCStringValue (char *valueBuffer, MLint bufferSize)
MLint getCStringValueSize ()
 Returns the length of the character string of the string value of the field.
void attachFieldSensor (FieldSensor *sensor)
 Attaches a field sensor sensor of this class instance in both directions.
void detachFieldSensor (FieldSensor *sensor)
 Detaches the field sensor sensor of this class instance in both directions.
void detachFieldSensors ()
 Detaches all field sensors of this class instance in both directions.
void attachField (OutputConnectorField *targetField)
void attachField (BaseField *targetField)
void attachField (SoNodeField *targetField)
void attachField (NotifyField *targetField)
void attachField (Field *targetField, bool propagateValueOnConnect)
void detachField (Field *targetField)
 Disconnects connections between the target field targetField and this instance.
void detachSourceFields ()
 Disconnects all source fields of this instance in both directions.
void detachDestinationFields ()
 Disconnects all target fields of this instance in both directions.
void detachAllFields ()
 Disconnects all source and target fields of this instance in both directions.
size_t getNumDestinationFields ()
 Returns the number of destination fields that could receive notifications or value sets.
FieldgetDestinationField (size_t index)
 Returns the destination field at index. Returns NULL if index is out of range.
size_t getNumSourceFields ()
 Returns the number of source fields that could send notifications or value sets.
FieldgetSourceField (size_t index)
 Returns the source field at index. Returns NULL if index is out of range.
virtual void touch (FieldSensor::Strength strength=FieldSensor::CHANGED)
void enableNotifications (bool flag)
bool areNotificationsEnabled ()

Protected Member Functions

void _initialize (const std::string &name="", size_t numEnums=0)
 Initializes this field.
void _setEnumerationNames (const std::string enumNames[])
 Sets the enumeration item names.
void _setEnumerationNames (const char *const *enumNames)
 Sets the enumeration item names.
void _setEnumerationNames (const std::vector< std::string > &enumNames)
 Sets the enumeration item names.
void _setEnumerationNames (const std::vector< EnumField::EnumEntry > &enumValues, int initialValue)
 Sets the enumeration item names.
 EnumField ()=default
 Protected constructor to allow derived classes.
Protected Member Functions inherited from ml::Field
void attachSourceField (Field *field)
void detachSourceField (Field *field)
 Removes a source field from this instance. If not found, then this call does nothing.
void detachFieldInternal (Field *field)
 Only removes the given field from the destination list.
virtual void setValueFromField (const Field &field)

Protected Attributes

int _value {}
 The field value; we use an integer to be compatible with normal enum types.
bool _linearEntries {}
 Stores whether enum entry values start at 0 and increase by 1.
std::vector< EnumEntry_entries
 Stores the possible enum values and names.
Protected Attributes inherited from ml::Field
std::string _name
 The name of this field.
std::vector< FieldSensor * > _sensors
 List of field sensors.
std::vector< Field * > _destinationFields
std::vector< Field * > _sourceFields
FieldContainer_fieldContainer
 The owning field container.
Flags _flags

Additional Inherited Members

static void enableNotificationsGlobally (bool flag)
static bool areNotificationsEnabledGlobally ()
static MLintenableNotificationsCounterState ()
Static Protected Attributes inherited from ml::Field
static MLint _enableNotifications
 Flag that disables the notification process of field (-sensors) globally.

Detailed Description

Field to encapsulate an enumerated value.

Definition at line 172 of file mlFields.h.

Constructor & Destructor Documentation

◆ EnumField() [1/4]

ml::EnumField::EnumField ( const std::string & name,
const std::string enumerationItemNames[],
size_t numEnumerationItems )

Implements the runtime type system interface for this class.

Constructor, creates a field with a name to manage an enum value. The value range for the enum value is [0, numEnumerationItems-1]. The value names are defined by enumerationItemNames. The maximum number of enum entries is ML_INT32_MAX, minimum is 1; exceeding that will lead to fatal errors, even on 64-bit systems. Note that enumerationItemNames must contain at least numEnumerationItems string values.

Referenced by ml::TypedEnumField< EnumType >::TypedEnumField().

◆ EnumField() [2/4]

ml::EnumField::EnumField ( const std::string & name,
const char *const * enumerationItemNames,
size_t numEnumerationItems )

Constructor, creates a field with a name to manage an enum value. The value range for the enum value is [0, numEnumerationItems-1]. The value names are defined by enumerationItemNames. The maximum number of enum entries is ML_INT32_MAX, minimum is 1; exceeding that will lead to fatal errors, even on 64-bit systems. Note that enumerationItemNames must contain at least numEnumerationItems string values.

◆ EnumField() [3/4]

ml::EnumField::EnumField ( const std::string & name,
const std::vector< std::string > & enumerationItemNames )

Constructor, creates a field with a name to manage an enum value. The field creates the value buffer internally. The value range for the enum value is [0, enumerationItemNames.size-1]. The value names are defined by enumerationItemNames. The maximum number of enum entries is ML_INT32_MAX, minimum is 1; exceeding that will lead to fatal errors, even on 64-bit systems. The default enum value is 0.

◆ ~EnumField()

ml::EnumField::~EnumField ( )
overridedefault

Destroys this field and releases internally allocated memory.

◆ EnumField() [4/4]

ml::EnumField::EnumField ( )
protecteddefault

Protected constructor to allow derived classes.

Member Function Documentation

◆ _initialize()

void ml::EnumField::_initialize ( const std::string & name = "",
size_t numEnums = 0 )
protected

Initializes this field.

Referenced by ml::TypedEnumField< EnumType >::TypedEnumField().

◆ _setEnumerationNames() [1/4]

void ml::EnumField::_setEnumerationNames ( const char *const * enumNames)
protected

Sets the enumeration item names.

◆ _setEnumerationNames() [2/4]

void ml::EnumField::_setEnumerationNames ( const std::string enumNames[])
protected

Sets the enumeration item names.

Referenced by ml::TypedEnumField< EnumType >::TypedEnumField().

◆ _setEnumerationNames() [3/4]

void ml::EnumField::_setEnumerationNames ( const std::vector< EnumField::EnumEntry > & enumValues,
int initialValue )
protected

Sets the enumeration item names.

◆ _setEnumerationNames() [4/4]

void ml::EnumField::_setEnumerationNames ( const std::vector< std::string > & enumNames)
protected

Sets the enumeration item names.

◆ getEnumEntryAtIndex()

const EnumEntry & ml::EnumField::getEnumEntryAtIndex ( size_t index) const

Returns the enum entry at given index, which allows to enumerate all existing enum entries. Allowed indices are [0 - getNumEnumerationItems()-1]. No bounds check is performed!

◆ getEnumValue()

int ml::EnumField::getEnumValue ( ) const

Returns the current enum value as integer.

Referenced by ml::TypedEnumField< EnumType >::getEnumValue(), and getValue().

◆ getNumEnumerationItems()

size_t ml::EnumField::getNumEnumerationItems ( ) const

Returns the number of registered enum values defined in constructor.

◆ getStringValue()

std::string ml::EnumField::getStringValue ( ) const
overridevirtual

Returns the value of the field as string value. setStringValue must be able to interpret this returned string correctly. On invalid enumValues, the first string item is returned.

Implements ml::Field.

◆ getValue()

int ml::EnumField::getValue ( ) const
inline

Same as getEnumValue().

Definition at line 259 of file mlFields.h.

References getEnumValue().

◆ setEnumValue()

void ml::EnumField::setEnumValue ( int enumValue)

Sets field value to enumValue.

Referenced by ml::TypedEnumField< EnumType >::setEnumValue(), and setValue().

◆ setStringValue()

void ml::EnumField::setStringValue ( const std::string & value)
overridevirtual

Sets value of the field to the enum item with given name value. If the value enum item is not found, the call is ignored. The comparison is performed in a case-sensitive manner.

Implements ml::Field.

◆ setStringValueDefaulted()

void ml::EnumField::setStringValueDefaulted ( const std::string & value)

If value equals one of the enum item names, set the field to this item; otherwise, set it to the first item of the enum.

◆ setValue()

void ml::EnumField::setValue ( int enumValue)
inline

Same as setEnumValue().

Definition at line 253 of file mlFields.h.

References setEnumValue().

◆ updateEnumValue()

void ml::EnumField::updateEnumValue ( int enumValue)

Sets field value to enumValue, but only touches the field if the new value is different from the old value.

Referenced by ml::TypedEnumField< EnumType >::updateEnumValue(), and updateValue().

◆ updateValue()

void ml::EnumField::updateValue ( int enumValue)
inline

Same as updateEnumValue().

Definition at line 256 of file mlFields.h.

References updateEnumValue().

Member Data Documentation

◆ _entries

std::vector<EnumEntry> ml::EnumField::_entries
protected

Stores the possible enum values and names.

Definition at line 282 of file mlFields.h.

◆ _linearEntries

bool ml::EnumField::_linearEntries {}
protected

Stores whether enum entry values start at 0 and increase by 1.

Definition at line 279 of file mlFields.h.

◆ _value

int ml::EnumField::_value {}
protected

The field value; we use an integer to be compatible with normal enum types.

Definition at line 276 of file mlFields.h.


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