Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
berryIServiceLocator.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 
14 #ifndef BERRYISERVICELOCATOR_H_
15 #define BERRYISERVICELOCATOR_H_
16 
18 
19 #include <berryObject.h>
20 #include <berryMacros.h>
21 #include <berryLog.h>
22 
23 #include <QObject>
24 
25 #include <typeinfo>
26 
27 namespace berry {
28 
43 struct BERRY_UI_QT IServiceLocator : public virtual Object
44 {
45 
47 
48  ~IServiceLocator() override;
49 
59  template<class S>
61  {
62  const char* typeName = qobject_interface_iid<S*>();
63  if (typeName == nullptr)
64  {
65  BERRY_WARN << "Error getting service: Cannot get the interface id for type '" << Reflection::GetClassName<S>()
66  << "'. It is probably missing a Q_DECLARE_INTERFACE macro in its header.";
67  return nullptr;
68  }
69  Object* obj = this->GetService(typeName);
70  S* service = dynamic_cast<S*>(obj);
71  if (obj != nullptr && service == nullptr)
72  {
73  BERRY_WARN << "Error getting service: Class '" << obj->GetClassName() << "' cannot be cast to service interface "
74  << "'" << Reflection::GetClassName<S>() << "'";
75  }
76  return service;
77  }
78 
91  template<class S>
92  bool HasService() const
93  {
94  return this->HasService(qobject_interface_iid<S*>());
95  }
96 
97  virtual Object* GetService(const QString& api) = 0;
98  virtual bool HasService(const QString& api) const = 0;
99 };
100 
101 }
102 
103 #endif /* BERRYISERVICELOCATOR_H_ */
org_blueberry_ui_qt_Export.h
berry::IServiceLocator::GetService
S * GetService()
Definition: berryIServiceLocator.h:60
berry::IServiceLocator
Definition: berryIServiceLocator.h:43
berryLog.h
berry::IServiceLocator::HasService
bool HasService() const
Definition: berryIServiceLocator.h:92
berryMacros.h
berry::Object
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
BERRY_WARN
#define BERRY_WARN
Definition: berryLog.h:21
BERRY_UI_QT
#define BERRY_UI_QT
Definition: org_blueberry_ui_qt_Export.h:26
berry::Object::GetClassName
virtual QString GetClassName() const
berryObjectMacro
#define berryObjectMacro(...)
Definition: berryMacros.h:31
berryObject.h
berry
Definition: QmitkPropertyItemModel.h:24