The Gaudi Framework  master (37c0b60a)
PropertyValue.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 // ============================================================================
12 // Include files
13 // ============================================================================
14 #include "PropertyValue.h"
15 #include <GaudiKernel/compose.h>
16 // ============================================================================
17 // STD & STL:
18 // ============================================================================
19 // ============================================================================
20 // Boost:
21 // ============================================================================
22 #include <boost/algorithm/string/join.hpp>
23 #include <boost/format.hpp>
24 // ============================================================================
25 namespace gp = Gaudi::Parsers;
26 // ============================================================================
27 bool gp::PropertyValue::IsSimple() const { return std::holds_alternative<std::string>( value_ ); }
28 // ============================================================================
29 bool gp::PropertyValue::IsVector() const { return std::holds_alternative<VectorOfStrings>( value_ ); }
30 // ============================================================================
31 bool gp::PropertyValue::IsMap() const { return std::holds_alternative<MapOfStrings>( value_ ); }
32 // ============================================================================
34 
35  if ( IsReference() ) { throw PropertyValueException::WrongLValue(); }
36  std::visit(
38  []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
39  []( VectorOfStrings& lhs, const std::string& rhs ) { lhs.push_back( rhs ); },
40  []( VectorOfStrings& lhs, const VectorOfStrings& rhs ) { lhs.insert( lhs.end(), rhs.begin(), rhs.end() ); },
41  []( MapOfStrings& lhs, const MapOfStrings& rhs ) { lhs.insert( rhs.begin(), rhs.end() ); },
42  []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
43  value_, right.value_ );
44  return *this;
45 }
46 
48  return PropertyValue{ *this } += right;
49 }
50 
52  if ( IsReference() ) { throw PropertyValueException::WrongLValue(); }
53  std::visit(
55  const std::string& rhs ) { lhs.erase( std::find( lhs.begin(), lhs.end(), rhs ) ); },
56  []( std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) {
57  for ( const auto& item : rhs ) lhs.erase( std::find( lhs.begin(), lhs.end(), item ) );
58  },
59  []( std::map<std::string, std::string>& lhs, const std::string& rhs ) { lhs.erase( rhs ); },
61  for ( const auto& item : rhs ) lhs.erase( item );
62  },
63  []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
64  []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
65  value_, right.value_ );
66  return *this;
67 }
68 
70  return PropertyValue{ *this } -= right;
71 }
72 // ============================================================================
74  if ( IsReference() ) {
75  const auto& value = std::get<VectorOfStrings>( value_ );
76  if ( value.at( 0 ) != "" ) {
77  return "@" + value.at( 0 ) + "." + value.at( 1 );
78  } else {
79  return "@" + value.at( 0 );
80  }
81  }
82  return std::visit(
83  Gaudi::overload( []( const std::string& v ) { return v; },
84  []( const VectorOfStrings& v ) { return '[' + boost::algorithm::join( v, ", " ) + ']'; },
85  []( const MapOfStrings& v ) {
86  std::string result = "{";
87  std::string delim = "";
88  for ( const auto& in : v ) {
89  result += delim + in.first + ":" + in.second;
90  delim = ", ";
91  }
92  return result + "}";
93  } ),
94  value_ );
95 }
Gaudi::Parsers::PropertyValue::operator-=
PropertyValue & operator-=(const PropertyValue &right)
Definition: PropertyValue.cpp:51
std::string
STL class.
Gaudi::Parsers::PropertyValue::operator-
const PropertyValue operator-(const PropertyValue &right)
Definition: PropertyValue.cpp:69
Gaudi::Parsers::PropertyValue::ToString
std::string ToString() const
Definition: PropertyValue.cpp:73
std::vector< std::string >
std::find
T find(T... args)
Gaudi::Parsers::PropertyValue
Definition: PropertyValue.h:29
Gaudi::Parsers::PropertyValueException::WrongRValue
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:82
PropertyValue.h
std::vector::push_back
T push_back(T... args)
Gaudi::Parsers::PropertyValue::value_
Value value_
Definition: PropertyValue.h:69
Gaudi::Parsers::PropertyValue::IsVector
bool IsVector() const
Definition: PropertyValue.cpp:29
std::vector::erase
T erase(T... args)
compose.h
std::map< std::string, std::string, std::less<> >
Gaudi::Parsers::PropertyValue::IsMap
bool IsMap() const
Definition: PropertyValue.cpp:31
Gaudi::Parsers::PropertyValue::operator+=
PropertyValue & operator+=(const PropertyValue &right)
Definition: PropertyValue.cpp:33
std::string::begin
T begin(T... args)
std::vector::insert
T insert(T... args)
Gaudi::Parsers::PropertyValueException::WrongLValue
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:78
Properties.v
v
Definition: Properties.py:122
Gaudi::Parsers::PropertyValue::IsSimple
bool IsSimple() const
Definition: PropertyValue.cpp:27
Gaudi::Parsers
Definition: DODBasicMapper.cpp:17
std::vector::end
T end(T... args)
Gaudi::Parsers::PropertyValue::operator+
const PropertyValue operator+(const PropertyValue &right)
Definition: PropertyValue.cpp:47
Gaudi::overload
auto overload(lambda_ts &&... lambdas)
Definition: compose.h:38