Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
berryIAdapterManager.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 BERRYIADAPTERMANAGER_H_
18 #define BERRYIADAPTERMANAGER_H_
19 
20 #include <berryMacros.h>
21 
23 
24 #include "berryPlatformObject.h"
25 #include "berryIAdapterFactory.h"
26 
27 #include <QtPlugin>
28 
29 #include <typeinfo>
30 
31 namespace berry
32 {
33 
85 {
86 
88 
89 
94  static const int NONE;
95 
101  static const int NOT_LOADED;
102 
107  static const int LOADED;
108 
126  template<typename A>
127  A* GetAdapter(const Object* adaptable)
128  {
129  const char* typeName = qobject_interface_iid<A*>();
130  if (typeName == nullptr)
131  {
132  BERRY_WARN << "Error getting adapter for '" << Reflection::GetClassName(adaptable) << "': "
133  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
134  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
135  return nullptr;
136  }
137  return dynamic_cast<A*>(this->GetAdapter(adaptable, typeName, false));
138  }
139 
157  virtual Object* GetAdapter(const Object* adaptable, const QString& adapterTypeName) = 0;
158 
177  virtual bool HasAdapter(const Object* adaptableType, const QString& adapterType) = 0;
179  template<typename A>
180  int QueryAdapter(const Object* adaptable)
181  {
182  const char* typeName = qobject_interface_iid<A*>();
183  if (typeName == nullptr)
184  {
185  BERRY_WARN << "Error querying adapter manager for '" << Reflection::GetClassName(adaptable) << "': "
186  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
187  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
188  return NONE;
189  }
190  return this->QueryAdapter(adaptable, typeName);
191  }
192 
208  virtual int QueryAdapter(const Object* adaptableType, const QString& adapterType) = 0;
209 
228  template<typename A>
229  A* LoadAdapter(const Object* adaptable)
230  {
231  const char* typeName = qobject_interface_iid<A*>();
232  if (typeName == nullptr)
233  {
234  BERRY_WARN << "Error getting adapter for '" << Reflection::GetClassName(adaptable) << "': "
235  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
236  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
237  return NULL;
238  }
239  return dynamic_cast<A*>(this->GetAdapter(adaptable, typeName, true));
240  }
241 
251  virtual void RegisterAdapters(IAdapterFactory* factory,
252  const QString& adaptableTypeName) = 0;
253 
263  virtual void UnregisterAdapters(IAdapterFactory* factory) = 0;
264 
275  virtual void UnregisterAdapters(IAdapterFactory* factory,
276  const QString& adaptableTypeName) = 0;
277 
278 private:
279 
280  virtual Object* GetAdapter(const Object* adaptable, const QString& adapterType, bool force) = 0;
281 };
282 
283 } // namespace berry
284 
285 Q_DECLARE_INTERFACE(berry::IAdapterManager, "org.blueberry.service.IAdapterManager")
286 
287 #endif /*BERRYIADAPTERMANAGER_H_*/
QString GetClassName(const Object *obj)
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:78
#define org_blueberry_core_runtime_EXPORT
#define berryObjectMacro(...)
Definition: berryMacros.h:37
#define BERRY_WARN
Definition: berryLog.h:25