The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
IOptionsSvc.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 "COPYING". *
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 <regex>
16#include <string>
17#include <tuple>
18#include <vector>
19
20namespace Gaudi {
21 namespace Details {
22 class PropertyBase;
23 }
24 namespace Interfaces {
46 struct IOptionsSvc : virtual public IInterface {
49
51 virtual void set( const std::string& key, const std::string& value ) = 0;
53 virtual std::string get( const std::string& key, const std::string& default_ = {} ) const = 0;
56 virtual std::string pop( const std::string& key, const std::string& default_ = {} ) = 0;
58 virtual bool has( const std::string& key ) const = 0;
60 virtual bool isSet( const std::string& key ) const = 0;
61
65
66 virtual std::vector<std::tuple<std::string, std::string>> items() const = 0;
68 template <class UnaryPredicate>
69 std::vector<std::tuple<std::string, std::string>> items( UnaryPredicate predicate ) const {
70 auto v = this->items();
71 v.erase( std::remove_if( begin( v ), end( v ),
72 [&predicate]( const auto& element ) { return !predicate( element ); } ),
73 v.end() );
74 return v;
75 }
76
77 std::vector<std::tuple<std::string, std::string>> items( const std::regex& filter ) const {
78 std::smatch match;
79 return items(
80 [&filter, &match]( const auto& element ) { return regex_match( std::get<0>( element ), match, filter ); } );
81 }
82
83
92 virtual void bind( const std::string& prefix, Gaudi::Details::PropertyBase* property ) = 0;
93
95
101 virtual void broadcast( const std::regex& filter, const std::string& value,
102 OnlyDefaults defaults = OnlyDefaults{ true } ) = 0;
103
106 virtual StatusCode readOptions( std::string_view file, std::string_view path = "" ) = 0;
107
108 protected:
109 virtual ~IOptionsSvc() = default;
110 };
111 } // namespace Interfaces
112} // namespace Gaudi
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition of the basic interface.
Definition IInterface.h:225
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
Interface for a component that manages application configuration options.
Definition IOptionsSvc.h:46
virtual std::vector< std::tuple< std::string, std::string > > items() const =0
Return all known options with their values.
std::vector< std::tuple< std::string, std::string > > items(const std::regex &filter) const
Return all known options with their values for which the key matches the given regular expression.
Definition IOptionsSvc.h:77
DeclareInterfaceID(IOptionsSvc, 1, 0)
InterfaceID declaration.
virtual bool isSet(const std::string &key) const =0
Test if an option key was explicitly set or not.
virtual void bind(const std::string &prefix, Gaudi::Details::PropertyBase *property)=0
Register a Gaudi::Property instance to the option service.
virtual void set(const std::string &key, const std::string &value)=0
Set the value of an option, overriding the old value, if any.
virtual bool has(const std::string &key) const =0
Test if an option key is available in the catalog.
virtual std::string get(const std::string &key, const std::string &default_={}) const =0
Get the value of an options, returning the specified default value if not found.
virtual std::string pop(const std::string &key, const std::string &default_={})=0
Get the value of an options, removing it from the storage, returning the specified default value if n...
virtual StatusCode readOptions(std::string_view file, std::string_view path="")=0
look for file 'file' into search path 'path' and read it to update the options
virtual void broadcast(const std::regex &filter, const std::string &value, OnlyDefaults defaults=OnlyDefaults{ true })=0
Broadcast version of IOptionsSvc::set.
virtual ~IOptionsSvc()=default
std::vector< std::tuple< std::string, std::string > > items(UnaryPredicate predicate) const
Return all known options with their values for which predicate evaluates to true.
Definition IOptionsSvc.h:69
Gaudi::tagged_bool< class OnlyDefaults_tag > OnlyDefaults
Definition IOptionsSvc.h:94