Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
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( Gaudi::overload( []( VectorOfStrings& lhs,
42  const std::string& rhs ) { lhs.erase( std::find( lhs.begin(), lhs.end(), rhs ) ); },
43  []( VectorOfStrings& lhs, const VectorOfStrings& rhs ) {
44  for ( const auto& item : rhs ) lhs.erase( std::find( lhs.begin(), lhs.end(), item ) );
45  },
46  []( MapOfStrings& lhs, const std::string& rhs ) { lhs.erase( rhs ); },
47  []( MapOfStrings& lhs, const VectorOfStrings& rhs ) {
48  for ( const auto& item : rhs ) lhs.erase( item );
49  },
50  []( std::string&, const auto& ) { throw PropertyValueException::WrongLValue(); },
51  []( auto&, const auto& ) { throw PropertyValueException::WrongRValue(); } ),
52  value_, right.value_ );
53  return *this;
54 }
55 
57  return PropertyValue{ *this } -= right;
58 }
59 
60 std::string gp::PropertyValue::ToString() const {
61  if ( IsReference() ) {
62  const auto& value = std::get<VectorOfStrings>( value_ );
63  if ( value.at( 0 ) != "" ) {
64  return "@" + value.at( 0 ) + "." + value.at( 1 );
65  } else {
66  return "@" + value.at( 0 );
67  }
68  }
69  return std::visit(
70  []( const auto& v ) {
71  // make sure to be consistent by explicitly re-using `GaudiUtils::operator<<`
72  using GaudiUtils::operator<<;
73  std::ostringstream s{};
74  s << v;
75  return s.str();
76  },
77  value_ );
78 }
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:56
Gaudi::Parsers::PropertyValue::ToString
std::string ToString() const
Definition: PropertyValue.cpp:60
gaudirun.s
string s
Definition: gaudirun.py:346
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
SerializeSTL.h
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