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 <string>
7 #include <list>
8 #include <functional>
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 ,
39  const InterfaceID& iid ,
40  IAlgTool*& tool ,
41  const IInterface* parent = 0 ,
42  bool createIf = true ) = 0;
43 
56  virtual StatusCode retrieve ( const std::string& type ,
57  const std::string& name ,
58  const InterfaceID& iid ,
59  IAlgTool*& tool ,
60  const IInterface* parent = 0 ,
61  bool createIf = true ) = 0 ;
62 
66  virtual std::vector<std::string> getInstances( const std::string& toolType ) = 0;
67 
70  virtual std::vector<std::string> getInstances() const = 0;
71 
74  virtual std::vector<IAlgTool*> getTools() const = 0;
75 
79  virtual StatusCode releaseTool( IAlgTool* tool ) = 0;
80 
81 
145  template <class T>
147  T*& tool ,
148  const IInterface* parent = nullptr,
149  bool createIf = true )
150  {
151  return retrieve( type,
152  T::interfaceID(),
153  (IAlgTool*&)tool,
154  parent,
155  createIf );
156  }
157 
201  template <class T>
203  const std::string& name ,
204  T*& tool ,
205  const IInterface* parent = nullptr ,
206  bool createIf = true )
207  {
208  return retrieve ( type,
209  name,
210  T::interfaceID(),
211  (IAlgTool*&)tool,
212  parent,
213  createIf );
214  }
215 
245  class Observer {
246  public:
247  virtual ~Observer() { if (m_unregister) m_unregister(); }
248  void setUnregister(std::function<void()> unregister) { m_unregister=std::move(unregister); }
249 
250  virtual void onCreate(const IAlgTool*) {}
251  virtual void onRetrieve(const IAlgTool*) {}
252  private:
254  };
255 
256  virtual void registerObserver(Observer *obs) = 0;
257 
258 };
259 
260 
261 #endif // GAUDIKERNEL_ITOOLSVC_H
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:19
virtual ~Observer()
Definition: IToolSvc.h:247
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:245
#define DeclareInterfaceID(iface, major, minor)
Macro to declare the interface ID when using the new mechanism of extending and implementing interfac...
Definition: IInterface.h:14
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:146
std::list< IAlgTool * > ListTools
Definition: IToolSvc.h:25
STL class.
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:250
Interface ID class.
Definition: IInterface.h:30
std::function< void()> m_unregister
Definition: IToolSvc.h:253
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:234
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:202
STL class.
T move(T...args)
void setUnregister(std::function< void()> unregister)
Definition: IToolSvc.h:248
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:251
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:237
#define GAUDI_API
Definition: Kernel.h:107