Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 { return boost::get<std::string>( &value_ ) != NULL; }
16 // ============================================================================
17 bool gp::PropertyValue::IsVector() const { return boost::get<std::vector<std::string>>( &value_ ) != NULL; }
18 // ============================================================================
19 bool gp::PropertyValue::IsMap() const { return boost::get<std::map<std::string, std::string>>( &value_ ) != NULL; }
20 // ============================================================================
21 gp::PropertyValue& gp::PropertyValue::operator+=( const PropertyValue& right ) {
22 
23  if ( IsSimple() || IsReference() ) { throw PropertyValueException::WrongLValue(); }
24 
25  if ( IsVector() ) {
26  if ( right.IsSimple() ) {
27  boost::get<VectorOfStrings>( value_ ).push_back( boost::get<std::string>( right.value_ ) );
28  return *this;
29  }
30  if ( right.IsVector() ) {
31  VectorOfStrings& vec = boost::get<VectorOfStrings>( value_ );
32  for ( const auto& item : boost::get<VectorOfStrings>( right.value_ ) ) { vec.push_back( item ); }
33  return *this;
34  }
35  throw PropertyValueException::WrongRValue();
36  }
37 
38  if ( IsMap() ) {
39  if ( !right.IsMap() ) { throw PropertyValueException::WrongRValue(); }
40  MapOfStrings& map = boost::get<MapOfStrings>( value_ );
41  const MapOfStrings& rmap = boost::get<MapOfStrings>( right.value_ );
42  for ( const auto& item : rmap ) { map.insert( item ); }
43  return *this;
44  }
45  return *this;
46 }
47 
48 const gp::PropertyValue gp::PropertyValue::operator+( const PropertyValue& right ) {
49  return PropertyValue{*this} += right;
50 }
51 
52 gp::PropertyValue& gp::PropertyValue::operator-=( const PropertyValue& right ) {
53  if ( IsSimple() || IsReference() ) { throw PropertyValueException::WrongLValue(); }
54 
55  if ( IsVector() ) {
56  VectorOfStrings& vec = Vector();
57  if ( right.IsSimple() ) {
58  vec.erase( std::find( vec.begin(), vec.end(), right.String() ) );
59  return *this;
60  }
61 
62  if ( right.IsVector() ) {
63  const VectorOfStrings& rvec = right.Vector();
64  for ( const auto& item : rvec ) { vec.erase( std::find( vec.begin(), vec.end(), item ) ); }
65  return *this;
66  }
67  throw PropertyValueException::WrongRValue();
68  }
69 
70  if ( IsMap() ) {
71  MapOfStrings& map = Map();
72  if ( right.IsSimple() ) {
73  map.erase( right.String() );
74  return *this;
75  }
76 
77  if ( right.IsVector() ) {
78  const VectorOfStrings& rvec = right.Vector();
79  for ( const auto& item : rvec ) { map.erase( item ); }
80  return *this;
81  }
82  throw PropertyValueException::WrongRValue();
83  }
84  throw PropertyValueException::WrongLValue();
85 }
86 
87 const gp::PropertyValue gp::PropertyValue::operator-( const PropertyValue& right ) {
88  return PropertyValue{*this} -= right;
89 }
90 // ============================================================================
91 std::string gp::PropertyValue::ToString() const {
92  if ( IsReference() ) {
93  const std::vector<std::string>* value = boost::get<std::vector<std::string>>( &value_ );
94  assert( value != NULL );
95  if ( value->at( 0 ) != "" ) {
96  return "@" + value->at( 0 ) + "." + value->at( 1 );
97  } else {
98  return "@" + value->at( 0 );
99  }
100  }
101  if ( const std::string* value = boost::get<std::string>( &value_ ) ) {
102  return *value;
103  } else if ( const std::vector<std::string>* value = boost::get<std::vector<std::string>>( &value_ ) ) {
104  std::string result = "[";
105  std::string delim = "";
106  for ( const auto& in : *value ) {
107  result += delim + in;
108  delim = ", ";
109  }
110  return result + "]";
111  } else if ( const std::map<std::string, std::string>* value =
113  std::string result = "{";
114  std::string delim = "";
115  for ( const auto& in : *value ) {
116  result += delim + in.first + ":" + in.second;
117  delim = ", ";
118  }
119  return result + "}";
120  }
121  assert( false );
122  // @todo Check the validity of this logic
123  return std::string(); // avoid compilation warning
124 }
T end(T...args)
void push_back(Container &c, const Value &v, std::true_type)
STL class.
T at(T...args)
T push_back(T...args)
struct GAUDI_API map
Parametrisation class for map-like implementation.
KeyedObjectManager< vector > Vector
Forward declaration of specialized std::vector-like object manager.
T erase(T...args)
VectorOfStrings & Vector()
Definition: PropertyValue.h:38
T insert(T...args)
T find(T...args)
T begin(T...args)
decltype(auto) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:707
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:118
KeyedObjectManager< map > Map
Forward declaration of specialized std::map-like object manager.