The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
IToolSvc.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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#pragma once
12
14#include <GaudiKernel/System.h>
15#include <functional>
16#include <list>
17#include <string>
18
19// Forward declaration
20class IAlgTool;
21
28class GAUDI_API IToolSvc : virtual public IInterface {
29public:
32
33 // Typedefs
34 typedef std::list<IAlgTool*> ListTools;
35
47 virtual StatusCode retrieve( std::string_view type, const InterfaceID& iid, IAlgTool*& tool,
48 const IInterface* parent = 0, bool createIf = true ) = 0;
49
62 virtual StatusCode retrieve( std::string_view type, std::string_view name, const InterfaceID& iid, IAlgTool*& tool,
63 const IInterface* parent = 0, bool createIf = true ) = 0;
64
68 virtual std::vector<std::string> getInstances( std::string_view toolType ) = 0;
69
72 virtual std::vector<std::string> getInstances() const = 0;
73
76 virtual std::vector<IAlgTool*> getTools() const = 0;
77
81 virtual StatusCode releaseTool( IAlgTool* tool ) = 0;
82
146 template <class T>
147 StatusCode retrieveTool( std::string_view type, T*& tool, const IInterface* parent = nullptr, bool createIf = true ) {
148 return retrieve( type, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
149 }
150
194 template <class T>
195 StatusCode retrieveTool( std::string_view type, std::string_view name, T*& tool, const IInterface* parent = nullptr,
196 bool createIf = true ) {
197 return retrieve( type, name, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
198 }
199
229 class Observer {
230 public:
231 virtual ~Observer() {
232 if ( m_unregister ) m_unregister();
233 }
234 void setUnregister( std::function<void()> unregister ) { m_unregister = std::move( unregister ); }
235
236 virtual void onCreate( const IAlgTool* ) {}
237 virtual void onRetrieve( const IAlgTool* ) {}
238
239 private:
240 std::function<void()> m_unregister;
241 };
242
243 virtual void registerObserver( Observer* obs ) = 0;
244};
#define GAUDI_API
Definition Kernel.h:49
The interface implemented by the AlgTool base class.
Definition IAlgTool.h:29
Definition of the basic interface.
Definition IInterface.h:225
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition IInterface.h:228
allow call-backs when a tool is a created or retrieved
Definition IToolSvc.h:229
void setUnregister(std::function< void()> unregister)
Definition IToolSvc.h:234
virtual ~Observer()
Definition IToolSvc.h:231
virtual void onRetrieve(const IAlgTool *)
Definition IToolSvc.h:237
std::function< void()> m_unregister
Definition IToolSvc.h:240
virtual void onCreate(const IAlgTool *)
Definition IToolSvc.h:236
The interface implemented by the IToolSvc base class.
Definition IToolSvc.h:28
virtual void registerObserver(Observer *obs)=0
virtual StatusCode retrieve(std::string_view type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent=0, bool createIf=true)=0
Retrieve tool with tool dependent part of the name automatically assigned.
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:195
std::list< IAlgTool * > ListTools
Definition IToolSvc.h:34
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
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:147
virtual std::vector< std::string > getInstances(std::string_view toolType)=0
Get the names of all instances of tools of a given type.
virtual std::vector< std::string > getInstances() const =0
Get the names all tool instances.
virtual StatusCode retrieve(std::string_view type, std::string_view name, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent=0, bool createIf=true)=0
Retrieve tool with tool dependent part of the name specified by the requester.
DeclareInterfaceID(IToolSvc, 2, 1)
InterfaceID.
virtual std::vector< IAlgTool * > getTools() const =0
Get pointers to all tool instances.
Interface ID class.
Definition IInterface.h:38
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64