The Gaudi Framework  v32r2 (46d42edc)
PropertyValue.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 #include "PropertyValue.h"
5 #include "GaudiKernel/compose.h"
6 // ============================================================================
7 // STD & STL:
8 // ============================================================================
9 // ============================================================================
10 // Boost:
11 // ============================================================================
12 #include "boost/algorithm/string/join.hpp"
13 #include "boost/format.hpp"
14 // ============================================================================
15 namespace gp = Gaudi::Parsers;
16 // ============================================================================
17 bool gp::PropertyValue::IsSimple() const { return std::holds_alternative<std::string>( value_ ); }
18 // ============================================================================
19 bool gp::PropertyValue::IsVector() const { return std::holds_alternative<std::vector<std::string>>( value_ ); }
20 // ============================================================================
21 bool gp::PropertyValue::IsMap() const { return std::holds_alternative<std::map<std::string, std::string>>( value_ ); }
22 // ============================================================================
23 gp::PropertyValue& gp::PropertyValue::operator+=( const PropertyValue& right ) {
24 
25  if ( IsReference() ) { throw PropertyValueException::WrongLValue(); }
26  std::visit(
27  Gaudi::overload( []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
28  []( std::vector<std::string>& lhs, const std::string& rhs ) { lhs.push_back( rhs ); },
29  []( std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) {
30  lhs.insert( lhs.end(), rhs.begin(), rhs.end() );
31  },
33  lhs.insert( rhs.begin(), rhs.end() );
34  },
35  []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
36  value_, right.value_ );
37  return *this;
38 }
39 
40 const gp::PropertyValue gp::PropertyValue::operator+( const PropertyValue& right ) {
41  return PropertyValue{*this} += right;
42 }
43 
44 gp::PropertyValue& gp::PropertyValue::operator-=( const PropertyValue& right ) {
45  if ( IsReference() ) { throw PropertyValueException::WrongLValue(); }
46  std::visit(
48  const std::string& rhs ) { lhs.erase( std::find( lhs.begin(), lhs.end(), rhs ) ); },
49  []( std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) {
50  for ( const auto& item : rhs ) lhs.erase( std::find( lhs.begin(), lhs.end(), item ) );
51  },
52  []( std::map<std::string, std::string>& lhs, const std::string& rhs ) { lhs.erase( rhs ); },
54  for ( const auto& item : rhs ) lhs.erase( item );
55  },
56  []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
57  []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
58  value_, right.value_ );
59  return *this;
60 }
61 
62 const gp::PropertyValue gp::PropertyValue::operator-( const PropertyValue& right ) {
63  return PropertyValue{*this} -= right;
64 }
65 // ============================================================================
66 std::string gp::PropertyValue::ToString() const {
67  if ( IsReference() ) {
68  const auto& value = std::get<std::vector<std::string>>( value_ );
69  if ( value.at( 0 ) != "" ) {
70  return "@" + value.at( 0 ) + "." + value.at( 1 );
71  } else {
72  return "@" + value.at( 0 );
73  }
74  }
75  return std::visit( Gaudi::overload( []( const std::string& v ) { return v; },
76  []( const std::vector<std::string>& v ) {
77  return '[' + boost::algorithm::join( v, ", " ) + ']';
78  },
79  []( const std::map<std::string, std::string>& v ) {
80  std::string result = "{";
81  std::string delim = "";
82  for ( const auto& in : v ) {
83  result += delim + in.first + ":" + in.second;
84  delim = ", ";
85  }
86  return result + "}";
87  } ),
88  value_ );
89 }
T end(T... args)
STL class.
T at(T... args)
T push_back(T... args)
T erase(T... args)
T insert(T... args)
T find(T... args)
T begin(T... args)
decltype(auto) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:708
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:118
auto overload(lambda_ts &&... lambdas)
Definition: compose.h:28