Go to the documentation of this file.00001
00002 #ifndef JOBOPTIONSVC_PROPERTY_VALUE_H_
00003 #define JOBOPTIONSVC_PROPERTY_VALUE_H_
00004
00005
00006
00007
00008
00009 #include <string>
00010 #include <vector>
00011 #include <map>
00012 #include <stdexcept>
00013
00014 #include <boost/variant.hpp>
00015 #include <boost/scoped_ptr.hpp>
00016 #include <boost/shared_ptr.hpp>
00017
00018 #include "Position.h"
00019
00020 namespace Gaudi { namespace Parsers {
00021
00022 class PropertyValue {
00023
00024 public:
00025 typedef boost::shared_ptr<PropertyValue> SharedPtr;
00026 typedef boost::shared_ptr<const PropertyValue> ConstSharedPtr;
00027 typedef boost::scoped_ptr<PropertyValue> ScopedPtr;
00028 typedef boost::scoped_ptr<const PropertyValue> ConstScopedPtr;
00029
00030 typedef boost::variant<std::string, std::vector<std::string>,
00031 std::map<std::string, std::string> > Value;
00032 typedef std::vector<std::string> VectorOfStrings;
00033 typedef std::map<std::string, std::string> MapOfStrings;
00034
00035
00036 explicit PropertyValue(const Value& value,
00037 bool is_reference=false): value_(value), is_reference_(is_reference) {}
00038 PropertyValue(const Value& value, const Position& position,
00039 bool is_reference=false): value_(value), position_(position),
00040 is_reference_(is_reference) {}
00041
00042 const Position& position() const { return position_;}
00043
00044 std::string& String() { return boost::get<std::string>(value_);}
00045 const std::string& String() const { return boost::get<std::string>(value_);}
00046
00047 VectorOfStrings& Vector() { return boost::get<VectorOfStrings>(value_);}
00048 const VectorOfStrings& Vector() const {
00049 return boost::get<VectorOfStrings>(value_);}
00050
00051 MapOfStrings& Map() { return boost::get<MapOfStrings>(value_);}
00052 const MapOfStrings& Map() const { return boost::get<MapOfStrings>(value_);}
00053
00054 std::string ToString() const;
00055 bool HasPosition() const {return position_.Exists();}
00056 bool IsSimple() const;
00057 bool IsVector() const;
00058 bool IsMap() const;
00059 bool IsReference() const { return is_reference_;};
00060
00061
00062
00063
00064 PropertyValue& operator += (const PropertyValue& right);
00065 const PropertyValue operator + (const PropertyValue& right);
00066 PropertyValue& operator -= (const PropertyValue& right);
00067 const PropertyValue operator - (const PropertyValue& right);
00068
00069 private:
00070 Value value_;
00071 Position position_;
00072 bool is_reference_;
00073
00074 };
00075
00076 class PropertyValueException : public std::runtime_error {
00077 public:
00078 PropertyValueException(const std::string& message):
00079 std::runtime_error(message){}
00080 static PropertyValueException WrongLValue() {
00081 return PropertyValueException("Cannot apply +=/-= operation to left value.");
00082 }
00083
00084 static PropertyValueException WrongRValue() {
00085 return PropertyValueException("Cannot apply +=/-= operation to right value.");
00086 }
00087
00088 };
00089
00090 class PositionalPropertyValueException : public std::runtime_error {
00091 public:
00092 PositionalPropertyValueException(const Position& position,
00093 const std::string& message): std::runtime_error(message),
00094 position_(position){}
00095 const Position& position() const { return position_;}
00096
00097 static PositionalPropertyValueException CouldNotFind(const Position& position,
00098 const std::string& name) {
00099 return PositionalPropertyValueException(position,
00100 "Could not find property "+name+".");
00101 }
00102
00103 static PositionalPropertyValueException CouldNotFindProperty(
00104 const Position& position,
00105 const std::string& name) {
00106 return PositionalPropertyValueException(position,
00107 "Could not find property '"+name+"'.");
00108 }
00109
00110 static PositionalPropertyValueException CouldNotFindUnit(
00111 const Position& position,
00112 const std::string& name) {
00113 return PositionalPropertyValueException(position,
00114 "Could not find unit '"+name+"'.");
00115 }
00116
00117 virtual ~PositionalPropertyValueException() throw() {}
00118 private:
00119 Position position_;
00120 };
00121
00122 } }
00123
00124 #endif // JOBOPTIONSVC_PROPERTY_VALUE_H_