Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryExtensionType.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 BlueBerry Platform
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef BERRY_EXTENSION_TYPES_H
18 #define BERRY_EXTENSION_TYPES_H
19 
21 
22 #include <QObject>
23 
24 namespace berry {
25 
40 {
41 
42 public:
43 
44  typedef void (*Destructor)(QObject *);
45  typedef QObject* (*Constructor)();
46 
53  static int registerType(const char* typeName, Destructor destructor,
54  Constructor constructor);
55 
61  static int registerTypedef(const char* typeName, int aliasId);
62 
69  static void unregisterType(const char* typeName);
70 
78  static int type(const char* typeName);
79 
87  static const char* typeName(int type);
88 
96  static bool isRegistered(int type);
97 
104  static QObject* construct(int type);
105 
112  static void destroy(int type, QObject* data);
113 };
114 
115 template <typename T>
117 {
118  delete t;
119 }
120 
121 template <typename T>
122 QObject* extensionTypeConstructHelper(const T* /*t*/)
123 {
124  return new T;
125 }
126 
127 template <typename T>
129 {
130  enum { Defined = 0 };
131 };
132 
133 template <typename T>
135 {
137  static inline int extensiontype_id() { return ExtensionTypeId<T>::extensiontype_id(); }
138 };
139 
140 namespace internal {
141 
142 template <typename T, bool Defined = ExtensionTypeId2<T>::Defined>
144 {
145  static inline int extensiontype_id()
147 };
148 
149 template <typename T>
150 struct ExtensionTypeIdHelper<T, false>
151 {
152  static inline int extensiontype_id()
153  { return -1; }
154 };
155 
156 } // end namespace internal
157 
169 template <typename T>
170 int registerExtensionType(const char* typeName
171 #ifndef DOXYGEN_SKIP
172  , T* dummy = 0
173 #endif
174 )
175 {
176  const int typedefOf = dummy ? -1 : internal::ExtensionTypeIdHelper<T>::extensiontype_id();
177  if (typedefOf != -1)
178  return ExtensionType::registerTypedef(typeName, typedefOf);
179 
180  typedef QObject*(*ConstructPtr)(const T*);
181  ConstructPtr cptr = extensionTypeConstructHelper<T>;
182  typedef void(*DeletePtr)(T*);
183  DeletePtr dptr = extensionTypeDeleteHelper<T>;
184 
185  return ExtensionType::registerType(typeName, reinterpret_cast<ExtensionType::Destructor>(dptr),
186  reinterpret_cast<ExtensionType::Constructor>(cptr));
187 }
188 
189 } // end namespace berry
190 
191 
192 #endif // BERRY_EXTENSION_TYPES_H
int registerExtensionType(const char *typeName, T *dummy=0)
#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)
void extensionTypeDeleteHelper(T *t)
static int registerTypedef(const char *typeName, int aliasId)