Medical Imaging Interaction Toolkit  2023.12.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 {
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:
252  PropertyList();
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
mitk::BaseProperty
Abstract base class for properties.
Definition: mitkBaseProperty.h:36
mitk::GenericProperty::GetValue
virtual T GetValue() const
mitkGenericProperty.h
itk::SmartPointer< const Self >
mitk::GenericProperty
Definition: mitkGenericProperty.h:46
mitk::PropertyList::GetPropertyValue
bool GetPropertyValue(const char *propertyKey, T &value) const
Convenience access method for GenericProperty<T> properties (T being the type of the second parameter...
Definition: mitkPropertyList.h:109
mitk::PropertyList::IsEmpty
bool IsEmpty() const
Definition: mitkPropertyList.h:226
mitkClassMacroItkParent
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:45
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::PropertyList::GetMap
const PropertyMap * GetMap() const
Definition: mitkPropertyList.h:225
mitkIPropertyOwner.h
json
nlohmann::json json
Definition: mitkModelTestFixture.h:29
mitk::PropertyList::PropertyMap
std::map< std::string, BaseProperty::Pointer > PropertyMap
Definition: mitkPropertyList.h:65
mitk::PropertyList
Key-value list holding instances of BaseProperty.
Definition: mitkPropertyList.h:56
mitk::ROIMapperHelper::GetConstProperty
const T * GetConstProperty(const std::string &propertyKey, const ROI::Element &roi, TimeStepType t)
Syntactic sugar for getting ROI properties.
Definition: mitkROIMapperHelper.h:48
mitk::PropertyList::m_Properties
PropertyMap m_Properties
Map of properties.
Definition: mitkPropertyList.h:260
mitk::MitkMultilabelIOMimeTypes::Get
MITKMULTILABELIO_EXPORT std::vector< CustomMimeType * > Get()
mitk::IPropertyOwner
Definition: mitkIPropertyOwner.h:22
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::PropertyList::PropertyMapElementType
std::pair< std::string, BaseProperty::Pointer > PropertyMapElementType
Definition: mitkPropertyList.h:72
mitk::replace
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
Definition: mitkLogDictionary.h:20