| The Gaudi Framework v29r0 (ff2e7097)

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