Medical Imaging Interaction Toolkit  2026.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>
111 void extensionTypeDeleteHelper(QObject* obj)
112 {
113  delete static_cast<T*>(obj);
114 }
115 
116 template <typename 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  return ExtensionType::registerType(typeName, &extensionTypeDeleteHelper<T>,
175  &extensionTypeConstructHelper<T>);
176 }
177 
178 } // end namespace berry
179 
180 
181 #endif // BERRY_EXTENSION_TYPES_H
The ExtensionType class manages named types.
static void destroy(int type, QObject *data)
static int registerTypedef(const char *typeName, int aliasId)
static const char * typeName(int type)
static void unregisterType(const char *typeName)
static int type(const char *typeName)
static bool isRegistered(int type)
static int registerType(const char *typeName, Destructor destructor, Constructor constructor)
static QObject * construct(int type)
QObject * extensionTypeConstructHelper()
void extensionTypeDeleteHelper(QObject *obj)
int registerExtensionType(const char *typeName, T *dummy=nullptr)
#define org_blueberry_core_runtime_EXPORT