Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ISvcLocator.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
2 #define GAUDIKERNEL_ISVCLOCATOR_H 1
3 
4 // Include files
7 #include "GaudiKernel/SmartIF.h"
9 #include <list>
10 #include <string>
11 
12 // Forward class declaration
13 class IService;
14 
25 class GAUDI_API ISvcLocator : virtual public IInterface {
26 public:
29 
30 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
31 
36  const bool createIf = true ) {
37  SmartIF<IService>& s = service( typeName, createIf );
38  svc = s.get();
39  if ( svc ) {
40  svc->addRef(); // Needed to maintain the correct reference counting.
41  return StatusCode::SUCCESS;
42  }
43  return StatusCode::FAILURE;
44  }
45 
52  IInterface*& pinterface ) {
53  auto svc = service( typeName, false );
54  return svc ? svc->queryInterface( iid, (void**)&pinterface ) : StatusCode::FAILURE;
55  }
56 
62 // virtual StatusCode getService( const Gaudi::Utils::TypeNameString& name,
63 // IService*& svc,
64 // bool createIf ) = 0;
65 #endif
66 
68  virtual const std::list<IService*>& getServices() const = 0;
69 
71  virtual bool existsService( const std::string& name ) const = 0;
72 
73 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
74  template <class T>
76  StatusCode service( const Gaudi::Utils::TypeNameString& name, T*& svc, bool createIf = true ) {
77  if ( createIf ) {
78  IService* s;
79  StatusCode sc = getService( name, s, true );
80  if ( !sc.isSuccess() ) return sc; // Must check if initialization was OK!
81  }
82  return getService( name, T::interfaceID(), (IInterface*&)svc );
83  }
84 
86  template <class T>
87  StatusCode service( const std::string& type, const std::string& name, T*& svc, bool createIf = true ) {
88  return service( type + "/" + name, svc, createIf );
89  }
90 #endif
91 
93  virtual SmartIF<IService>& service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) = 0;
94 
96  template <typename T>
97  inline SmartIF<T> service( const Gaudi::Utils::TypeNameString& typeName, const bool createIf = true ) {
98  return SmartIF<T>{service( typeName, createIf )};
99  }
100 
101  // try to access a different interface of the _current_ serviceLocator...
102  template <typename IFace>
104  return SmartIF<IFace>{this};
105  }
106 };
107 
108 #endif // GAUDI_ISVCLOCATOR_H
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
bool isSuccess() const
Definition: StatusCode.h:267
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
SmartIF< T > service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
Returns a smart pointer to the requested interface of a service.
Definition: ISvcLocator.h:97
StatusCode service(const std::string &type, const std::string &name, T *&svc, bool createIf=true)
Templated method to access a service by type and name.
Definition: ISvcLocator.h:87
SmartIF< IFace > as()
Definition: ISvcLocator.h:103
STL class.
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
Interface ID class.
Definition: IInterface.h:29
Helper class to parse a string of format "type/name".
General service interface definition.
Definition: IService.h:18
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
#define DeclareInterfaceID(iface, major, minor)
Macro to declare the interface ID when using the new mechanism of extending and implementing interfac...
Definition: IInterface.h:13
Definition of the basic interface.
Definition: IInterface.h:244
virtual StatusCode getService(const Gaudi::Utils::TypeNameString &typeName, IService *&svc, const bool createIf=true)
Get a reference to the service given a service name.
Definition: ISvcLocator.h:35
virtual StatusCode getService(const Gaudi::Utils::TypeNameString &typeName, const InterfaceID &iid, IInterface *&pinterface)
Get a specific interface pointer given a service name and interface id.
Definition: ISvcLocator.h:51
string s
Definition: gaudirun.py:312
constexpr static const auto FAILURE
Definition: StatusCode.h:86
std::string typeName(const std::type_info &typ)
Definition: Dictionary.cpp:21
#define GAUDI_API
Definition: Kernel.h:71
IInterface *PyHelper() getService(IInterface *app, char *name)
Definition: Bootstrap.cpp:229
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:247