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 // ============================================================================
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) {}
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 
62  const PropertyValue operator + (const PropertyValue& right);
64  const PropertyValue operator - (const PropertyValue& right);
65  //bool operator == (const PropertyValue& right) const;
66  private:
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){}
78  return PropertyValueException("Cannot apply +=/-= operation to left value.");
79  }
80 
82  return PropertyValueException("Cannot apply +=/-= operation to right value.");
83  }
84 
85 };
86 
87 class PositionalPropertyValueException : public std::runtime_error {
88  public:
90  const std::string& message): std::runtime_error(message),
91  position_(position){}
92  const Position& position() const { return position_;}
93 
95  const std::string& name) {
96  return PositionalPropertyValueException(position,
97  "Could not find property "+name+".");
98  }
99 
101  const Position& position,
102  const std::string& name) {
103  return PositionalPropertyValueException(position,
104  "Could not find property '"+name+"'.");
105  }
106 
108  const Position& position,
109  const std::string& name) {
110  return PositionalPropertyValueException(position,
111  "Could not find unit '"+name+"'.");
112  }
113 
115  private:
117 };
118 // ============================================================================
119 } /* Gaudi */ } /* Parsers */
120 // ============================================================================
121 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_
const PropertyValue operator-(const PropertyValue &right)
std::vector< std::string > VectorOfStrings
Definition: PropertyValue.h:29
std::map< std::string, std::string > MapOfStrings
Definition: PropertyValue.h:30
const std::string & String() const
Definition: PropertyValue.h:42
static PositionalPropertyValueException CouldNotFind(const Position &position, const std::string &name)
Definition: PropertyValue.h:94
PropertyValue(const Value &value, bool is_reference=false)
Definition: PropertyValue.h:33
const MapOfStrings & Map() const
Definition: PropertyValue.h:49
PositionalPropertyValueException(const Position &position, const std::string &message)
Definition: PropertyValue.h:89
static PositionalPropertyValueException CouldNotFindUnit(const Position &position, const std::string &name)
const VectorOfStrings & Vector() const
Definition: PropertyValue.h:45
PropertyValueException(const std::string &message)
Definition: PropertyValue.h:75
static PropertyValueException WrongRValue()
Definition: PropertyValue.h:81
boost::scoped_ptr< const PropertyValue > ConstScopedPtr
Definition: PropertyValue.h:25
const Position & position() const
Definition: PropertyValue.h:39
boost::variant< std::string, std::vector< std::string >, std::map< std::string, std::string > > Value
Definition: PropertyValue.h:28
VectorOfStrings & Vector()
Definition: PropertyValue.h:44
PropertyValue & operator+=(const PropertyValue &right)
static PositionalPropertyValueException CouldNotFindProperty(const Position &position, const std::string &name)
const PropertyValue operator+(const PropertyValue &right)
PropertyValue & operator-=(const PropertyValue &right)
std::string ToString() const
PropertyValue(const Value &value, const Position &position, bool is_reference=false)
Definition: PropertyValue.h:35
bool Exists() const
Definition: Position.h:23
std
AIDA -> ROTO converter.
Definition: GaudiAlgs.py:73
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:15
boost::scoped_ptr< PropertyValue > ScopedPtr
Definition: PropertyValue.h:24
static PropertyValueException WrongLValue()
Definition: PropertyValue.h:77