The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
ServiceLocatorHelper.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
15#include <GaudiKernel/SmartIF.h>
17#include <string>
18
19class InterfaceID;
20class MsgStream;
21
27public:
29 : m_svcLoc( svcLoc )
30 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
31 , // use requester msg level
32 m_requesterName( requester.name() ) {}
33 ServiceLocatorHelper( ISvcLocator& svcLoc, std::string loggedName, std::string requesterName )
34 : m_svcLoc( svcLoc )
35 , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), std::move( loggedName ) )
36 , // use requester msg level
37 m_requesterName( std::move( requesterName ) ) {}
39 : m_svcLoc( svcLoc )
41 , // use requester msg level
42 m_requesterName( std::move( requesterName ) ) {}
43
44 SmartIF<IService> service( std::string_view name, const bool quiet = false, const bool createIf = true ) const;
45
46 template <typename T>
47 SmartIF<T> service( std::string_view name, const bool quiet = false, const bool createIf = true ) const {
48 return service( name, quiet, createIf ).as<T>();
49 }
50
51private:
52 ISvcLocator* serviceLocator() const { return &m_svcLoc; }
53 MsgStream& log() const { return m_msgLog; }
54 const std::string& requesterName() const { return m_requesterName; }
57 std::string m_requesterName;
58};
#define GAUDI_API
Definition Kernel.h:49
The IMessage is the interface implemented by the message service.
Definition IMessageSvc.h:34
IInterface compliant class extending IInterface with the name() method.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Interface ID class.
Definition IInterface.h:38
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
ServiceLocatorHelper(ISvcLocator &svcLoc, std::string loggedName, std::string requesterName)
MsgStream & log() const
const std::string & requesterName() const
ServiceLocatorHelper(ISvcLocator &svcLoc, const INamedInterface &requester)
SmartIF< IService > service(std::string_view name, const bool quiet=false, const bool createIf=true) const
ISvcLocator * serviceLocator() const
SmartIF< T > service(std::string_view name, const bool quiet=false, const bool createIf=true) const
ServiceLocatorHelper(ISvcLocator &svcLoc, std::string requesterName)
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
STL namespace.