Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkPropertyList.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 mitkPropertyList_h
14 #define mitkPropertyList_h
15 
16 #include <mitkIPropertyOwner.h>
17 #include <mitkGenericProperty.h>
18 
19 #include <nlohmann/json_fwd.hpp>
20 
21 namespace mitk
22 {
56  class MITKCORE_EXPORT PropertyList : public itk::Object, public IPropertyOwner
57  {
58  public:
60 
64  itkFactorylessNewMacro(Self);
65  itkCloneMacro(Self);
66 
71  typedef std::map<std::string, BaseProperty::Pointer> PropertyMap;
72  typedef std::pair<std::string, BaseProperty::Pointer> PropertyMapElementType;
73 
74  // IPropertyProvider
75  BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override;
76  std::vector<std::string> GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override;
77  std::vector<std::string> GetPropertyContextNames() const override;
78 
79  // IPropertyOwner
80  BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override;
81  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
82  void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
83 
87  mitk::BaseProperty *GetProperty(const std::string &propertyKey) const;
88 
97  void ReplaceProperty(const std::string &propertyKey, BaseProperty *property);
98 
102  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
103 
104  //##Documentation
105  //## @brief Convenience access method for GenericProperty<T> properties
106  //## (T being the type of the second parameter)
107  //## @return @a true property was found
108  template <typename T>
109  bool GetPropertyValue(const char *propertyKey, T &value) const
110  {
111  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey));
112  if (gp != nullptr)
113  {
114  value = gp->GetValue();
115  return true;
116  }
117  return false;
118  }
119 
123  bool GetBoolProperty(const char *propertyKey, bool &boolValue) const;
127  bool Get(const char *propertyKey, bool &boolValue) const;
128 
132  void SetBoolProperty(const char *propertyKey, bool boolValue);
136  void Set(const char *propertyKey, bool boolValue);
137 
141  bool GetIntProperty(const char *propertyKey, int &intValue) const;
145  bool Get(const char *propertyKey, int &intValue) const;
146 
150  void SetIntProperty(const char *propertyKey, int intValue);
154  void Set(const char *propertyKey, int intValue);
155 
159  bool GetFloatProperty(const char *propertyKey, float &floatValue) const;
163  bool Get(const char *propertyKey, float &floatValue) const;
164 
168  void SetFloatProperty(const char *propertyKey, float floatValue);
172  void Set(const char *propertyKey, float floatValue);
173 
177  bool GetDoubleProperty(const char *propertyKey, double &doubleValue) const;
181  bool Get(const char *propertyKey, double &doubleValue) const;
182 
186  void SetDoubleProperty(const char *propertyKey, double doubleValue);
190  void Set(const char *propertyKey, double doubleValue);
191 
195  bool GetStringProperty(const char *propertyKey, std::string &stringValue) const;
199  bool Get(const char *propertyKey, std::string &stringValue) const;
200 
204  void SetStringProperty(const char *propertyKey, const char *stringValue);
208  void Set(const char *propertyKey, const char *stringValue);
212  void Set(const char *propertyKey, const std::string &stringValue);
213 
218  itk::ModifiedTimeType GetMTime() const override;
219 
223  bool DeleteProperty(const std::string &propertyKey);
224 
225  const PropertyMap *GetMap() const { return &m_Properties; }
226  bool IsEmpty() const { return m_Properties.empty(); }
227  virtual void Clear();
228 
238  void ToJSON(nlohmann::json& j) const;
239 
249  void FromJSON(const nlohmann::json& j);
250 
251  protected:
253  PropertyList(const PropertyList &other);
254 
255  ~PropertyList() override;
256 
261 
262  private:
263  itk::LightObject::Pointer InternalClone() const override;
264  };
265 
266 } // namespace mitk
267 
268 #endif
#define MITKCORE_EXPORT
Abstract base class for properties.
virtual T GetValue() const
Key-value list holding instances of BaseProperty.
bool GetBoolProperty(const char *propertyKey, bool &boolValue) const
Convenience method to access the value of a BoolProperty.
std::map< std::string, BaseProperty::Pointer > PropertyMap
PropertyMap m_Properties
Map of properties.
void SetStringProperty(const char *propertyKey, const char *stringValue)
Convenience method to set the value of a StringProperty.
itk::ModifiedTimeType GetMTime() const override
Get the timestamp of the last change of the map or the last change of one of the properties store in ...
void ToJSON(nlohmann::json &j) const
Serialize the property list to JSON.
void Set(const char *propertyKey, float floatValue)
ShortCut for the above method.
bool Get(const char *propertyKey, int &intValue) const
ShortCut for the above method.
bool GetStringProperty(const char *propertyKey, std::string &stringValue) const
Convenience method to access the value of a StringProperty.
mitkClassMacroItkParent(PropertyList, itk::Object)
void RemoveProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Removes a property. If the property does not exist, nothing will be done.
bool Get(const char *propertyKey, double &doubleValue) const
ShortCut for the above method.
bool Get(const char *propertyKey, std::string &stringValue) const
ShortCut for the above method.
void SetDoubleProperty(const char *propertyKey, double doubleValue)
Convenience method to set the value of a DoubleProperty.
BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) const override
Get property by its key.
std::vector< std::string > GetPropertyContextNames() const override
Query names of existing contexts.
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Add new or change existent property.
void Set(const char *propertyKey, int intValue)
ShortCut for the above method.
bool GetDoubleProperty(const char *propertyKey, double &doubleValue) const
Convenience method to access the value of a DoubleProperty.
bool DeleteProperty(const std::string &propertyKey)
Remove a property from the list/map.
std::vector< std::string > GetPropertyKeys(const std::string &contextName="", bool includeDefaultContext=false) const override
Query keys of existing properties.
BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) override
Get property by its key.
bool Get(const char *propertyKey, float &floatValue) const
ShortCut for the above method.
bool GetPropertyValue(const char *propertyKey, T &value) const
Convenience access method for GenericProperty<T> properties (T being the type of the second parameter...
bool GetFloatProperty(const char *propertyKey, float &floatValue) const
Convenience method to access the value of a FloatProperty.
void FromJSON(const nlohmann::json &j)
Deserialize the property list from JSON.
mitk::BaseProperty * GetProperty(const std::string &propertyKey) const
Get a property by its name.
void Set(const char *propertyKey, bool boolValue)
ShortCut for the above method.
virtual void Clear()
void Set(const char *propertyKey, const char *stringValue)
ShortCut for the above method.
~PropertyList() override
void ReplaceProperty(const std::string &propertyKey, BaseProperty *property)
Set a property object in the list/map by reference.
const PropertyMap * GetMap() const
void Set(const char *propertyKey, double doubleValue)
ShortCut for the above method.
void SetIntProperty(const char *propertyKey, int intValue)
Convenience method to set the value of an IntProperty.
void Set(const char *propertyKey, const std::string &stringValue)
ShortCut for the above method.
std::pair< std::string, BaseProperty::Pointer > PropertyMapElementType
void SetFloatProperty(const char *propertyKey, float floatValue)
Convenience method to set the value of a FloatProperty.
bool GetIntProperty(const char *propertyKey, int &intValue) const
Convenience method to access the value of an IntProperty.
void ConcatenatePropertyList(PropertyList *pList, bool replace=false)
Set a property object in the list/map by reference.
void SetBoolProperty(const char *propertyKey, bool boolValue)
Convenience method to set the value of a BoolProperty.
PropertyList(const PropertyList &other)
bool Get(const char *propertyKey, bool &boolValue) const
ShortCut for the above method.
nlohmann::json json
Find image slices visible on a given plane.
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...