Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkPropertyPersistenceInfo.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 mitkPropertyPersistenceInfo_h
14 #define mitkPropertyPersistenceInfo_h
15 
16 #include <functional>
17 
18 #include <mitkBaseProperty.h>
19 #include <mitkCommon.h>
20 
21 #include <MitkCoreExports.h>
22 #include <itkObjectFactory.h>
23 
24 namespace mitk
25 {
33  class MITKCORE_EXPORT PropertyPersistenceInfo : public itk::LightObject
34  {
35  public:
39  using DeserializationFunctionType = std::function<mitk::BaseProperty::Pointer(const std::string &)>;
40 
42  using SerializationFunctionType = std::function<std::string(const mitk::BaseProperty *)>;
43 
45  using MimeTypeNameType = std::string;
46 
48  itkFactorylessNewMacro(Self);
49  itkCloneMacro(Self) mitkNewMacro1Param(Self, const std::string &);
50  mitkNewMacro2Param(Self, const std::string &, const std::string &);
51 
53  std::string GetName() const;
54 
60  std::string GetKey() const;
61 
67  void SetName(const std::string &name);
68 
75  void SetNameAndKey(const std::string &name, const std::string &key);
76 
78  bool IsRegEx() const;
79 
89  void UseRegEx(const std::string &nameRegEx, const std::string &nameTemplate);
90 
102  void UseRegEx(const std::string &nameRegEx,
103  const std::string &nameTemplate,
104  const std::string &keyRegEx,
105  const std::string keyTemplate);
106 
108  const std::string &GetKeyTemplate() const;
109 
111  const std::string &GetNameTemplate() const;
112 
115 
119  void SetMimeTypeName(const MimeTypeNameType &mimeTypeName);
120 
123 
128 
131 
136 
144  PropertyPersistenceInfo::Pointer UnRegExByName(const std::string &propertyName) const;
145 
153  PropertyPersistenceInfo::Pointer UnRegExByKey(const std::string &key) const;
154 
161 
162  protected:
167  PropertyPersistenceInfo(const std::string &name = "");
168 
174  PropertyPersistenceInfo(const std::string &name, const std::string &mimeTypeName);
175 
177 
178  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
179 
180  private:
181  PropertyPersistenceInfo(const Self &other);
182  Self &operator=(const Self &other);
183 
184  struct Impl;
185  Impl *m_Impl;
186  };
187 
189  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &os, const PropertyPersistenceInfo &info);
190 
192  namespace PropertyPersistenceSerialization
193  {
198  MITKCORE_EXPORT::std::string serializeByGetValueAsString(const mitk::BaseProperty *prop);
199  }
200 
202  namespace PropertyPersistenceDeserialization
203  {
208  MITKCORE_EXPORT mitk::BaseProperty::Pointer deserializeToStringProperty(const std::string &value);
209  }
210 }
211 
212 #endif
#define MITKCORE_EXPORT
Abstract base class for properties.
const DeserializationFunctionType GetDeserializationFunction() const
Get the deserialization function used to convert a string back to a property.
const MimeTypeNameType & GetMimeTypeName() const
Get the MIME type name this persistence info is associated with.
void SetName(const std::string &name)
Set the property name (and key to the same value).
std::string GetKey() const
Get the persistence key used for this property.
std::function< mitk::BaseProperty::Pointer(const std::string &)> DeserializationFunctionType
Signature specification for functions that can be provided for deserialization of the property.
void SetMimeTypeName(const MimeTypeNameType &mimeTypeName)
Set the MIME type name this persistence info should be associated with.
PropertyPersistenceInfo::Pointer UnRegExByName(const std::string &propertyName) const
Create a non-regex info by resolving the regex against a property name.
const SerializationFunctionType GetSerializationFunction() const
Get the serialization function used to convert a property to a string.
PropertyPersistenceInfo(const std::string &name="")
Constructor.
std::function< std::string(const mitk::BaseProperty *)> SerializationFunctionType
Signature specification for functions that can be provided for serialization of the property.
bool IsRegEx() const
Check whether this info uses regular expressions for name and key matching.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
std::string GetName() const
Get the property name described by this info.
const std::string & GetKeyTemplate() const
Get the template string used for generating concrete keys from regex groups.
PropertyPersistenceInfo(const std::string &name, const std::string &mimeTypeName)
Constructor.
void UseRegEx(const std::string &nameRegEx, const std::string &nameTemplate)
Set the name and key as a regular expression with a shared template.
mitkNewMacro2Param(Self, const std::string &, const std::string &)
std::string MimeTypeNameType
Type alias for MIME type name strings.
void SetNameAndKey(const std::string &name, const std::string &key)
Set name and key independently.
void SetDeserializationFunction(const DeserializationFunctionType &fnc)
Set the deserialization function.
PropertyPersistenceInfo::Pointer UnRegExByKey(const std::string &key) const
Create a non-regex info by resolving the regex against a persistence key.
const std::string & GetNameTemplate() const
Get the template string used for generating concrete names from regex groups.
static MimeTypeNameType ANY_MIMETYPE_NAME()
Return the MIME type name that indicates compatibility with any MIME type.
mitkClassMacroItkParent(PropertyPersistenceInfo, itk::LightObject)
void SetSerializationFunction(const SerializationFunctionType &fnc)
Set the serialization function.
void UseRegEx(const std::string &nameRegEx, const std::string &nameTemplate, const std::string &keyRegEx, const std::string keyTemplate)
Set the name and key as separate regular expressions with individual templates.
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:62
MITKCORE_EXPORT mitk::BaseProperty::Pointer deserializeToStringProperty(const std::string &value)
Default deserialization that creates a StringProperty from the passed string.
MITKCORE_EXPORT::std::string serializeByGetValueAsString(const mitk::BaseProperty *prop)
Default serialization that uses BaseProperty::GetValueAsString().
Find image slices visible on a given plane.
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
Stream output operator for DataNode smart pointers.