| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PropertyValue.h
Go to the documentation of this file.
1 // $Id:$
2 #ifndef JOBOPTIONSVC_PROPERTY_VALUE_H_
3 #define JOBOPTIONSVC_PROPERTY_VALUE_H_
4 // ============================================================================
5 // Includes:
6 // ============================================================================
7 // STD & STL:
8 // ============================================================================
9 #include <string>
10 #include <vector>
11 #include <map>
12 #include <stdexcept>
13 // ============================================================================
14 #include <boost/variant.hpp>
15 #include <boost/scoped_ptr.hpp>
16 // ============================================================================
17 #include "Position.h"
18 // ============================================================================
19 namespace Gaudi { namespace Parsers {
20 // ============================================================================
21 class PropertyValue {
22 // ----------------------------------------------------------------------------
23 public:
24 typedef boost::scoped_ptr<PropertyValue> ScopedPtr;
25 typedef boost::scoped_ptr<const PropertyValue> ConstScopedPtr;
26
27 typedef boost::variant<std::string, std::vector<std::string>,
28 std::map<std::string, std::string> > Value;
29 typedef std::vector<std::string> VectorOfStrings;
30 typedef std::map<std::string, std::string> MapOfStrings;
31
32 // ----------------------------------------------------------------------------
33 explicit PropertyValue(const Value& value,
34 bool is_reference=false): value_(value), is_reference_(is_reference) {}
35 PropertyValue(const Value& value, const Position& position,
36 bool is_reference=false): value_(value), position_(position),
37 is_reference_(is_reference) {}
38 // ----------------------------------------------------------------------------
39 const Position& position() const { return position_;}
40 // ----------------------------------------------------------------------------
41 std::string& String() { return boost::get<std::string>(value_);}
42 const std::string& String() const { return boost::get<std::string>(value_);}
43
44 VectorOfStrings& Vector() { return boost::get<VectorOfStrings>(value_);}
45 const VectorOfStrings& Vector() const {
46 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 public:
75 PropertyValueException(const std::string& message):
76 std::runtime_error(message){}
77 static PropertyValueException WrongLValue() {
78 return PropertyValueException("Cannot apply +=/-= operation to left value.");
79 }
80
81 static PropertyValueException WrongRValue() {
82 return PropertyValueException("Cannot apply +=/-= operation to right value.");
83 }
84
85 };
86
87 class PositionalPropertyValueException : public std::runtime_error {
88 public:
89 PositionalPropertyValueException(const Position& position,
90 const std::string& message): std::runtime_error(message),
91 position_(position){}
92 const Position& position() const { return position_;}
93
94 static PositionalPropertyValueException CouldNotFind(const Position& position,
95 const std::string& name) {
96 return PositionalPropertyValueException(position,
97 "Could not find property "+name+".");
98 }
99
100 static PositionalPropertyValueException CouldNotFindProperty(
101 const Position& position,
102 const std::string& name) {
103 return PositionalPropertyValueException(position,
104 "Could not find property '"+name+"'.");
105 }
106
107 static PositionalPropertyValueException CouldNotFindUnit(
108 const Position& position,
109 const std::string& name) {
110 return PositionalPropertyValueException(position,
111 "Could not find unit '"+name+"'.");
112 }
113
114 virtual ~PositionalPropertyValueException() throw() {}
115 private:
116 Position position_;
117 };
118 // ============================================================================
119 } /* Gaudi */ } /* Parsers */
120 // ============================================================================
121 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_