Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
IToolSvc.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_ITOOLSVC_H
2 #define GAUDIKERNEL_ITOOLSVC_H
3 
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:
23 
24  // Typedefs
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>
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:
233  };
234 
235  virtual void registerObserver( Observer* obs ) = 0;
236 };
237 
238 #endif // GAUDIKERNEL_ITOOLSVC_H
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:19
virtual ~Observer()
Definition: IToolSvc.h:223
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:221
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
std::list< IAlgTool * > ListTools
Definition: IToolSvc.h:25
STL class.
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:228
Interface ID class.
Definition: IInterface.h:29
std::function< void()> m_unregister
Definition: IToolSvc.h:232
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
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
STL class.
T move(T...args)
void setUnregister(std::function< void()> unregister)
Definition: IToolSvc.h:226
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:229
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
#define GAUDI_API
Definition: Kernel.h:71
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:247