Medical Imaging Interaction Toolkit  2026.06.00
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 {
54  class MITKCORE_EXPORT PropertyList : public itk::Object, public IPropertyOwner
55  {
56  public:
58 
62  itkFactorylessNewMacro(Self);
63  itkCloneMacro(Self);
64 
69  typedef std::map<std::string, BaseProperty::Pointer> PropertyMap;
70  typedef std::pair<std::string, BaseProperty::Pointer> PropertyMapElementType;
71 
72  // IPropertyProvider
73 
84  BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override;
85 
97  std::vector<std::string> GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override;
98 
108  std::vector<std::string> GetPropertyContextNames() const override;
109 
110  // IPropertyOwner
111 
122  BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override;
123 
142  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
143 
153  void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
154 
162  mitk::BaseProperty *GetProperty(const std::string &propertyKey) const;
163 
178  void ReplaceProperty(const std::string &propertyKey, BaseProperty *property);
179 
194  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
195 
208  template <typename T>
209  bool GetPropertyValue(const char *propertyKey, T &value) const
210  {
211  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey));
212  if (gp != nullptr)
213  {
214  value = gp->GetValue();
215  return true;
216  }
217  return false;
218  }
219 
227  bool GetBoolProperty(const char *propertyKey, bool &boolValue) const;
228 
236  bool Get(const char *propertyKey, bool &boolValue) const;
237 
246  void SetBoolProperty(const char *propertyKey, bool boolValue);
247 
254  void Set(const char *propertyKey, bool boolValue);
255 
263  bool GetIntProperty(const char *propertyKey, int &intValue) const;
264 
272  bool Get(const char *propertyKey, int &intValue) const;
273 
282  void SetIntProperty(const char *propertyKey, int intValue);
283 
290  void Set(const char *propertyKey, int intValue);
291 
299  bool GetFloatProperty(const char *propertyKey, float &floatValue) const;
300 
308  bool Get(const char *propertyKey, float &floatValue) const;
309 
318  void SetFloatProperty(const char *propertyKey, float floatValue);
319 
326  void Set(const char *propertyKey, float floatValue);
327 
335  bool GetDoubleProperty(const char *propertyKey, double &doubleValue) const;
336 
344  bool Get(const char *propertyKey, double &doubleValue) const;
345 
354  void SetDoubleProperty(const char *propertyKey, double doubleValue);
355 
362  void Set(const char *propertyKey, double doubleValue);
363 
371  bool GetStringProperty(const char *propertyKey, std::string &stringValue) const;
372 
380  bool Get(const char *propertyKey, std::string &stringValue) const;
381 
390  void SetStringProperty(const char *propertyKey, const char *stringValue);
391 
398  void Set(const char *propertyKey, const char *stringValue);
399 
406  void Set(const char *propertyKey, const std::string &stringValue);
407 
416  itk::ModifiedTimeType GetMTime() const override;
417 
424  bool DeleteProperty(const std::string &propertyKey);
425 
431  const PropertyMap *GetMap() const { return &m_Properties; }
432 
438  bool IsEmpty() const { return m_Properties.empty(); }
439 
443  virtual void Clear();
444 
454  void ToJSON(nlohmann::json& j) const;
455 
465  void FromJSON(const nlohmann::json& j);
466 
467  protected:
469  PropertyList(const Self &other);
470 
471  ~PropertyList() override;
472 
474 
479  };
480 
492 
504 
505 } // namespace mitk
506 
507 #endif
#define MITKCORE_EXPORT
Abstract base class for properties.
Template class for generating properties for simple value types (int, float, bool,...
virtual T GetValue() const
Get the property value.
Interface implemented by classes that provide write/read access to property information.
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 modification timestamp of the list.
void ToJSON(nlohmann::json &j) const
Serialize the property list to JSON.
void Set(const char *propertyKey, float floatValue)
Shortcut for SetFloatProperty().
bool Get(const char *propertyKey, int &intValue) const
Shortcut for GetIntProperty().
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
Remove a property from the list by key.
bool Get(const char *propertyKey, double &doubleValue) const
Shortcut for GetDoubleProperty().
PropertyList(const Self &other)
bool Get(const char *propertyKey, std::string &stringValue) const
Shortcut for GetStringProperty().
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
Retrieve a property by key (const version).
std::vector< std::string > GetPropertyContextNames() const override
Return available property context names.
void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName="", bool fallBackOnDefaultContext=false) override
Set a property in the list, preserving existing property type.
void Set(const char *propertyKey, int intValue)
Shortcut for SetIntProperty().
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 by key.
std::vector< std::string > GetPropertyKeys(const std::string &contextName="", bool includeDefaultContext=false) const override
Retrieve all property keys.
BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName="", bool fallBackOnDefaultContext=true) override
Retrieve a property by key (non-const version).
bool Get(const char *propertyKey, float &floatValue) const
Shortcut for GetFloatProperty().
bool GetPropertyValue(const char *propertyKey, T &value) const
Convenience access method for GenericProperty<T> properties.
bool GetFloatProperty(const char *propertyKey, float &floatValue) const
Convenience method to access the value of a FloatProperty.
bool IsEmpty() const
Check whether the property list contains no properties.
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 SetBoolProperty().
virtual void Clear()
Remove all properties from the list.
void Set(const char *propertyKey, const char *stringValue)
Shortcut for SetStringProperty() accepting a C-string.
~PropertyList() override
void ReplaceProperty(const std::string &propertyKey, BaseProperty *property)
Replace a property object in the list by a new one.
const PropertyMap * GetMap() const
Get a read-only pointer to the internal property map.
void Set(const char *propertyKey, double doubleValue)
Shortcut for SetDoubleProperty().
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 SetStringProperty() accepting a std::string.
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)
Merge another PropertyList into this one.
void SetBoolProperty(const char *propertyKey, bool boolValue)
Convenience method to set the value of a BoolProperty.
bool Get(const char *propertyKey, bool &boolValue) const
Shortcut for GetBoolProperty().
nlohmann::json json
Find image slices visible on a given plane.
static const char * replace[]
Dictionary for abbreviating class, module, and namespace names in log output.
MITKCORE_EXPORT nlohmann::json ConvertPropertyListToSelfContainedJson(const mitk::PropertyList *propertyList)
Serialize all properties from a PropertyList to self contained JSON representations.
MITKCORE_EXPORT PropertyList::Pointer ConvertPropertyListFromSelfContainedJson(const nlohmann::json &json)
Deserialize a property list from self contained JSON representations.