Go to the documentation of this file.00001
00002
00003
00004
00005 #include "PropertyValue.h"
00006
00007
00008
00009
00010
00011
00012 #include <boost/format.hpp>
00013 #include <boost/foreach.hpp>
00014
00015 namespace gp = Gaudi::Parsers;
00016
00017 bool gp::PropertyValue::IsSimple() const {
00018 return boost::get<std::string>(&value_) != NULL;
00019 }
00020
00021 bool gp::PropertyValue::IsVector() const {
00022 return boost::get<std::vector<std::string> >(&value_) != NULL;
00023 }
00024
00025 bool gp::PropertyValue::IsMap() const {
00026 return boost::get<std::map<std::string, std::string> >(&value_) != NULL;
00027 }
00028
00029 gp::PropertyValue&
00030 gp::PropertyValue::operator += (const PropertyValue& right) {
00031
00032 if (IsSimple() || IsReference()) {
00033 throw PropertyValueException::WrongLValue();
00034 }
00035
00036 if (IsVector()) {
00037 if (right.IsSimple()) {
00038 boost::get<VectorOfStrings>(value_).push_back(
00039 boost::get<std::string>(right.value_));
00040 return *this;
00041 }
00042 if (right.IsVector()){
00043 VectorOfStrings& vec = boost::get<VectorOfStrings>(value_);
00044 BOOST_FOREACH(const std::string& item,
00045 boost::get<VectorOfStrings>(right.value_)) {
00046 vec.push_back(item);
00047 }
00048 return *this;
00049 }
00050 throw PropertyValueException::WrongRValue();
00051 }
00052
00053 if (IsMap()) {
00054 if (!right.IsMap()) {
00055 throw PropertyValueException::WrongRValue();
00056 }
00057 MapOfStrings& map = boost::get<MapOfStrings>(value_);
00058 const MapOfStrings& rmap = boost::get<MapOfStrings>(right.value_);
00059 BOOST_FOREACH(const MapOfStrings::value_type& item, rmap) {
00060 map.insert(item);
00061 }
00062 return *this;
00063 }
00064 return *this;
00065 }
00066
00067 const gp::PropertyValue
00068 gp::PropertyValue::operator+(const PropertyValue& right) {
00069 return PropertyValue(*this) += right;
00070
00071 }
00072
00073 gp::PropertyValue&
00074 gp::PropertyValue::operator-=(const PropertyValue& right) {
00075 if (IsSimple() || IsReference()) {
00076 throw PropertyValueException::WrongLValue();
00077 }
00078
00079 if (IsVector()) {
00080 VectorOfStrings& vec = Vector();
00081 if (right.IsSimple()) {
00082 vec.erase(std::find(vec.begin(), vec.end(), right.String()));
00083 return *this;
00084 }
00085
00086 if (right.IsVector()) {
00087 const VectorOfStrings& rvec = right.Vector();
00088 BOOST_FOREACH(const std::string& item, rvec) {
00089 vec.erase(std::find(vec.begin(), vec.end(), item));
00090 }
00091 return *this;
00092 }
00093 throw PropertyValueException::WrongRValue();
00094 }
00095
00096 if (IsMap()) {
00097 MapOfStrings& map = Map();
00098 if (right.IsSimple()) {
00099 map.erase(right.String());
00100 return *this;
00101 }
00102
00103 if (right.IsVector()) {
00104 const VectorOfStrings& rvec = right.Vector();
00105 BOOST_FOREACH(const std::string& item, rvec) {
00106 map.erase(item);
00107 }
00108 return *this;
00109 }
00110 throw PropertyValueException::WrongRValue();
00111 }
00112 throw PropertyValueException::WrongLValue();
00113 }
00114
00115 const gp::PropertyValue
00116 gp::PropertyValue::operator-(const PropertyValue& right) {
00117 return PropertyValue(*this) -= right;
00118 }
00119
00120 std::string gp::PropertyValue::ToString() const {
00121 if (IsReference()) {
00122 const std::vector<std::string>*
00123 value = boost::get<std::vector<std::string> >(&value_);
00124 assert(value != NULL);
00125 if (value->at(0) != "") {
00126 return "@"+value->at(0)+"."+value->at(1);
00127 } else {
00128 return "@"+value->at(0);
00129 }
00130 }
00131 if (const std::string* value = boost::get<std::string>(&value_)) {
00132 return *value;
00133 } else if (const std::vector<std::string>*
00134 value = boost::get<std::vector<std::string> >(&value_)) {
00135 std::string result = "[";
00136 std::string delim = "";
00137 BOOST_FOREACH(const std::string& in, *value) {
00138 result += delim + in;
00139 delim = ", ";
00140 }
00141 return result+"]";
00142 } else if (const std::map<std::string, std::string>*
00143 value = boost::get<std::map<std::string, std::string> >(&value_)) {
00144 std::string result = "{";
00145 std::string delim = "";
00146 typedef std::pair<std::string, std::string> pair_t;
00147 BOOST_FOREACH(const pair_t& in, *value) {
00148 result += delim + in.first + ":" + in.second;
00149 delim = ", ";
00150 }
00151 return result+"}";
00152 }
00153 assert(false);
00154
00155 return std::string();
00156 }
00157