Medical Imaging Interaction Toolkit  2018.4.99-6a3ea89d
Medical Imaging Interaction Toolkit
berryIAdapterManager.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 BERRYIADAPTERMANAGER_H_
14 #define BERRYIADAPTERMANAGER_H_
15 
16 #include <berryMacros.h>
17 
19 
20 #include "berryPlatformObject.h"
21 #include "berryIAdapterFactory.h"
22 
23 #include <QtPlugin>
24 
25 #include <typeinfo>
26 
27 namespace berry
28 {
29 
81 {
82 
84 
90  static const int NONE;
91 
97  static const int NOT_LOADED;
98 
103  static const int LOADED;
104 
122  template<typename A>
123  A* GetAdapter(const Object* adaptable)
124  {
125  const char* typeName = qobject_interface_iid<A*>();
126  if (typeName == nullptr)
127  {
128  BERRY_WARN << "Error getting adapter for '" << Reflection::GetClassName(adaptable) << "': "
129  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
130  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
131  return nullptr;
132  }
133  return dynamic_cast<A*>(this->GetAdapter(adaptable, typeName, false));
134  }
135 
153  virtual Object* GetAdapter(const Object* adaptable, const QString& adapterTypeName) = 0;
154 
173  virtual bool HasAdapter(const Object* adaptableType, const QString& adapterType) = 0;
174 
175  template<typename A>
176  int QueryAdapter(const Object* adaptable)
177  {
178  const char* typeName = qobject_interface_iid<A*>();
179  if (typeName == nullptr)
180  {
181  BERRY_WARN << "Error querying adapter manager for '" << Reflection::GetClassName(adaptable) << "': "
182  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
183  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
184  return NONE;
185  }
186  return this->QueryAdapter(adaptable, typeName);
187  }
188 
204  virtual int QueryAdapter(const Object* adaptableType, const QString& adapterType) = 0;
205 
224  template<typename A>
225  A* LoadAdapter(const Object* adaptable)
226  {
227  const char* typeName = qobject_interface_iid<A*>();
228  if (typeName == nullptr)
229  {
230  BERRY_WARN << "Error getting adapter for '" << Reflection::GetClassName(adaptable) << "': "
231  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
232  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
233  return nullptr;
234  }
235  return dynamic_cast<A*>(this->GetAdapter(adaptable, typeName, true));
236  }
237 
247  virtual void RegisterAdapters(IAdapterFactory* factory,
248  const QString& adaptableTypeName) = 0;
249 
259  virtual void UnregisterAdapters(IAdapterFactory* factory) = 0;
260 
271  virtual void UnregisterAdapters(IAdapterFactory* factory,
272  const QString& adaptableTypeName) = 0;
273 
274 private:
275 
276  virtual Object* GetAdapter(const Object* adaptable, const QString& adapterType, bool force) = 0;
277 };
278 
279 } // namespace berry
280 
281 Q_DECLARE_INTERFACE(berry::IAdapterManager, "org.blueberry.service.IAdapterManager")
282 
283 #endif /*BERRYIADAPTERMANAGER_H_*/
QString GetClassName(const Object *obj)
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
A * GetAdapter(const Object *adaptable)
int QueryAdapter(const Object *adaptable)
#define org_blueberry_core_runtime_EXPORT
#define berryObjectMacro(...)
Definition: berryMacros.h:33
#define BERRY_WARN
Definition: berryLog.h:21
A * LoadAdapter(const Object *adaptable)