| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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