Medical Imaging Interaction Toolkit  2018.4.99-9a29ffc6
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 PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D
14 #define PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D
15 
16 #include "mitkBaseProperty.h"
17 #include "mitkGenericProperty.h"
18 #include "mitkUIDGenerator.h"
19 #include "mitkIPropertyOwner.h"
20 #include <MitkCoreExports.h>
21 
22 #include <itkObjectFactory.h>
23 
24 #include <map>
25 #include <string>
26 
27 namespace mitk
28 {
29  class XMLWriter;
30 
64  class MITKCORE_EXPORT PropertyList : public itk::Object, public IPropertyOwner
65  {
66  public:
68 
72  itkFactorylessNewMacro(Self);
73  itkCloneMacro(Self);
74 
79  typedef std::map<std::string, BaseProperty::Pointer> PropertyMap;
80  typedef std::pair<std::string, BaseProperty::Pointer> PropertyMapElementType;
81 
82  // IPropertyProvider
83  BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override;
84  std::vector<std::string> GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override;
85  std::vector<std::string> GetPropertyContextNames() const override;
86 
87  // IPropertyOwner
88  BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override;
89  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
90  void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
91 
95  mitk::BaseProperty *GetProperty(const std::string &propertyKey) const;
96 
105  void ReplaceProperty(const std::string &propertyKey, BaseProperty *property);
106 
110  void ConcatenatePropertyList(PropertyList *pList, bool replace = false);
111 
112  //##Documentation
113  //## @brief Convenience access method for GenericProperty<T> properties
114  //## (T being the type of the second parameter)
115  //## @return @a true property was found
116  template <typename T>
117  bool GetPropertyValue(const char *propertyKey, T &value) const
118  {
119  GenericProperty<T> *gp = dynamic_cast<GenericProperty<T> *>(GetProperty(propertyKey));
120  if (gp != nullptr)
121  {
122  value = gp->GetValue();
123  return true;
124  }
125  return false;
126  }
127 
131  bool GetBoolProperty(const char *propertyKey, bool &boolValue) const;
135  bool Get(const char *propertyKey, bool &boolValue) const;
136 
140  void SetBoolProperty(const char *propertyKey, bool boolValue);
144  void Set(const char *propertyKey, bool boolValue);
145 
149  bool GetIntProperty(const char *propertyKey, int &intValue) const;
153  bool Get(const char *propertyKey, int &intValue) const;
154 
158  void SetIntProperty(const char *propertyKey, int intValue);
162  void Set(const char *propertyKey, int intValue);
163 
167  bool GetFloatProperty(const char *propertyKey, float &floatValue) const;
171  bool Get(const char *propertyKey, float &floatValue) const;
172 
176  void SetFloatProperty(const char *propertyKey, float floatValue);
180  void Set(const char *propertyKey, float floatValue);
181 
185  bool GetDoubleProperty(const char *propertyKey, double &doubleValue) const;
189  bool Get(const char *propertyKey, double &doubleValue) const;
190 
194  void SetDoubleProperty(const char *propertyKey, double doubleValue);
198  void Set(const char *propertyKey, double doubleValue);
199 
203  bool GetStringProperty(const char *propertyKey, std::string &stringValue) const;
207  bool Get(const char *propertyKey, std::string &stringValue) const;
208 
212  void SetStringProperty(const char *propertyKey, const char *stringValue);
216  void Set(const char *propertyKey, const char *stringValue);
220  void Set(const char *propertyKey, const std::string &stringValue);
221 
226  unsigned long GetMTime() const override;
227 
231  bool DeleteProperty(const std::string &propertyKey);
232 
233  const PropertyMap *GetMap() const { return &m_Properties; }
234  bool IsEmpty() const { return m_Properties.empty(); }
235  virtual void Clear();
236 
237  protected:
238  PropertyList();
239  PropertyList(const PropertyList &other);
240 
241  ~PropertyList() override;
242 
246  PropertyMap m_Properties;
247 
248  private:
249  itk::LightObject::Pointer InternalClone() const override;
250  };
251 
252 } // namespace mitk
253 
254 #endif /* PROPERTYLIST_H_HEADER_INCLUDED_C1C77D8D */
#define MITKCORE_EXPORT
signed integer value
Definition: jsoncpp.h:348
std::pair< std::string, BaseProperty::Pointer > PropertyMapElementType
DataCollection - Class to facilitate loading/accessing structured data.
Key-value list holding instances of BaseProperty.
virtual T GetValue() const
bool GetPropertyValue(const char *propertyKey, T &value) const
Convenience access method for GenericProperty<T> properties (T being the type of the second parameter...
Abstract base class for properties.
std::map< std::string, BaseProperty::Pointer > PropertyMap
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:49
PropertyMap m_Properties
Map of properties.
UTF-8 string value.
Definition: jsoncpp.h:351
static const char * replace[]
This is a dictionary to replace long names of classes, modules, etc. to shorter versions in the conso...
const PropertyMap * GetMap() const