The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
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/SerializeSTL.h
>
13
#include <
GaudiKernel/compose.h
>
14
#include <algorithm>
15
#include <sstream>
16
17
namespace
gp
=
Gaudi::Parsers
;
18
19
bool
gp::PropertyValue::IsSimple
()
const
{
return
std::holds_alternative<std::string>(
value_
); }
20
bool
gp::PropertyValue::IsVector
()
const
{
return
std::holds_alternative<VectorOfStrings>(
value_
); }
21
bool
gp::PropertyValue::IsMap
()
const
{
return
std::holds_alternative<MapOfStrings>(
value_
); }
22
gp::PropertyValue
&
gp::PropertyValue::operator+=
(
const
PropertyValue
& right ) {
23
24
if
(
IsReference
() ) {
throw
PropertyValueException::WrongLValue
(); }
25
std::visit(
26
Gaudi::overload
(
27
[]( std::string&,
const
auto
& ) {
throw
PropertyValueException::WrongLValue
(); },
28
[](
VectorOfStrings
& lhs,
const
std::string& rhs ) { lhs.push_back( rhs ); },
29
[](
VectorOfStrings
& lhs,
const
VectorOfStrings
& rhs ) { lhs.insert( lhs.end(), rhs.begin(), rhs.end() ); },
30
[](
MapOfStrings
& lhs,
const
MapOfStrings
& rhs ) { lhs.insert( rhs.begin(), rhs.end() ); },
31
[](
auto
&,
const
auto
& ) {
throw
PropertyValueException::WrongRValue
(); } ),
32
value_
, right.
value_
);
33
return
*
this
;
34
}
35
36
const
gp::PropertyValue
gp::PropertyValue::operator+
(
const
PropertyValue
& right ) {
37
return
PropertyValue
{ *
this
} += right;
38
}
39
40
gp::PropertyValue
&
gp::PropertyValue::operator-=
(
const
PropertyValue
& right ) {
41
if
(
IsReference
() ) {
throw
PropertyValueException::WrongLValue
(); }
42
std::visit(
Gaudi::overload
( [](
VectorOfStrings
& lhs,
43
const
std::string& rhs ) { lhs.erase( std::find( lhs.begin(), lhs.end(), rhs ) ); },
44
[](
VectorOfStrings
& lhs,
const
VectorOfStrings
& rhs ) {
45
for
(
const
auto
& item : rhs ) lhs.erase( std::find( lhs.begin(), lhs.end(), item ) );
46
},
47
[](
MapOfStrings
& lhs,
const
std::string& rhs ) { lhs.erase( rhs ); },
48
[](
MapOfStrings
& lhs,
const
VectorOfStrings
& 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
57
const
gp::PropertyValue
gp::PropertyValue::operator-
(
const
PropertyValue
& right ) {
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
[](
const
auto
& v ) {
72
// make sure to be consistent by explicitly re-using `GaudiUtils::operator<<`
73
using
GaudiUtils::operator<<;
// cppcheck-suppress constStatement
74
std::ostringstream s{};
75
s << v;
76
return
s.str();
77
},
78
value_
);
79
}
PropertyValue.h
SerializeSTL.h
Provide serialization function (output only) for some common STL classes (vectors,...
Gaudi::Parsers::PropertyValueException::WrongRValue
static PropertyValueException WrongRValue()
Definition
PropertyValue.h:70
Gaudi::Parsers::PropertyValueException::WrongLValue
static PropertyValueException WrongLValue()
Definition
PropertyValue.h:66
Gaudi::Parsers::PropertyValue
Definition
PropertyValue.h:22
Gaudi::Parsers::PropertyValue::VectorOfStrings
std::vector< std::string > VectorOfStrings
Definition
PropertyValue.h:24
Gaudi::Parsers::PropertyValue::MapOfStrings
std::map< std::string, std::string, std::less<> > MapOfStrings
Definition
PropertyValue.h:25
Gaudi::Parsers::PropertyValue::operator+
const PropertyValue operator+(const PropertyValue &right)
Definition
PropertyValue.cpp:36
Gaudi::Parsers::PropertyValue::IsMap
bool IsMap() const
Definition
PropertyValue.cpp:21
Gaudi::Parsers::PropertyValue::operator+=
PropertyValue & operator+=(const PropertyValue &right)
Definition
PropertyValue.cpp:22
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::PropertyValue
PropertyValue(Value value, bool is_reference=false)
Definition
PropertyValue.h:29
Gaudi::Parsers::PropertyValue::operator-=
PropertyValue & operator-=(const PropertyValue &right)
Definition
PropertyValue.cpp:40
Gaudi::Parsers::PropertyValue::value_
Value value_
Definition
PropertyValue.h:58
Gaudi::Parsers::PropertyValue::IsVector
bool IsVector() const
Definition
PropertyValue.cpp:20
Gaudi::Parsers::PropertyValue::IsReference
bool IsReference() const
Definition
PropertyValue.h:50
Gaudi::Parsers::PropertyValue::IsSimple
bool IsSimple() const
Definition
PropertyValue.cpp:19
compose.h
Gaudi::Parsers
Definition
DODBasicMapper.cpp:17
Gaudi::overload
auto overload(lambda_ts &&... lambdas)
Definition
compose.h:37
GaudiCoreSvc
src
JobOptionsSvc
PropertyValue.cpp
Generated on
for The Gaudi Framework by
1.17.0