Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::EnumerationProperty Class Reference

Property for storing enumeration-like values identified by id and name. More...

#include <mitkEnumerationProperty.h>

Inheritance diagram for mitk::EnumerationProperty:
Collaboration diagram for mitk::EnumerationProperty:

Public Types

typedef unsigned int IdType
 Unsigned integer type used as unique enumeration value identifier. More...
 
typedef std::map< IdType, std::string > EnumIdsContainerType
 Map type storing id-to-name mappings. More...
 
typedef std::map< std::string, IdType > EnumStringsContainerType
 Map type storing name-to-id mappings. More...
 
typedef EnumIdsContainerType::const_iterator EnumConstIterator
 Const iterator type for iterating over enumeration values. More...
 

Public Member Functions

 mitkClassMacro (EnumerationProperty, BaseProperty)
 
Pointer Clone () const
 
virtual bool AddEnum (const std::string &name, const IdType &id)
 Add an enumeration value. More...
 
virtual bool SetValue (const std::string &name)
 Set the current value of the enumeration by name. More...
 
virtual bool SetValue (const IdType &id)
 Set the current value of the enumeration by id. More...
 
virtual IdType GetValueAsId () const
 Get the id of the currently selected enumeration value. More...
 
std::string GetValueAsString () const override
 Get the name of the currently selected enumeration value. More...
 
virtual void Clear ()
 Remove all enumeration values and reset the current selection. More...
 
virtual EnumIdsContainerType::size_type Size () const
 Get the number of defined enumeration values. More...
 
virtual EnumConstIterator Begin () const
 Get an iterator to the first enumeration value. More...
 
virtual EnumConstIterator End () const
 Get an iterator past the last enumeration value. More...
 
virtual std::string GetEnumString (const IdType &id) const
 Get the name string for a given enumeration id. More...
 
virtual IdType GetEnumId (const std::string &name) const
 Get the id for a given enumeration name. More...
 
virtual bool IsValidEnumerationValue (const IdType &id) const
 Check whether a given id corresponds to a valid enumeration value. More...
 
virtual bool IsValidEnumerationValue (const std::string &name) const
 Check whether a given name corresponds to a valid enumeration value. More...
 
const EnumIdsContainerType & GetEnumIds () const
 Get a const reference to the id-to-name map. More...
 
const EnumStringsContainerType & GetEnumStrings () const
 Get a const reference to the name-to-id map. More...
 
EnumIdsContainerType & GetEnumIds ()
 Get a mutable reference to the id-to-name map. More...
 
EnumStringsContainerType & GetEnumStrings ()
 Get a mutable reference to the name-to-id map. More...
 
bool ToJSON (nlohmann::json &j) const override
 Serialize the current enumeration value to JSON. More...
 
bool FromJSON (const nlohmann::json &j) override
 Deserialize the enumeration value from JSON. More...
 
EnumerationProperty & operator= (const EnumerationProperty &)=delete
 
BaseProperty & operator= (const BaseProperty &property)
 Assign a property value to this instance. More...
 
- Public Member Functions inherited from mitk::BaseProperty
 mitkClassMacroItkParent (BaseProperty, itk::Object)
 
Pointer Clone () const
 
bool operator== (const BaseProperty &property) const
 Compare two properties for equality. More...
 
BaseProperty & operator= (const BaseProperty &property)
 Assign a property value to this instance. More...
 
bool AssignProperty (const BaseProperty &property)
 Assign a property value to this instance and report success. More...
 

Static Public Member Functions

static Pointer New ()
 

Protected Member Functions

 EnumerationProperty ()
 
 EnumerationProperty (const EnumerationProperty &)
 
bool IsEqual (const BaseProperty &property) const override
 
bool Assign (const BaseProperty &property) override
 
 mitkCloneMacro (Self)
 
- Protected Member Functions inherited from mitk::BaseProperty
 BaseProperty ()
 
 BaseProperty (const BaseProperty &other)
 
 ~BaseProperty () override
 

Additional Inherited Members

- Static Public Attributes inherited from mitk::BaseProperty
static const std::string VALUE_CANNOT_BE_CONVERTED_TO_STRING
 Default return value for properties that cannot be converted to a string. More...
 

Detailed Description

Property for storing enumeration-like values identified by id and name.

This class may be used to store properties similar to C++ enumeration values. Each enumeration value is identified by a unique id and a unique name. You must add enumeration values before using the Get/SetValue methods.

To use this class, create a subclass that adds the possible enumeration values in its constructor. You should override AddEnum() as protected so that users cannot add invalid enumeration values.

See also
VtkRepresentationProperty
VtkInterpolationProperty
BaseProperty

Definition at line 38 of file mitkEnumerationProperty.h.

Member Typedef Documentation

◆ EnumConstIterator

typedef EnumIdsContainerType::const_iterator mitk::EnumerationProperty::EnumConstIterator

Const iterator type for iterating over enumeration values.

Definition at line 55 of file mitkEnumerationProperty.h.

◆ EnumIdsContainerType

Map type storing id-to-name mappings.

Definition at line 49 of file mitkEnumerationProperty.h.

◆ EnumStringsContainerType

Map type storing name-to-id mappings.

Definition at line 52 of file mitkEnumerationProperty.h.

◆ IdType

typedef unsigned int mitk::EnumerationProperty::IdType

Unsigned integer type used as unique enumeration value identifier.

Definition at line 46 of file mitkEnumerationProperty.h.

Constructor & Destructor Documentation

◆ EnumerationProperty() [1/2]

mitk::EnumerationProperty::EnumerationProperty ( )
protected

Default constructor. The current value of the enumeration is undefined.

◆ EnumerationProperty() [2/2]

mitk::EnumerationProperty::EnumerationProperty ( const EnumerationProperty &  )
protected

Member Function Documentation

◆ AddEnum()

virtual bool mitk::EnumerationProperty::AddEnum ( const std::string &  name,
const IdType &  id 
)
virtual

Add an enumeration value.

The name and id provided must both be unique. If either already exists, the value is not added and false is returned.

Parameters
[in]nameThe unique name of the enumeration value.
[in]idThe unique id of the enumeration value.
Returns
true if the name/id combination was successfully added, false if either name or id already exists.

Reimplemented in mitk::PlanarFigureControlPointStyleProperty, mitk::RegVisStyleProperty, mitk::RegVisDirectionProperty, mitk::RegVisColorStyleProperty, mitk::RegEvalWipeStyleProperty, mitk::RegEvalStyleProperty, mitk::GridVolumeMapperProperty, mitk::GridRepresentationProperty, mitk::VtkScalarModeProperty, mitk::VtkResliceInterpolationProperty, mitk::VtkRepresentationProperty, mitk::VtkInterpolationProperty, mitk::RenderingModeProperty, mitk::PointSetShapeProperty, and mitk::PlaneOrientationProperty.

◆ Assign()

bool mitk::EnumerationProperty::Assign ( const BaseProperty &  )
overrideprotectedvirtual

Override this method in subclasses to implement a meaningful assignment. The property argument is guaranteed to be castable to the type of the implementing subclass.

Warning
This is not yet exception aware/safe and if this method returns false, this property's state might be undefined.
Returns
True if the argument could be assigned to this property.

Implements mitk::BaseProperty.

◆ Begin()

virtual EnumConstIterator mitk::EnumerationProperty::Begin ( ) const
virtual

Get an iterator to the first enumeration value.

Iterator dereferences to a pair where first is the id and second is the name.

Returns
A const iterator to the beginning of the enumeration values.

◆ Clear()

virtual void mitk::EnumerationProperty::Clear ( )
virtual

Remove all enumeration values and reset the current selection.

◆ Clone()

Pointer mitk::EnumerationProperty::Clone ( ) const

◆ End()

virtual EnumConstIterator mitk::EnumerationProperty::End ( ) const
virtual

Get an iterator past the last enumeration value.

Returns
A const iterator pointing past the end of the enumeration values.

◆ FromJSON()

bool mitk::EnumerationProperty::FromJSON ( const nlohmann::json &  j)
overridevirtual

Deserialize the enumeration value from JSON.

Reads a string from JSON and sets the enumeration value by name.

Note
Classes deriving from EnumerationProperty are covered by this implementation and do not need to override this method again.
Parameters
[in]jThe JSON string value to read from.
Returns
Always true.
Exceptions
mitk::Exceptionif the JSON string is not a valid enumeration value.

Implements mitk::BaseProperty.

◆ GetEnumId()

virtual IdType mitk::EnumerationProperty::GetEnumId ( const std::string &  name) const
virtual

Get the id for a given enumeration name.

Parameters
[in]nameThe enumeration name for which to retrieve the id.
Returns
The id of the enumeration value. If the name is invalid, the return value is 0.

◆ GetEnumIds() [1/2]

EnumIdsContainerType& mitk::EnumerationProperty::GetEnumIds ( )

Get a mutable reference to the id-to-name map.

Returns
The map of enumeration ids to names.

◆ GetEnumIds() [2/2]

const EnumIdsContainerType& mitk::EnumerationProperty::GetEnumIds ( ) const

Get a const reference to the id-to-name map.

Returns
The map of enumeration ids to names.

◆ GetEnumString()

virtual std::string mitk::EnumerationProperty::GetEnumString ( const IdType &  id) const
virtual

Get the name string for a given enumeration id.

Parameters
[in]idThe id for which to retrieve the name.
Returns
The name of the enumeration value. If the id is invalid, the return value is the string "invalid enum id or enums empty".

◆ GetEnumStrings() [1/2]

EnumStringsContainerType& mitk::EnumerationProperty::GetEnumStrings ( )

Get a mutable reference to the name-to-id map.

Returns
The map of enumeration names to ids.

◆ GetEnumStrings() [2/2]

const EnumStringsContainerType& mitk::EnumerationProperty::GetEnumStrings ( ) const

Get a const reference to the name-to-id map.

Returns
The map of enumeration names to ids.

◆ GetValueAsId()

virtual IdType mitk::EnumerationProperty::GetValueAsId ( ) const
virtual

Get the id of the currently selected enumeration value.

Returns
The id of the current value. If no value has been set, the return value is unspecified.

◆ GetValueAsString()

std::string mitk::EnumerationProperty::GetValueAsString ( ) const
overridevirtual

Get the name of the currently selected enumeration value.

Returns
The name string of the current value. If no value has been set, the return value is unspecified.

Reimplemented from mitk::BaseProperty.

◆ IsEqual()

bool mitk::EnumerationProperty::IsEqual ( const BaseProperty &  property) const
overrideprotectedvirtual

Override this method in subclasses to implement a meaningful comparison. The property argument is guaranteed to be castable to the type of the implementing subclass.

Implements mitk::BaseProperty.

◆ IsValidEnumerationValue() [1/2]

virtual bool mitk::EnumerationProperty::IsValidEnumerationValue ( const IdType &  id) const
virtual

Check whether a given id corresponds to a valid enumeration value.

Parameters
[in]idThe id to check.
Returns
true if the id is valid, false otherwise.

◆ IsValidEnumerationValue() [2/2]

virtual bool mitk::EnumerationProperty::IsValidEnumerationValue ( const std::string &  name) const
virtual

Check whether a given name corresponds to a valid enumeration value.

Parameters
[in]nameThe name to check.
Returns
true if the name is valid, false otherwise.

◆ mitkClassMacro()

mitk::EnumerationProperty::mitkClassMacro ( EnumerationProperty  ,
BaseProperty   
)

◆ mitkCloneMacro()

mitk::EnumerationProperty::mitkCloneMacro ( Self  )
protected

◆ New()

static Pointer mitk::EnumerationProperty::New ( )
static

◆ operator=() [1/2]

BaseProperty& mitk::BaseProperty::operator=

Assign a property value to this instance.

Performs a polymorphic assignment from the given property. The assignment succeeds only if the source and target properties are of the same type. The subclass-specific Assign() method is called to perform the actual value copy.

Subclasses must implement Assign(const BaseProperty&) and call the superclass Assign method for proper handling. The copy assignment operator of the subclass should be disabled and the base class operator should be made visible using "using" statements.

Parameters
[in]propertyThe property whose value should be assigned to this instance.
Returns
A reference to this property.
See also
AssignProperty
Assign

◆ operator=() [2/2]

EnumerationProperty& mitk::EnumerationProperty::operator= ( const EnumerationProperty &  )
delete

◆ SetValue() [1/2]

virtual bool mitk::EnumerationProperty::SetValue ( const IdType &  id)
virtual

Set the current value of the enumeration by id.

Parameters
[in]idThe id of the enumeration value to set.
Returns
true if the value was successfully set (id is valid), false otherwise.

◆ SetValue() [2/2]

virtual bool mitk::EnumerationProperty::SetValue ( const std::string &  name)
virtual

Set the current value of the enumeration by name.

Parameters
[in]nameThe name of the enumeration value to set.
Returns
true if the value was successfully set (name is valid), false otherwise.

◆ Size()

virtual EnumIdsContainerType::size_type mitk::EnumerationProperty::Size ( ) const
virtual

Get the number of defined enumeration values.

Returns
The count of registered enumeration values.

◆ ToJSON()

bool mitk::EnumerationProperty::ToJSON ( nlohmann::json &  j) const
overridevirtual

Serialize the current enumeration value to JSON.

Writes the current enumeration value name as a JSON string.

Note
Classes deriving from EnumerationProperty are covered by this implementation and do not need to override this method again.
Parameters
[out]jThe JSON value to write into.
Returns
Always true.

Implements mitk::BaseProperty.


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