Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkCommon.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 mitkCommon_h
14 #define mitkCommon_h
15 
16 // add only those headers here that are really necessary for all classes!
17 #include <itkObject.h>
18 #include <mitkConfig.h>
19 #include <mitkExceptionMacro.h>
20 #include <mitkGetClassHierarchy.h>
21 #include <mitkLog.h>
22 
23 typedef unsigned int MapperSlotId;
24 
30 #define mitkClassMacro(className, SuperClassName) \
31  typedef className Self; \
32  typedef SuperClassName Superclass; \
33  typedef itk::SmartPointer<Self> Pointer; \
34  typedef itk::SmartPointer<const Self> ConstPointer; \
35  static const char *GetStaticNameOfClass() { return #className; } \
36  virtual std::vector<std::string> GetClassHierarchy() const override { return mitk::GetClassHierarchy<Self>(); } \
37  itkTypeMacro(className, SuperClassName);
38 
39 #define mitkClassMacroItkParent(className, SuperClassName) \
40  typedef className Self; \
41  typedef SuperClassName Superclass; \
42  typedef itk::SmartPointer<Self> Pointer; \
43  typedef itk::SmartPointer<const Self> ConstPointer; \
44  static const char *GetStaticNameOfClass() { return #className; } \
45  virtual std::vector<std::string> GetClassHierarchy() const { return mitk::GetClassHierarchy<Self>(); } \
46  itkTypeMacro(className, SuperClassName);
47 
51 #define mitkClassMacroNoParent(className) \
52  typedef className Self; \
53  typedef itk::SmartPointer<Self> Pointer; \
54  typedef itk::SmartPointer<const Self> ConstPointer; \
55  static const char *GetStaticNameOfClass() { return #className; } \
56  virtual std::vector<std::string> GetClassHierarchy() const { return mitk::GetClassHierarchy<Self>(); } \
57  itkTypeMacroNoParent(className)
58 
62 #define mitkNewMacro1Param(classname, type) \
63  \
64  static Pointer New(type _arg) \
65  \
66  { \
67  Pointer smartPtr = new classname(_arg); \
68  smartPtr->UnRegister(); \
69  return smartPtr; \
70  }
71 
75 #define mitkNewMacro2Param(classname, typea, typeb) \
76  \
77  static Pointer New(typea _arga, typeb _argb) \
78  \
79  { \
80  Pointer smartPtr = new classname(_arga, _argb); \
81  smartPtr->UnRegister(); \
82  return smartPtr; \
83  }
84 
88 #define mitkNewMacro3Param(classname, typea, typeb, typec) \
89  \
90  static Pointer New(typea _arga, typeb _argb, typec _argc) \
91  \
92  { \
93  Pointer smartPtr = new classname(_arga, _argb, _argc); \
94  smartPtr->UnRegister(); \
95  return smartPtr; \
96  }
97 
101 #define mitkNewMacro4Param(classname, typea, typeb, typec, typed) \
102  \
103  static Pointer New(typea _arga, typeb _argb, typec _argc, typed _argd) \
104  \
105  { \
106  Pointer smartPtr = new classname(_arga, _argb, _argc, _argd); \
107  smartPtr->UnRegister(); \
108  return smartPtr; \
109  }
110 
114 #define mitkNewMacro5Param(classname, typea, typeb, typec, typed, typee) \
115  \
116  static Pointer New(typea _arga, typeb _argb, typec _argc, typed _argd, typee _arge) \
117  \
118  { \
119  Pointer smartPtr = new classname(_arga, _argb, _argc, _argd, _arge); \
120  smartPtr->UnRegister(); \
121  return smartPtr; \
122  }
123 
127 #define mitkNewMacro6Param(classname, typea, typeb, typec, typed, typee, typef) \
128  \
129  static Pointer New(typea _arga, typeb _argb, typec _argc, typed _argd, typee _arge, typef _argf) \
130  \
131  { \
132  Pointer smartPtr = new classname(_arga, _argb, _argc, _argd, _arge, _argf); \
133  smartPtr->UnRegister(); \
134  return smartPtr; \
135  }
136 
139 #define mitkGetObjectMacroConst(name, type) \
140  virtual type *Get##name() const \
141  { \
142  itkDebugMacro("returning " #name " address " << this->m_##name); \
143  return this->m_##name.GetPointer(); \
144  }
145 
148 #define mitkCloneMacro(classname) \
149  virtual itk::LightObject::Pointer InternalClone() const override \
150  \
151  { \
152  Pointer smartPtr = new classname(*this); \
153  smartPtr->UnRegister(); \
154  return smartPtr.GetPointer(); \
155  }
156 
169 #define mitkOverrideSetStringMacro(name) \
170  void Set##name(const char *_arg) override \
171  { \
172  if (_arg && (_arg == this->m_##name)) \
173  { \
174  return; \
175  } \
176  if (_arg) \
177  { \
178  this->m_##name = _arg; \
179  } \
180  else \
181  { \
182  this->m_##name = ""; \
183  } \
184  this->Modified(); \
185  } \
186  void Set##name(const std::string &_arg) { this->Set##name(_arg.c_str()); } \
187  ITK_MACROEND_NOOP_STATEMENT
188 
189 #define mitkOverrideGetStringMacro(name) \
190  const char *Get##name() const override { return this->m_##name.c_str(); } \
191  ITK_MACROEND_NOOP_STATEMENT
192 
193 #define mitkOverrideSetConstObjectMacro(name, type) \
194  void Set##name(const type *_arg) override \
195  { \
196  itkDebugMacro("setting " << #name " to " << _arg); \
197  if (this->m_##name != _arg) \
198  { \
199  this->m_##name = _arg; \
200  this->Modified(); \
201  } \
202  } \
203  ITK_MACROEND_NOOP_STATEMENT
204 
205 #define mitkOverrideGetConstObjectMacro(name, type) \
206  const type *Get##name() const override { return this->m_##name.GetPointer(); } \
207  ITK_MACROEND_NOOP_STATEMENT
208 
213 #if defined(__clang__) || defined(__GNUC__)
214 #define MITK_EXPORT __attribute__((visibility("default")))
215 #define MITK_IMPORT __attribute__((visibility("default")))
216 #define MITK_LOCAL __attribute__((visibility("hidden")))
217 #elif defined(WIN32)
218 #define MITK_EXPORT __declspec(dllexport)
219 #define MITK_IMPORT __declspec(dllimport)
220 #define MITK_LOCAL
221 #else
222 #define MITK_EXPORT
223 #define MITK_IMPORT
224 #define MITK_LOCAL
225 #endif
226 
227 #endif
unsigned int MapperSlotId
Definition: mitkCommon.h:23