Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
berryExtensionType.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 BERRY_EXTENSION_TYPES_H
14 #define BERRY_EXTENSION_TYPES_H
15 
17 
18 #include <QObject>
19 
20 namespace berry {
21 
35 {
36 
37 public:
38 
39  typedef void (*Destructor)(QObject *);
40  typedef QObject* (*Constructor)();
41 
48  static int registerType(const char* typeName, Destructor destructor,
49  Constructor constructor);
50 
56  static int registerTypedef(const char* typeName, int aliasId);
57 
64  static void unregisterType(const char* typeName);
65 
73  static int type(const char* typeName);
74 
82  static const char* typeName(int type);
83 
91  static bool isRegistered(int type);
92 
99  static QObject* construct(int type);
100 
107  static void destroy(int type, QObject* data);
108 };
109 
110 template <typename T>
112 {
113  delete t;
114 }
115 
116 template <typename T>
117 QObject* extensionTypeConstructHelper(const T* /*t*/)
118 {
119  return new T;
120 }
121 
122 template <typename T>
124 {
125  enum { Defined = 0 };
126 };
127 
128 template <typename T>
130 {
132  static inline int extensiontype_id() { return ExtensionTypeId<T>::extensiontype_id(); }
133 };
134 
135 namespace internal {
136 
137 template <typename T, bool Defined = ExtensionTypeId2<T>::Defined>
139 {
140  static inline int extensiontype_id()
142 };
143 
144 template <typename T>
145 struct ExtensionTypeIdHelper<T, false>
146 {
147  static inline int extensiontype_id()
148  { return -1; }
149 };
150 
151 } // end namespace internal
152 
163 template <typename T>
164 int registerExtensionType(const char* typeName
165 #ifndef DOXYGEN_SKIP
166  , T* dummy = nullptr
167 #endif
168 )
169 {
170  const int typedefOf = dummy ? -1 : internal::ExtensionTypeIdHelper<T>::extensiontype_id();
171  if (typedefOf != -1)
172  return ExtensionType::registerTypedef(typeName, typedefOf);
173 
174  typedef QObject*(*ConstructPtr)(const T*);
175  ConstructPtr cptr = extensionTypeConstructHelper<T>;
176  typedef void(*DeletePtr)(T*);
177  DeletePtr dptr = extensionTypeDeleteHelper<T>;
178 
179  return ExtensionType::registerType(typeName, reinterpret_cast<ExtensionType::Destructor>(dptr),
180  reinterpret_cast<ExtensionType::Constructor>(cptr));
181 }
182 
183 } // end namespace berry
184 
185 
186 #endif // BERRY_EXTENSION_TYPES_H
org_blueberry_core_runtime_Export.h
berry::ExtensionTypeId2::extensiontype_id
static int extensiontype_id()
Definition: berryExtensionType.h:132
berry::ExtensionType::registerTypedef
static int registerTypedef(const char *typeName, int aliasId)
berry::internal::ExtensionTypeIdHelper
Definition: berryExtensionType.h:138
berry::ExtensionType::registerType
static int registerType(const char *typeName, Destructor destructor, Constructor constructor)
org_blueberry_core_runtime_EXPORT
#define org_blueberry_core_runtime_EXPORT
Definition: org_blueberry_core_runtime_Export.h:26
berry::ExtensionTypeId::Defined
@ Defined
Definition: berryExtensionType.h:125
berry::ExtensionTypeId2::Defined
@ Defined
Definition: berryExtensionType.h:131
berry::ExtensionType
The ExtensionType class manages named types.
Definition: berryExtensionType.h:34
berry::registerExtensionType
int registerExtensionType(const char *typeName, T *dummy=nullptr)
Definition: berryExtensionType.h:164
berry::ExtensionType::Constructor
QObject *(* Constructor)()
Definition: berryExtensionType.h:40
berry::ExtensionTypeId
Definition: berryExtensionType.h:123
berry::ExtensionType::Destructor
void(* Destructor)(QObject *)
Definition: berryExtensionType.h:39
berry::extensionTypeDeleteHelper
void extensionTypeDeleteHelper(T *t)
Definition: berryExtensionType.h:111
berry::ExtensionTypeId2
Definition: berryExtensionType.h:129
berry::internal::ExtensionTypeIdHelper::extensiontype_id
static int extensiontype_id()
Definition: berryExtensionType.h:140
berry::extensionTypeConstructHelper
QObject * extensionTypeConstructHelper(const T *)
Definition: berryExtensionType.h:117
berry
Definition: QmitkPropertyItemModel.h:24
berry::internal::ExtensionTypeIdHelper< T, false >::extensiontype_id
static int extensiontype_id()
Definition: berryExtensionType.h:147