The Gaudi Framework  v33r0 (d5ea422b)
PropertyValue.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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<std::vector<std::string>>( value_ ); }
30 // ============================================================================
31 bool gp::PropertyValue::IsMap() const { return std::holds_alternative<std::map<std::string, std::string>>( value_ ); }
32 // ============================================================================
33 gp::PropertyValue& gp::PropertyValue::operator+=( const PropertyValue& right ) {
34 
35  if ( IsReference() ) { throw PropertyValueException::WrongLValue(); }
36  std::visit(
37  Gaudi::overload( []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
38  []( std::vector<std::string>& lhs, const std::string& rhs ) { lhs.push_back( rhs ); },
39  []( std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) {
40  lhs.insert( lhs.end(), rhs.begin(), rhs.end() );
41  },
43  lhs.insert( rhs.begin(), rhs.end() );
44  },
45  []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
46  value_, right.value_ );
47  return *this;
48 }
49 
50 const gp::PropertyValue gp::PropertyValue::operator+( const PropertyValue& right ) {
51  return PropertyValue{*this} += right;
52 }
53 
54 gp::PropertyValue& gp::PropertyValue::operator-=( const PropertyValue& right ) {
55  if ( IsReference() ) { throw PropertyValueException::WrongLValue(); }
56  std::visit(
58  const std::string& rhs ) { lhs.erase( std::find( lhs.begin(), lhs.end(), rhs ) ); },
59  []( std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) {
60  for ( const auto& item : rhs ) lhs.erase( std::find( lhs.begin(), lhs.end(), item ) );
61  },
62  []( std::map<std::string, std::string>& lhs, const std::string& rhs ) { lhs.erase( rhs ); },
64  for ( const auto& item : rhs ) lhs.erase( item );
65  },
66  []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
67  []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
68  value_, right.value_ );
69  return *this;
70 }
71 
72 const gp::PropertyValue gp::PropertyValue::operator-( const PropertyValue& right ) {
73  return PropertyValue{*this} -= right;
74 }
75 // ============================================================================
76 std::string gp::PropertyValue::ToString() const {
77  if ( IsReference() ) {
78  const auto& value = std::get<std::vector<std::string>>( value_ );
79  if ( value.at( 0 ) != "" ) {
80  return "@" + value.at( 0 ) + "." + value.at( 1 );
81  } else {
82  return "@" + value.at( 0 );
83  }
84  }
85  return std::visit( Gaudi::overload( []( const std::string& v ) { return v; },
86  []( const std::vector<std::string>& v ) {
87  return '[' + boost::algorithm::join( v, ", " ) + ']';
88  },
89  []( const std::map<std::string, std::string>& v ) {
90  std::string result = "{";
91  std::string delim = "";
92  for ( const auto& in : v ) {
93  result += delim + in.first + ":" + in.second;
94  delim = ", ";
95  }
96  return result + "}";
97  } ),
98  value_ );
99 }
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:736
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:128
auto overload(lambda_ts &&... lambdas)
Definition: compose.h:38