Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkEnumerationProperty.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkEnumerationProperty_h
14 #define mitkEnumerationProperty_h
15 
16 #include <mitkBaseProperty.h>
17 
18 #include <map>
19 #include <string>
20 
21 namespace mitk
22 {
39  {
40  public:
42  itkFactorylessNewMacro(Self);
43  itkCloneMacro(Self);
44 
46  typedef unsigned int IdType;
47 
49  typedef std::map<IdType, std::string> EnumIdsContainerType;
50 
52  typedef std::map<std::string, IdType> EnumStringsContainerType;
53 
55  typedef EnumIdsContainerType::const_iterator EnumConstIterator;
56 
68  virtual bool AddEnum(const std::string &name, const IdType &id);
69 
77  virtual bool SetValue(const std::string &name);
78 
86  virtual bool SetValue(const IdType &id);
87 
94  virtual IdType GetValueAsId() const;
95 
102  std::string GetValueAsString() const override;
103 
107  virtual void Clear();
108 
114  virtual EnumIdsContainerType::size_type Size() const;
115 
123  virtual EnumConstIterator Begin() const;
124 
130  virtual EnumConstIterator End() const;
131 
139  virtual std::string GetEnumString(const IdType &id) const;
140 
148  virtual IdType GetEnumId(const std::string &name) const;
149 
156  virtual bool IsValidEnumerationValue(const IdType &id) const;
157 
164  virtual bool IsValidEnumerationValue(const std::string &name) const;
165 
171 
177 
183 
189 
201  bool ToJSON(nlohmann::json& j) const override;
202 
215  bool FromJSON(const nlohmann::json& j) override;
216 
217  using BaseProperty::operator=;
219 
220  protected:
225 
227 
228  bool IsEqual(const BaseProperty &property) const override;
229  bool Assign(const BaseProperty &property) override;
230 
232 
233  private:
234  IdType m_CurrentValue;
235  EnumIdsContainerType m_IdMap;
236  EnumStringsContainerType m_NameMap;
237  };
238 }
239 
240 
241 #endif
#define MITKCORE_EXPORT
Abstract base class for properties.
Property for storing enumeration-like values identified by id and name.
virtual bool IsValidEnumerationValue(const IdType &id) const
Check whether a given id corresponds to a valid enumeration value.
bool FromJSON(const nlohmann::json &j) override
Deserialize the enumeration value from JSON.
virtual bool SetValue(const IdType &id)
Set the current value of the enumeration by id.
virtual void Clear()
Remove all enumeration values and reset the current selection.
virtual EnumConstIterator End() const
Get an iterator past the last enumeration value.
const EnumStringsContainerType & GetEnumStrings() const
Get a const reference to the name-to-id map.
virtual bool IsValidEnumerationValue(const std::string &name) const
Check whether a given name corresponds to a valid enumeration value.
virtual bool AddEnum(const std::string &name, const IdType &id)
Add an enumeration value.
virtual std::string GetEnumString(const IdType &id) const
Get the name string for a given enumeration id.
std::map< std::string, IdType > EnumStringsContainerType
Map type storing name-to-id mappings.
bool IsEqual(const BaseProperty &property) const override
virtual IdType GetValueAsId() const
Get the id of the currently selected enumeration value.
EnumIdsContainerType::const_iterator EnumConstIterator
Const iterator type for iterating over enumeration values.
bool Assign(const BaseProperty &property) override
EnumerationProperty(const EnumerationProperty &)
EnumStringsContainerType & GetEnumStrings()
Get a mutable reference to the name-to-id map.
virtual EnumConstIterator Begin() const
Get an iterator to the first enumeration value.
virtual bool SetValue(const std::string &name)
Set the current value of the enumeration by name.
const EnumIdsContainerType & GetEnumIds() const
Get a const reference to the id-to-name map.
unsigned int IdType
Unsigned integer type used as unique enumeration value identifier.
EnumerationProperty & operator=(const EnumerationProperty &)=delete
std::string GetValueAsString() const override
Get the name of the currently selected enumeration value.
EnumIdsContainerType & GetEnumIds()
Get a mutable reference to the id-to-name map.
mitkClassMacro(EnumerationProperty, BaseProperty)
bool ToJSON(nlohmann::json &j) const override
Serialize the current enumeration value to JSON.
virtual IdType GetEnumId(const std::string &name) const
Get the id for a given enumeration name.
virtual EnumIdsContainerType::size_type Size() const
Get the number of defined enumeration values.
std::map< IdType, std::string > EnumIdsContainerType
Map type storing id-to-name mappings.
nlohmann::json json
Find image slices visible on a given plane.