| The Gaudi Framework v32r1 (f65d50dc)

IToolSvc.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_ITOOLSVC_H
2 #define GAUDIKERNEL_ITOOLSVC_H
3
4 #include "GaudiKernel/IInterface.h"
5 #include "GaudiKernel/System.h"
6 #include <functional>
7 #include <list>
8 #include <string>
9
10 // Forward declaration
11 class IAlgTool;
12
19 class GAUDI_API IToolSvc : virtual public IInterface {
20 public:
22 DeclareInterfaceID( IToolSvc, 2, 1 );
23
24 // Typedefs
25 typedef std::list<IAlgTool*> ListTools;
26
38 virtual StatusCode retrieve( const std::string& type, const InterfaceID& iid, IAlgTool*& tool,
39 const IInterface* parent = 0, bool createIf = true ) = 0;
40
53 virtual StatusCode retrieve( const std::string& type, const std::string& name, const InterfaceID& iid,
54 IAlgTool*& tool, const IInterface* parent = 0, bool createIf = true ) = 0;
55
59 virtual std::vector<std::string> getInstances( const std::string& toolType ) = 0;
60
63 virtual std::vector<std::string> getInstances() const = 0;
64
67 virtual std::vector<IAlgTool*> getTools() const = 0;
68
72 virtual StatusCode releaseTool( IAlgTool* tool ) = 0;
73
137 template <class T>
138 StatusCode retrieveTool( const std::string& type, T*& tool, const IInterface* parent = nullptr,
139 bool createIf = true ) {
140 return retrieve( type, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
141 }
142
186 template <class T>
187 StatusCode retrieveTool( const std::string& type, const std::string& name, T*& tool,
188 const IInterface* parent = nullptr, bool createIf = true ) {
189 return retrieve( type, name, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
190 }
191
221 class Observer {
222 public:
223 virtual ~Observer() {
224 if ( m_unregister ) m_unregister();
225 }
226 void setUnregister( std::function<void()> unregister ) { m_unregister = std::move( unregister ); }
227
228 virtual void onCreate( const IAlgTool* ) {}
229 virtual void onRetrieve( const IAlgTool* ) {}
230
231 private:
232 std::function<void()> m_unregister;
233 };
234
235 virtual void registerObserver( Observer* obs ) = 0;
236 };
237
238 #endif // GAUDIKERNEL_ITOOLSVC_H
System.h
IToolSvc
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:19
IToolSvc::Observer::~Observer
virtual ~Observer()
Definition: IToolSvc.h:223
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
std::function
IToolSvc::Observer
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:221
IToolSvc::retrieveTool
StatusCode retrieveTool(const std::string &type, T *&tool, const IInterface *parent=nullptr, bool createIf=true)
Retrieve specified tool sub-type with tool dependent part of the name automatically assigned.
Definition: IToolSvc.h:138
IToolSvc::ListTools
std::list< IAlgTool * > ListTools
Definition: IToolSvc.h:25
std::string
STL class.
IToolSvc::Observer::onCreate
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:228
InterfaceID
Interface ID class.
Definition: IInterface.h:29
IToolSvc::Observer::m_unregister
std::function< void()> m_unregister
Definition: IToolSvc.h:232
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IInterface
Definition of the basic interface.
Definition: IInterface.h:244
gaudirun.type
type
Definition: gaudirun.py:142
IToolSvc::retrieveTool
StatusCode retrieveTool(const std::string &type, const std::string &name, T *&tool, const IInterface *parent=nullptr, bool createIf=true)
Retrieve specified tool sub-type with tool dependent part of the name tool dependent part of the name...
Definition: IToolSvc.h:187
std::list
STL class.
std::move
T move(T... args)
DeclareInterfaceID
#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
IToolSvc::Observer::setUnregister
void setUnregister(std::function< void()> unregister)
Definition: IToolSvc.h:226
std::vector< std::string >
IToolSvc::Observer::onRetrieve
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:229
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
IInterface.h
IInterface::iid
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:247