Skip to content
Snippets Groups Projects
Commit 7d114654 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Improve OptionsSvc interface

- added default value to return for `get`
- added `pop` method
- added `item` method to get all options
parent 01bba39d
No related branches found
No related tags found
No related merge requests found
......@@ -59,7 +59,7 @@ StatusCode JobOptionsSvc::addPropertyToCatalogue( const std::string& client,
// ============================================================================
StatusCode JobOptionsSvc::removePropertyFromCatalogue( const std::string& client, const std::string& name )
{
m_options.erase( client + '.' + name );
pop( client + '.' + name );
return StatusCode::SUCCESS;
}
// ============================================================================
......
......@@ -37,12 +37,30 @@ private:
protected:
void set( const std::string& key, const std::string& value ) override { m_options[key] = value; }
std::string get( const std::string& key ) const override
std::string get( const std::string& key, const std::string& default_ = {} ) const override
{
auto item = find( key, true );
return item != m_options.end() ? item->second : std::string{};
return item != m_options.end() ? item->second : default_;
}
std::string pop( const std::string& key, const std::string& default_ = {} ) override
{
std::string result = default_;
auto item = find( key, true );
if ( item != m_options.end() ) {
m_options.erase( item );
result = std::move( item->second );
}
return result;
}
bool has( const std::string& key ) const override { return find( key, false ) != m_options.end(); }
std::vector<std::tuple<std::string, std::string>> items() const override
{
std::vector<std::tuple<std::string, std::string>> v;
v.reserve( m_options.size() );
std::for_each( begin( m_options ), end( m_options ), [&v]( const auto& item ) { v.emplace_back( item ); } );
return v;
}
public:
// Constructor
......
#pragma once
#include <string>
#include <tuple>
#include <vector>
namespace Gaudi
{
......@@ -8,8 +10,11 @@ namespace Gaudi
{
struct OptionsSvc {
virtual void set( const std::string& key, const std::string& value ) = 0;
virtual std::string get( const std::string& key ) const = 0;
virtual bool has( const std::string& key ) const = 0;
virtual std::string get( const std::string& key, const std::string& default_ = {} ) const = 0;
virtual std::string pop( const std::string& key, const std::string& default_ = {} ) = 0;
virtual bool has( const std::string& key ) const = 0;
virtual std::vector<std::tuple<std::string, std::string>> items() const = 0;
protected:
virtual ~OptionsSvc() = default;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment