Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
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 
121  template<typename A>
122  A* GetAdapter(const Object* adaptable)
123  {
124  const char* typeName = qobject_interface_iid<A*>();
125  if (typeName == nullptr)
126  {
127  BERRY_WARN << "Error getting adapter for '" << Reflection::GetClassName(adaptable) << "': "
128  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
129  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
130  return nullptr;
131  }
132  return dynamic_cast<A*>(this->GetAdapter(adaptable, typeName, false));
133  }
134 
152  virtual Object* GetAdapter(const Object* adaptable, const QString& adapterTypeName) = 0;
153 
172  virtual bool HasAdapter(const Object* adaptableType, const QString& adapterType) = 0;
173 
174  template<typename A>
175  int QueryAdapter(const Object* adaptable)
176  {
177  const char* typeName = qobject_interface_iid<A*>();
178  if (typeName == nullptr)
179  {
180  BERRY_WARN << "Error querying adapter manager for '" << Reflection::GetClassName(adaptable) << "': "
181  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
182  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
183  return NONE;
184  }
185  return this->QueryAdapter(adaptable, typeName);
186  }
187 
203  virtual int QueryAdapter(const Object* adaptableType, const QString& adapterType) = 0;
204 
222  template<typename A>
223  A* LoadAdapter(const Object* adaptable)
224  {
225  const char* typeName = qobject_interface_iid<A*>();
226  if (typeName == nullptr)
227  {
228  BERRY_WARN << "Error getting adapter for '" << Reflection::GetClassName(adaptable) << "': "
229  << "Cannot get the interface id for type '" << Reflection::GetClassName<A>()
230  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
231  return nullptr;
232  }
233  return dynamic_cast<A*>(this->GetAdapter(adaptable, typeName, true));
234  }
235 
244  virtual void RegisterAdapters(IAdapterFactory* factory,
245  const QString& adaptableTypeName) = 0;
246 
256  virtual void UnregisterAdapters(IAdapterFactory* factory) = 0;
257 
268  virtual void UnregisterAdapters(IAdapterFactory* factory,
269  const QString& adaptableTypeName) = 0;
270 
271 private:
272 
273  virtual Object* GetAdapter(const Object* adaptable, const QString& adapterType, bool force) = 0;
274 };
275 
276 } // namespace berry
277 
278 Q_DECLARE_INTERFACE(berry::IAdapterManager, "org.blueberry.service.IAdapterManager")
279 
280 #endif /*BERRYIADAPTERMANAGER_H_*/
berry::IAdapterManager::GetAdapter
A * GetAdapter(const Object *adaptable)
Definition: berryIAdapterManager.h:122
org_blueberry_core_runtime_Export.h
berry::Reflection::GetClassName
org_blueberry_core_runtime_EXPORT QString GetClassName(const Object *obj)
berry::IAdapterManager::LOADED
static const int LOADED
Definition: berryIAdapterManager.h:103
berryMacros.h
berry::Object
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
berryIAdapterFactory.h
berry::IAdapterManager::LoadAdapter
A * LoadAdapter(const Object *adaptable)
Definition: berryIAdapterManager.h:223
BERRY_WARN
#define BERRY_WARN
Definition: berryLog.h:21
berry::IAdapterManager
Definition: berryIAdapterManager.h:80
org_blueberry_core_runtime_EXPORT
#define org_blueberry_core_runtime_EXPORT
Definition: org_blueberry_core_runtime_Export.h:26
berry::IAdapterManager::NONE
static const int NONE
Definition: berryIAdapterManager.h:90
berry::IAdapterFactory
Definition: berryIAdapterFactory.h:36
berryPlatformObject.h
berry::IAdapterManager::NOT_LOADED
static const int NOT_LOADED
Definition: berryIAdapterManager.h:97
berryObjectMacro
#define berryObjectMacro(...)
Definition: berryMacros.h:31
berry::IAdapterManager::QueryAdapter
int QueryAdapter(const Object *adaptable)
Definition: berryIAdapterManager.h:175
berry
Definition: QmitkPropertyItemModel.h:24