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) {}
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 
57  const PropertyValue operator + (const PropertyValue& right);
59  const PropertyValue operator - (const PropertyValue& right);
60  //bool operator == (const PropertyValue& right) const;
61  private:
62  Value value_;
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){}
73  return PropertyValueException("Cannot apply +=/-= operation to left value.");
74  }
75 
77  return PropertyValueException("Cannot apply +=/-= operation to right value.");
78  }
79 
80 };
81 
82 class PositionalPropertyValueException : public std::runtime_error {
83  public:
85  const std::string& message): std::runtime_error(message),
86  position_(position){}
87  const Position& position() const { return position_;}
88 
90  const std::string& name) {
91  return PositionalPropertyValueException(position,
92  "Could not find property "+name+".");
93  }
94 
96  const Position& position,
97  const std::string& name) {
98  return PositionalPropertyValueException(position,
99  "Could not find property '"+name+"'.");
100  }
101 
103  const Position& position,
104  const std::string& name) {
105  return PositionalPropertyValueException(position,
106  "Could not find unit '"+name+"'.");
107  }
108 
110  private:
112 };
113 // ============================================================================
114 } /* Gaudi */ } /* Parsers */
115 // ============================================================================
116 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_
const PropertyValue operator-(const PropertyValue &right)
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:24
std::map< std::string, std::string > MapOfStrings
Definition: PropertyValue.h:25
const std::string & String() const
Definition: PropertyValue.h:37
PropertyValue(Value value, bool is_reference=false)
Definition: PropertyValue.h:28
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:89
STL namespace.
const MapOfStrings & Map() const
Definition: PropertyValue.h:44
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:84
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:40
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:70
PropertyValue(Value value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:30
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:76
const Position & position() const
Definition: PropertyValue.h:34
boost::variant< std::string, std::vector< std::string >, std::map< std::string, std::string > > Value
Definition: PropertyValue.h:23
VectorOfStrings & Vector()
Definition: PropertyValue.h:39
PropertyValue & operator+=(const PropertyValue &right)
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
Definition: PropertyValue.h:95
const PropertyValue operator+(const PropertyValue &right)
PropertyValue & operator-=(const PropertyValue &right)
std::string ToString() const
bool Exists() const
Definition: Position.h:22
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:72
Helper functions to set/get the application return code.
Definition: __init__.py:1