| The Gaudi Framework v27r1

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

- File List
- File Members

PropertyValue.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 #include "PropertyValue.h"
5 // ============================================================================
6 // STD & STL:
7 // ============================================================================
8 // ============================================================================
9 // Boost:
10 // ============================================================================
11 #include <boost/format.hpp>
12 // ============================================================================
13 namespace gp = Gaudi::Parsers;
14 // ============================================================================
15 bool gp::PropertyValue::IsSimple() const {
16 return boost::get<std::string>(&value_) != NULL;
17 }
18 // ============================================================================
19 bool gp::PropertyValue::IsVector() const {
20 return boost::get<std::vector<std::string> >(&value_) != NULL;
21 }
22 // ============================================================================
23 bool gp::PropertyValue::IsMap() const {
24 return boost::get<std::map<std::string, std::string> >(&value_) != NULL;
25 }
26 // ============================================================================
27 gp::PropertyValue&
28 gp::PropertyValue::operator += (const PropertyValue& right) {
29
30 if (IsSimple() || IsReference()) {
31 throw PropertyValueException::WrongLValue();
32 }
33
34 if (IsVector()) {
35 if (right.IsSimple()) {
36 boost::get<VectorOfStrings>(value_).push_back(
37 boost::get<std::string>(right.value_));
38 return *this;
39 }
40 if (right.IsVector()){
41 VectorOfStrings& vec = boost::get<VectorOfStrings>(value_);
42 for (const auto& item : boost::get<VectorOfStrings>(right.value_)) {
43 vec.push_back(item);
44 }
45 return *this;
46 }
47 throw PropertyValueException::WrongRValue();
48 }
49
50 if (IsMap()) {
51 if (!right.IsMap()) {
52 throw PropertyValueException::WrongRValue();
53 }
54 MapOfStrings& map = boost::get<MapOfStrings>(value_);
55 const MapOfStrings& rmap = boost::get<MapOfStrings>(right.value_);
56 for (const auto& item : rmap) {
57 map.insert(item);
58 }
59 return *this;
60 }
61 return *this;
62 }
63
64 const gp::PropertyValue
65 gp::PropertyValue::operator+(const PropertyValue& right) {
66 return PropertyValue(*this) += right;
67
68 }
69
70 gp::PropertyValue&
71 gp::PropertyValue::operator-=(const PropertyValue& right) {
72 if (IsSimple() || IsReference()) {
73 throw PropertyValueException::WrongLValue();
74 }
75
76 if (IsVector()) {
77 VectorOfStrings& vec = Vector();
78 if (right.IsSimple()) {
79 vec.erase(std::find(vec.begin(), vec.end(), right.String()));
80 return *this;
81 }
82
83 if (right.IsVector()) {
84 const VectorOfStrings& rvec = right.Vector();
85 for (const auto& item : rvec) {
86 vec.erase(std::find(vec.begin(), vec.end(), item));
87 }
88 return *this;
89 }
90 throw PropertyValueException::WrongRValue();
91 }
92
93 if (IsMap()) {
94 MapOfStrings& map = Map();
95 if (right.IsSimple()) {
96 map.erase(right.String());
97 return *this;
98 }
99
100 if (right.IsVector()) {
101 const VectorOfStrings& rvec = right.Vector();
102 for (const auto& item : rvec) {
103 map.erase(item);
104 }
105 return *this;
106 }
107 throw PropertyValueException::WrongRValue();
108 }
109 throw PropertyValueException::WrongLValue();
110 }
111
112 const gp::PropertyValue
113 gp::PropertyValue::operator-(const PropertyValue& right) {
114 return PropertyValue(*this) -= right;
115 }
116 // ============================================================================
117 std::string gp::PropertyValue::ToString() const {
118 if (IsReference()) {
119 const std::vector<std::string>*
120 value = boost::get<std::vector<std::string> >(&value_);
121 assert(value != NULL);
122 if (value->at(0) != "") {
123 return "@"+value->at(0)+"."+value->at(1);
124 } else {
125 return "@"+value->at(0);
126 }
127 }
128 if (const std::string* value = boost::get<std::string>(&value_)) {
129 return *value;
130 } else if (const std::vector<std::string>*
131 value = boost::get<std::vector<std::string> >(&value_)) {
132 std::string result = "[";
133 std::string delim = "";
134 for (const auto& in : *value) {
135 result += delim + in;
136 delim = ", ";
137 }
138 return result+"]";
139 } else if (const std::map<std::string, std::string>*
140 value = boost::get<std::map<std::string, std::string> >(&value_)) {
141 std::string result = "{";
142 std::string delim = "";
143 for (const auto& in : *value) {
144 result += delim + in.first + ":" + in.second;
145 delim = ", ";
146 }
147 return result+"}";
148 }
149 assert(false);
150 // @todo Check the validity of this logic
151 return std::string(); // avoid compilation warning
152 }
153
Containers::Vector
KeyedObjectManager< vector > Vector
Forward declaration of specialized std::vector-like object manager.
Definition: KeyedObjectManager.h:98
std::vector::end
T end(T...args)
std::map< std::string, std::string >
std::string
STL class.
std::vector::at
T at(T...args)
std::vector::push_back
T push_back(T...args)
Gaudi::Parsers::PropertyValue
Definition: PropertyValue.h:19
Containers::map
struct GAUDI_API map
Parametrisation class for map-like implementation.
Definition: KeyedObjectManager.h:25
std::vector::erase
T erase(T...args)
dump_component_properties.value
list value
Definition: dump_component_properties.py:12
Gaudi::Parsers::PropertyValue::String
std::string & String()
Definition: PropertyValue.h:36
Gaudi::Parsers::PropertyValue::IsVector
bool IsVector() const
Definition: PropertyValue.cpp:19
Gaudi::Parsers::PropertyValue::Vector
VectorOfStrings & Vector()
Definition: PropertyValue.h:39
Gaudi::Parsers::PropertyValue::IsSimple
bool IsSimple() const
Definition: PropertyValue.cpp:15
std::map::insert
T insert(T...args)
std::find
T find(T...args)
std::vector< std::string >
GaudiPython.Persistency.get
def get(type_)
Definition: Persistency.py:23
std::vector::begin
T begin(T...args)
Gaudi::Parsers::PropertyValue::value_
Value value_
Definition: PropertyValue.h:62
Gaudi::Parsers
Definition: DODBasicMapper.cpp:7
ana.item
tuple item
print s1,s2
Definition: ana.py:146
PropertyValue.h
Gaudi::Parsers::PropertyValue::IsMap
bool IsMap() const
Definition: PropertyValue.cpp:23
operator+
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:163
operator-
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:168
Containers::Map
KeyedObjectManager< map > Map
Forward declaration of specialized std::map-like object manager.
Definition: KeyedObjectManager.h:94