The Gaudi Framework  v30r3 (a5ef0a68)
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 {
21 public:
24 
25  // Typedefs
27 
39  virtual StatusCode retrieve( const std::string& type, const InterfaceID& iid, IAlgTool*& tool,
40  const IInterface* parent = 0, bool createIf = true ) = 0;
41 
54  virtual StatusCode retrieve( const std::string& type, const std::string& name, const InterfaceID& iid,
55  IAlgTool*& tool, const IInterface* parent = 0, bool createIf = true ) = 0;
56 
60  virtual std::vector<std::string> getInstances( const std::string& toolType ) = 0;
61 
64  virtual std::vector<std::string> getInstances() const = 0;
65 
68  virtual std::vector<IAlgTool*> getTools() const = 0;
69 
73  virtual StatusCode releaseTool( IAlgTool* tool ) = 0;
74 
138  template <class T>
139  StatusCode retrieveTool( const std::string& type, T*& tool, const IInterface* parent = nullptr, bool createIf = true )
140  {
141  return retrieve( type, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
142  }
143 
187  template <class T>
189  const IInterface* parent = nullptr, bool createIf = true )
190  {
191  return retrieve( type, name, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
192  }
193 
223  class Observer
224  {
225  public:
226  virtual ~Observer()
227  {
228  if ( m_unregister ) m_unregister();
229  }
230  void setUnregister( std::function<void()> unregister ) { m_unregister = std::move( unregister ); }
231 
232  virtual void onCreate( const IAlgTool* ) {}
233  virtual void onRetrieve( const IAlgTool* ) {}
234 
235  private:
237  };
238 
239  virtual void registerObserver( Observer* obs ) = 0;
240 };
241 
242 #endif // GAUDIKERNEL_ITOOLSVC_H
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:19
virtual ~Observer()
Definition: IToolSvc.h:226
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:223
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:139
std::list< IAlgTool * > ListTools
Definition: IToolSvc.h:26
STL class.
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:232
Interface ID class.
Definition: IInterface.h:29
std::function< void()> m_unregister
Definition: IToolSvc.h:236
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
#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:277
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:188
STL class.
T move(T...args)
void setUnregister(std::function< void()> unregister)
Definition: IToolSvc.h:230
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:233
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
#define GAUDI_API
Definition: Kernel.h:104
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:281