The Gaudi Framework  v33r0 (d5ea422b)
IToolSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_ITOOLSVC_H
12 #define GAUDIKERNEL_ITOOLSVC_H
13 
14 #include "GaudiKernel/IInterface.h"
15 #include "GaudiKernel/System.h"
16 #include <functional>
17 #include <list>
18 #include <string>
19 
20 // Forward declaration
21 class IAlgTool;
22 
29 class GAUDI_API IToolSvc : virtual public IInterface {
30 public:
33 
34  // Typedefs
36 
48  virtual StatusCode retrieve( const std::string& type, const InterfaceID& iid, IAlgTool*& tool,
49  const IInterface* parent = 0, bool createIf = true ) = 0;
50 
63  virtual StatusCode retrieve( const std::string& type, const std::string& name, const InterfaceID& iid,
64  IAlgTool*& tool, const IInterface* parent = 0, bool createIf = true ) = 0;
65 
69  virtual std::vector<std::string> getInstances( const std::string& toolType ) = 0;
70 
73  virtual std::vector<std::string> getInstances() const = 0;
74 
77  virtual std::vector<IAlgTool*> getTools() const = 0;
78 
82  virtual StatusCode releaseTool( IAlgTool* tool ) = 0;
83 
147  template <class T>
148  StatusCode retrieveTool( const std::string& type, T*& tool, const IInterface* parent = nullptr,
149  bool createIf = true ) {
150  return retrieve( type, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
151  }
152 
196  template <class T>
198  const IInterface* parent = nullptr, bool createIf = true ) {
199  return retrieve( type, name, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
200  }
201 
231  class Observer {
232  public:
233  virtual ~Observer() {
234  if ( m_unregister ) m_unregister();
235  }
236  void setUnregister( std::function<void()> unregister ) { m_unregister = std::move( unregister ); }
237 
238  virtual void onCreate( const IAlgTool* ) {}
239  virtual void onRetrieve( const IAlgTool* ) {}
240 
241  private:
243  };
244 
245  virtual void registerObserver( Observer* obs ) = 0;
246 };
247 
248 #endif // GAUDIKERNEL_ITOOLSVC_H
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:29
virtual ~Observer()
Definition: IToolSvc.h:233
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:231
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:148
std::list< IAlgTool * > ListTools
Definition: IToolSvc.h:35
STL class.
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:238
Interface ID class.
Definition: IInterface.h:39
std::function< void()> m_unregister
Definition: IToolSvc.h:242
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
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:197
STL class.
T move(T... args)
#define DeclareInterfaceID(iface, major, minor)
Macro to declare the interface ID when using the new mechanism of extending and implementing interfac...
Definition: IInterface.h:23
void setUnregister(std::function< void()> unregister)
Definition: IToolSvc.h:236
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:239
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:33
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:257