Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkSmartPointerProperty.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 mitkSmartPointerProperty_h
14 #define mitkSmartPointerProperty_h
15 
16 #include <mitkBaseProperty.h>
17 #include <mitkUIDGenerator.h>
18 #include <MitkCoreExports.h>
19 
20 #include <list>
21 #include <map>
22 #include <string>
23 
24 namespace mitk
25 {
40  {
41  public:
43  itkFactorylessNewMacro(Self);
44  itkCloneMacro(Self);
46 
48  typedef itk::Object::Pointer ValueType;
49 
54  itk::Object::Pointer GetSmartPointer() const;
55 
61 
70  void SetSmartPointer(itk::Object *);
71 
77  void SetValue(const ValueType &);
78 
86  std::string GetValueAsString() const override;
87 
94  static void PostProcessXMLReading();
95 
101  static unsigned int GetReferenceCountFor(itk::Object *);
102 
108  static std::string GetReferenceUIDFor(itk::Object *);
109 
115  static void RegisterPointerTarget(itk::Object *, const std::string uid);
116 
123  bool ToJSON(nlohmann::json& j) const override;
124 
131  bool FromJSON(const nlohmann::json& j) override;
132 
133  using BaseProperty::operator=;
134 
135  protected:
136  SmartPointerProperty(itk::Object * = nullptr);
138 
139  itk::Object::Pointer m_SmartPointer;
140 
142 
143  private:
144  // purposely not implemented
145  SmartPointerProperty &operator=(const SmartPointerProperty &);
146 
147  bool IsEqual(const BaseProperty &) const override;
148  bool Assign(const BaseProperty &) override;
149 
150  typedef std::map<itk::Object *, unsigned int> ReferenceCountMapType;
151  typedef std::map<itk::Object *, std::string> ReferencesUIDMapType;
152  typedef std::map<SmartPointerProperty *, std::string> ReadInSmartPointersMapType;
153  typedef std::map<std::string, itk::Object *> ReadInTargetsMapType;
154 
156  static ReferenceCountMapType m_ReferenceCount;
157  static ReferencesUIDMapType m_ReferencesUID;
158  static ReadInSmartPointersMapType m_ReadInInstances;
159  static ReadInTargetsMapType m_ReadInTargets;
160 
162  static UIDGenerator m_UIDGenerator;
163  };
164 
165 
166 } // namespace mitk
167 
168 #endif
#define MITKCORE_EXPORT
Abstract base class for properties.
Property containing a smart pointer to an itk::Object.
static std::string GetReferenceUIDFor(itk::Object *)
Get the reference UID for the given object.
itk::Object::Pointer GetSmartPointer() const
Get the stored smart pointer.
bool FromJSON(const nlohmann::json &j) override
JSON deserialization is not supported for SmartPointerProperty.
std::string GetValueAsString() const override
Return the UID of the pointed-to object as a string.
SmartPointerProperty(const SmartPointerProperty &)
SmartPointerProperty(itk::Object *=nullptr)
bool ToJSON(nlohmann::json &j) const override
JSON serialization is not supported for SmartPointerProperty.
void SetSmartPointer(itk::Object *)
Set the stored smart pointer.
ValueType GetValue() const
Get the stored smart pointer (alias for GetSmartPointer()).
mitkCloneMacro(SmartPointerProperty)
mitkClassMacro(SmartPointerProperty, BaseProperty)
static void RegisterPointerTarget(itk::Object *, const std::string uid)
Register an object as a potential target for XML deserialization.
void SetValue(const ValueType &)
Set the stored smart pointer (alias for SetSmartPointer()).
static unsigned int GetReferenceCountFor(itk::Object *)
Get the number of SmartPointerProperties referencing the given object.
static void PostProcessXMLReading()
Resolve all smart pointer references after XML deserialization.
mitkNewMacro1Param(SmartPointerProperty, itk::Object *)
itk::Object::Pointer ValueType
The type of the value stored by this property.
Generates unique identifier strings.
nlohmann::json json
Find image slices visible on a given plane.