The Gaudi Framework  v40r0 (475e45c1)
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"
12 #include <GaudiKernel/compose.h>
13 #include <boost/algorithm/string/join.hpp>
14 #include <boost/format.hpp>
15 
16 namespace gp = Gaudi::Parsers;
17 
18 bool gp::PropertyValue::IsSimple() const { return std::holds_alternative<std::string>( value_ ); }
19 bool gp::PropertyValue::IsVector() const { return std::holds_alternative<VectorOfStrings>( value_ ); }
20 bool gp::PropertyValue::IsMap() const { return std::holds_alternative<MapOfStrings>( value_ ); }
22 
23  if ( IsReference() ) { throw PropertyValueException::WrongLValue(); }
24  std::visit(
26  []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
27  []( VectorOfStrings& lhs, const std::string& rhs ) { lhs.push_back( rhs ); },
28  []( VectorOfStrings& lhs, const VectorOfStrings& rhs ) { lhs.insert( lhs.end(), rhs.begin(), rhs.end() ); },
29  []( MapOfStrings& lhs, const MapOfStrings& rhs ) { lhs.insert( rhs.begin(), rhs.end() ); },
30  []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
31  value_, right.value_ );
32  return *this;
33 }
34 
36  return PropertyValue{ *this } += right;
37 }
38 
40  if ( IsReference() ) { throw PropertyValueException::WrongLValue(); }
41  std::visit(
42  Gaudi::overload( []( std::vector<std::string>& lhs,
43  const std::string& rhs ) { lhs.erase( std::find( lhs.begin(), lhs.end(), rhs ) ); },
44  []( std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) {
45  for ( const auto& item : rhs ) lhs.erase( std::find( lhs.begin(), lhs.end(), item ) );
46  },
47  []( std::map<std::string, std::string>& lhs, const std::string& rhs ) { lhs.erase( rhs ); },
48  []( std::map<std::string, std::string>& lhs, const std::vector<std::string>& 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 
61 std::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  Gaudi::overload( []( const std::string& v ) { return v; },
72  []( const VectorOfStrings& v ) { return '[' + boost::algorithm::join( v, ", " ) + ']'; },
73  []( const MapOfStrings& v ) {
74  std::string result = "{";
75  std::string delim = "";
76  for ( const auto& in : v ) {
77  result += delim + in.first + ":" + in.second;
78  delim = ", ";
79  }
80  return result + "}";
81  } ),
82  value_ );
83 }
Gaudi::Parsers::PropertyValue::operator-=
PropertyValue & operator-=(const PropertyValue &right)
Definition: PropertyValue.cpp:39
Gaudi::Parsers::PropertyValue::operator-
const PropertyValue operator-(const PropertyValue &right)
Definition: PropertyValue.cpp:57
Gaudi::Parsers::PropertyValue::ToString
std::string ToString() const
Definition: PropertyValue.cpp:61
Gaudi::Parsers::PropertyValue::VectorOfStrings
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:24
Gaudi::Parsers::PropertyValue
Definition: PropertyValue.h:22
Gaudi::Parsers::PropertyValueException::WrongRValue
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:70
PropertyValue.h
Gaudi::Parsers::PropertyValue::value_
Value value_
Definition: PropertyValue.h:58
Gaudi::Parsers::PropertyValue::IsVector
bool IsVector() const
Definition: PropertyValue.cpp:19
Gaudi::Parsers::PropertyValue::MapOfStrings
std::map< std::string, std::string, std::less<> > MapOfStrings
Definition: PropertyValue.h:25
compose.h
Gaudi::Parsers::PropertyValue::IsMap
bool IsMap() const
Definition: PropertyValue.cpp:20
Gaudi::Parsers::PropertyValue::operator+=
PropertyValue & operator+=(const PropertyValue &right)
Definition: PropertyValue.cpp:21
Gaudi::Parsers::PropertyValueException::WrongLValue
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:66
Properties.v
v
Definition: Properties.py:122
Gaudi::Parsers::PropertyValue::IsSimple
bool IsSimple() const
Definition: PropertyValue.cpp:18
Gaudi::Parsers
Definition: DODBasicMapper.cpp:17
Gaudi::Parsers::PropertyValue::operator+
const PropertyValue operator+(const PropertyValue &right)
Definition: PropertyValue.cpp:35
Gaudi::overload
auto overload(lambda_ts &&... lambdas)
Definition: compose.h:37