Medical Imaging Interaction Toolkit  2018.4.99-36d69b77
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 {
131  enum { Defined = ExtensionTypeId<T>::Defined };
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
#define org_blueberry_core_runtime_EXPORT
The ExtensionType class manages named types.
QObject * extensionTypeConstructHelper(const T *)
static int registerType(const char *typeName, Destructor destructor, Constructor constructor)
int registerExtensionType(const char *typeName, T *dummy=nullptr)
void extensionTypeDeleteHelper(T *t)
static int registerTypedef(const char *typeName, int aliasId)