The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
PropertyValue.cpp
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#include "PropertyValue.h"
13#include <GaudiKernel/compose.h>
14#include <algorithm>
15#include <sstream>
16
17namespace gp = Gaudi::Parsers;
18
19bool gp::PropertyValue::IsSimple() const { return std::holds_alternative<std::string>( value_ ); }
20bool gp::PropertyValue::IsVector() const { return std::holds_alternative<VectorOfStrings>( value_ ); }
21bool gp::PropertyValue::IsMap() const { return std::holds_alternative<MapOfStrings>( value_ ); }
23
25 std::visit(
27 []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
28 []( VectorOfStrings& lhs, const std::string& rhs ) { lhs.push_back( rhs ); },
29 []( VectorOfStrings& lhs, const VectorOfStrings& rhs ) { lhs.insert( lhs.end(), rhs.begin(), rhs.end() ); },
30 []( MapOfStrings& lhs, const MapOfStrings& rhs ) { lhs.insert( rhs.begin(), rhs.end() ); },
31 []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
32 value_, right.value_ );
33 return *this;
34}
35
37 return PropertyValue{ *this } += right;
38}
39
42 std::visit( Gaudi::overload( []( VectorOfStrings& lhs,
43 const std::string& rhs ) { lhs.erase( std::find( lhs.begin(), lhs.end(), rhs ) ); },
44 []( VectorOfStrings& lhs, const VectorOfStrings& rhs ) {
45 for ( const auto& item : rhs ) lhs.erase( std::find( lhs.begin(), lhs.end(), item ) );
46 },
47 []( MapOfStrings& lhs, const std::string& rhs ) { lhs.erase( rhs ); },
48 []( MapOfStrings& lhs, const VectorOfStrings& rhs ) {
49 for ( const auto& item : rhs ) lhs.erase( item );
50 },
51 []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
52 []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
53 value_, right.value_ );
54 return *this;
55}
56
58 return PropertyValue{ *this } -= right;
59}
60
61std::string gp::PropertyValue::ToString() const {
62 if ( IsReference() ) {
63 const auto& value = std::get<VectorOfStrings>( value_ );
64 if ( value.at( 0 ) != "" ) {
65 return "@" + value.at( 0 ) + "." + value.at( 1 );
66 } else {
67 return "@" + value.at( 0 );
68 }
69 }
70 return std::visit(
71 []( const auto& v ) {
72 // make sure to be consistent by explicitly re-using `GaudiUtils::operator<<`
73 using GaudiUtils::operator<<;
74 std::ostringstream s{};
75 s << v;
76 return s.str();
77 },
78 value_ );
79}
Provide serialization function (output only) for some common STL classes (vectors,...
static PropertyValueException WrongRValue()
static PropertyValueException WrongLValue()
std::vector< std::string > VectorOfStrings
std::map< std::string, std::string, std::less<> > MapOfStrings
const PropertyValue operator+(const PropertyValue &right)
PropertyValue & operator+=(const PropertyValue &right)
const PropertyValue operator-(const PropertyValue &right)
PropertyValue(Value value, bool is_reference=false)
PropertyValue & operator-=(const PropertyValue &right)
auto overload(lambda_ts &&... lambdas)
Definition compose.h:37