| The Gaudi Framework v32r1 (f65d50dc)

PropertyValue.h
Go to the documentation of this file.
1 #ifndef JOBOPTIONSVC_PROPERTY_VALUE_H_
2 #define JOBOPTIONSVC_PROPERTY_VALUE_H_
3 // ============================================================================
4 // Includes:
5 // ============================================================================
6 // STD & STL:
7 // ============================================================================
8 #include <map>
9 #include <stdexcept>
10 #include <string>
11 #include <variant>
12 #include <vector>
13 // ============================================================================
14 #include "Position.h"
15 // ============================================================================
16 namespace Gaudi {
17 namespace Parsers {
18 // ============================================================================
19 class PropertyValue final {
20 // ----------------------------------------------------------------------------
21 public:
22 typedef std::variant<std::string, std::vector<std::string>, std::map<std::string, std::string>> Value;
23 typedef std::vector<std::string> VectorOfStrings;
24 typedef std::map<std::string, std::string> MapOfStrings;
25
26 // ----------------------------------------------------------------------------
27 explicit PropertyValue( Value value, bool is_reference = false )
28 : value_( std::move( value ) ), is_reference_( is_reference ) {}
29 PropertyValue( Value value, const Position& position, bool is_reference = false )
30 : value_( std::move( value ) ), position_( position ), is_reference_( is_reference ) {}
31 // ----------------------------------------------------------------------------
32 const Position& position() const { return position_; }
33 // ----------------------------------------------------------------------------
34 std::string& String() { return std::get<std::string>( value_ ); }
35 const std::string& String() const { return std::get<std::string>( value_ ); }
36
37 VectorOfStrings& Vector() { return std::get<VectorOfStrings>( value_ ); }
38 const VectorOfStrings& Vector() const { return std::get<VectorOfStrings>( value_ ); }
39
40 MapOfStrings& Map() { return std::get<MapOfStrings>( value_ ); }
41 const MapOfStrings& Map() const { return std::get<MapOfStrings>( value_ ); }
42 // ----------------------------------------------------------------------------
43 std::string ToString() const;
44 bool HasPosition() const { return position_.Exists(); }
45 bool IsSimple() const;
46 bool IsVector() const;
47 bool IsMap() const;
48 bool IsReference() const { return is_reference_; };
49 // ----------------------------------------------------------------------------
50 // Operators:
51 // ----------------------------------------------------------------------------
52
53 PropertyValue& operator+=( const PropertyValue& right );
54 const PropertyValue operator+( const PropertyValue& right );
55 PropertyValue& operator-=( const PropertyValue& right );
56 const PropertyValue operator-( const PropertyValue& right );
57 // bool operator == (const PropertyValue& right) const;
58 private:
59 Value value_;
60 Position position_;
61 bool is_reference_;
62 // ----------------------------------------------------------------------------
63 }; // class PropertyValue
64 // ============================================================================
65 class PropertyValueException : public std::runtime_error {
66 public:
67 PropertyValueException( const std::string& message ) : std::runtime_error( message ) {}
68 static PropertyValueException WrongLValue() {
69 return PropertyValueException( "Cannot apply +=/-= operation to left value." );
70 }
71
72 static PropertyValueException WrongRValue() {
73 return PropertyValueException( "Cannot apply +=/-= operation to right value." );
74 }
75 };
76
77 class PositionalPropertyValueException : public std::runtime_error {
78 public:
79 PositionalPropertyValueException( const Position& position, const std::string& message )
80 : std::runtime_error( message ), position_( position ) {}
81 const Position& position() const { return position_; }
82
83 static PositionalPropertyValueException CouldNotFind( const Position& position, const std::string& name ) {
84 return PositionalPropertyValueException( position, "Could not find property " + name + "." );
85 }
86
87 static PositionalPropertyValueException CouldNotFindProperty( const Position& position,
88 const std::string& name ) {
89 return PositionalPropertyValueException( position, "Could not find property '" + name + "'." );
90 }
91
92 static PositionalPropertyValueException CouldNotFindUnit( const Position& position, const std::string& name ) {
93 return PositionalPropertyValueException( position, "Could not find unit '" + name + "'." );
94 }
95
96 virtual ~PositionalPropertyValueException() throw() {}
97
98 private:
99 Position position_;
100 };
101 // ============================================================================
102 } // namespace Parsers
103 } // namespace Gaudi
104 // ============================================================================
105 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_
Gaudi::Parsers::PropertyValue::operator-
const PropertyValue operator-(const PropertyValue &right)
Definition: PropertyValue.cpp:62
Gaudi::Parsers::PropertyValue::VectorOfStrings
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:23
Gaudi::Parsers::PropertyValue::MapOfStrings
std::map< std::string, std::string > MapOfStrings
Definition: PropertyValue.h:24
Gaudi::Parsers::PropertyValue::Vector
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:38
Gaudi::Parsers::PropertyValue::IsVector
bool IsVector() const
Definition: PropertyValue.cpp:19
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::Parsers::PropertyValue::PropertyValue
PropertyValue(Value value, bool is_reference=false)
Definition: PropertyValue.h:27
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFind
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:83
Gaudi::Parsers::PositionalPropertyValueException::~PositionalPropertyValueException
virtual ~PositionalPropertyValueException()
Definition: PropertyValue.h:96
Gaudi::Parsers::PropertyValue::position_
Position position_
Definition: PropertyValue.h:60
Gaudi::Parsers::PropertyValue::HasPosition
bool HasPosition() const
Definition: PropertyValue.h:44
std
STL namespace.
Gaudi::Parsers::PropertyValue::ToString
std::string ToString() const
Definition: PropertyValue.cpp:66
Gaudi::Parsers::PositionalPropertyValueException::PositionalPropertyValueException
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:79
Gaudi::Parsers::PropertyValueException
Definition: PropertyValue.h:65
std::map< std::string, std::string >
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFindUnit
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
Definition: PropertyValue.h:92
std::string
STL class.
Gaudi::Parsers::PropertyValue::IsMap
bool IsMap() const
Definition: PropertyValue.cpp:21
Gaudi::Parsers::PropertyValue
Definition: PropertyValue.h:19
Gaudi::Parsers::PropertyValueException::PropertyValueException
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:67
Gaudi::Parsers::Position::Exists
bool Exists() const
Definition: Position.h:23
Gaudi::Parsers::PropertyValue::IsReference
bool IsReference() const
Definition: PropertyValue.h:48
Gaudi::Parsers::PropertyValue::Value
std::variant< std::string, std::vector< std::string >, std::map< std::string, std::string > > Value
Definition: PropertyValue.h:22
Gaudi::Parsers::PropertyValue::PropertyValue
PropertyValue(Value value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:29
Gaudi::Parsers::PropertyValueException::WrongRValue
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:72
std::runtime_error
STL class.
Gaudi::Parsers::PropertyValue::IsSimple
bool IsSimple() const
Definition: PropertyValue.cpp:17
Gaudi::Parsers::PositionalPropertyValueException
Definition: PropertyValue.h:77
Gaudi::Parsers::Position
Definition: Position.h:13
Gaudi::Parsers::PropertyValue::String
std::string & String()
Definition: PropertyValue.h:34
Gaudi::Parsers::PropertyValue::Vector
VectorOfStrings & Vector()
Definition: PropertyValue.h:37
Gaudi::Parsers::PropertyValue::operator+=
PropertyValue & operator+=(const PropertyValue &right)
Definition: PropertyValue.cpp:23
Gaudi::Parsers::PropertyValue::is_reference_
bool is_reference_
Definition: PropertyValue.h:61
Gaudi::Parsers::PositionalPropertyValueException::CouldNotFindProperty
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
Definition: PropertyValue.h:87
Gaudi::Parsers::PropertyValue::operator+
const PropertyValue operator+(const PropertyValue &right)
Definition: PropertyValue.cpp:40
Gaudi::Parsers::PropertyValue::operator-=
PropertyValue & operator-=(const PropertyValue &right)
Definition: PropertyValue.cpp:44
std::vector< std::string >
Gaudi::Parsers::PropertyValue::String
const std::string & String() const
Definition: PropertyValue.h:35
Position.h
Gaudi::Parsers::PropertyValue::value_
Value value_
Definition: PropertyValue.h:59
Gaudi::Parsers::PropertyValue::position
const Position & position() const
Definition: PropertyValue.h:32
Gaudi::Parsers::PositionalPropertyValueException::position_
Position position_
Definition: PropertyValue.h:99
Gaudi::Parsers::PropertyValueException::WrongLValue
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:68
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Parsers::PositionalPropertyValueException::position
const Position & position() const
Definition: PropertyValue.h:81
Gaudi::Parsers::PropertyValue::Map
const MapOfStrings & Map() const
Definition: PropertyValue.h:41
Gaudi::Parsers::PropertyValue::Map
MapOfStrings & Map()
Definition: PropertyValue.h:40