Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ServiceLocatorHelper.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_SERVICELOCATORHELPER_H
2 #define GAUDIKERNEL_SERVICELOCATORHELPER_H
3 
4 #include <GaudiKernel/IService.h>
6 #include <GaudiKernel/SmartIF.h>
8 #include <string>
9 
10 class InterfaceID;
11 class MsgStream;
12 
18 public:
19  ServiceLocatorHelper( ISvcLocator& svcLoc, const INamedInterface& requester )
20  : m_svcLoc( svcLoc )
21  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
22  , // use requester msg level
23  m_requesterName( requester.name() ) {}
24  ServiceLocatorHelper( ISvcLocator& svcLoc, const std::string& loggedName, const std::string& requesterName )
25  : m_svcLoc( svcLoc )
26  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), loggedName )
27  , // use requester msg level
28  m_requesterName( requesterName ) {}
29  ServiceLocatorHelper( ISvcLocator& svcLoc, const std::string& requesterName )
30  : m_svcLoc( svcLoc )
31  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
32  , // use requester msg level
33  m_requesterName( requesterName ) {}
34 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
36  const MsgStream& log, // use requester msg level
37  const std::string& requesterName )
38  : m_svcLoc( svcLoc ), m_msgLog( log ), m_requesterName( requesterName ) {}
39 #endif
40 
41  StatusCode getService( const std::string& name, bool createIf, const InterfaceID& iid, void** ppSvc ) const {
42  return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
43  }
44 
45  StatusCode locateService( const std::string& name, const InterfaceID& iid, void** ppSvc, bool quiet = false ) const;
46 
47  StatusCode createService( const std::string& name, const InterfaceID& iid, void** ppSvc ) const;
48 
49  StatusCode createService( const std::string& type, const std::string& name, const InterfaceID& iid,
50  void** ppSvc ) const;
51 
52  SmartIF<IService> service( const std::string& name, const bool quiet = false, const bool createIf = true ) const;
53 
54  template <typename T>
55  SmartIF<T> service( const std::string& name, const bool quiet = false, const bool createIf = true ) const {
56  return service( name, quiet, createIf ).as<T>();
57  }
58 
59 private:
60  ISvcLocator* serviceLocator() const { return &m_svcLoc; }
61  MsgStream& log() const { return m_msgLog; }
62  const std::string& requesterName() const { return m_requesterName; }
66 };
67 #endif
ISvcLocator * serviceLocator() const
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
an helper to share the implementation of service() among the various kernel base classes ...
Small smart pointer class with automatic reference counting for IInterface.
Definition: IConverter.h:15
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ServiceLocatorHelper(ISvcLocator &svcLoc, const INamedInterface &requester)
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &loggedName, const std::string &requesterName)
STL class.
MsgStream & log() const
Interface ID class.
Definition: IInterface.h:29
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:107
ServiceLocatorHelper(ISvcLocator &svcLoc, const std::string &requesterName)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:37
SmartIF< T > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
IInterface compliant class extending IInterface with the name() method.
const std::string & requesterName() const
ServiceLocatorHelper(ISvcLocator &svcLoc, const MsgStream &log, const std::string &requesterName)
#define GAUDI_API
Definition: Kernel.h:71
StatusCode getService(const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const