The Gaudi Framework  v33r1 (b1225454)
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( std::string_view type, const InterfaceID& iid, IAlgTool*& tool,
49  const IInterface* parent = 0, bool createIf = true ) = 0;
50 
63  virtual StatusCode retrieve( std::string_view type, std::string_view name, const InterfaceID& iid, IAlgTool*& tool,
64  const IInterface* parent = 0, bool createIf = true ) = 0;
65 
69  virtual std::vector<std::string> getInstances( std::string_view 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( std::string_view type, T*& tool, const IInterface* parent = nullptr, bool createIf = true ) {
149  return retrieve( type, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
150  }
151 
195  template <class T>
196  StatusCode retrieveTool( std::string_view type, std::string_view name, T*& tool, const IInterface* parent = nullptr,
197  bool createIf = true ) {
198  return retrieve( type, name, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
199  }
200 
230  class Observer {
231  public:
232  virtual ~Observer() {
233  if ( m_unregister ) m_unregister();
234  }
235  void setUnregister( std::function<void()> unregister ) { m_unregister = std::move( unregister ); }
236 
237  virtual void onCreate( const IAlgTool* ) {}
238  virtual void onRetrieve( const IAlgTool* ) {}
239 
240  private:
242  };
243 
244  virtual void registerObserver( Observer* obs ) = 0;
245 };
246 
247 #endif // GAUDIKERNEL_ITOOLSVC_H
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:29
virtual ~Observer()
Definition: IToolSvc.h:232
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:230
StatusCode retrieveTool(std::string_view type, std::string_view 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:196
std::list< IAlgTool * > ListTools
Definition: IToolSvc.h:35
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:237
Interface ID class.
Definition: IInterface.h:39
std::function< void()> m_unregister
Definition: IToolSvc.h:241
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
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:235
StatusCode retrieveTool(std::string_view 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
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:238
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:33
const Gaudi::Algorithm & parent
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:257