Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkSerializerMacros.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 mitkSerializerMacros_h
14 #define mitkSerializerMacros_h
15 
28 #include <itkObjectFactoryBase.h>
29 #include <itkVersion.h>
30 
51 #define MITK_REGISTER_SERIALIZER(classname) \
52  \
53 \
54 namespace mitk \
55  \
56 { \
57  \
58 class classname##Factory : public ::itk::ObjectFactoryBase \
59  \
60 { \
61  public: \
62  /* ITK typedefs */ \
63  typedef classname##Factory Self; \
64  typedef itk::ObjectFactoryBase Superclass; \
65  typedef itk::SmartPointer<Self> Pointer; \
66  typedef itk::SmartPointer<const Self> ConstPointer; \
67  \
68  /* Methods from ObjectFactoryBase */ \
69  virtual const char *GetITKSourceVersion() const override { return ITK_SOURCE_VERSION; } \
70  virtual const char *GetDescription() const override { return "Generated factory for " #classname; } \
71  /* Method for class instantiation. */ \
72  itkFactorylessNewMacro(Self); \
73  \
74  /* Run-time type information (and related methods). */ \
75  itkTypeMacro(classname##Factory, itkObjectFactoryBase); \
76  \
77  protected: \
78  classname##Factory() \
79  { \
80  itk::ObjectFactoryBase::RegisterOverride(#classname, \
81  #classname, \
82  "Generated factory for " #classname, \
83  1, \
84  itk::CreateObjectFunction<classname>::New()); \
85  } \
86  \
87  ~classname##Factory() {} \
88  private: \
89  classname##Factory(const Self &); /* purposely not implemented */ \
90  void operator=(const Self &); /* purposely not implemented */ \
91  \
92 }; \
93  \
94  class classname##RegistrationMethod \
95  { \
96  public: \
97  classname##RegistrationMethod() \
98  { \
99  m_Factory = classname##Factory::New(); \
100  itk::ObjectFactoryBase::RegisterFactory(m_Factory); \
101  } \
102  \
103  ~classname##RegistrationMethod() { itk::ObjectFactoryBase::UnRegisterFactory(m_Factory); } \
104  private: \
105  classname##Factory::Pointer m_Factory; \
106  }; \
107  \
108 } \
109  \
110 static mitk::classname##RegistrationMethod somestaticinitializer_##classname;
111 
112 #endif