StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
ConfigHolderStruct.hpp
Go to the documentation of this file.
1 #ifndef __STDAIR_BOM_CONFIGHOLDERSTRUCT_HPP
2 #define __STDAIR_BOM_CONFIGHOLDERSTRUCT_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <iosfwd>
9 #include <string>
10 // Boost
11 #include <boost/static_assert.hpp>
12 #include <boost/type_traits/is_same.hpp>
13 #if BOOST_VERSION >= 104100
14 // Boost Property Tree
15 #include <boost/property_tree/ptree.hpp>
16 #endif // BOOST_VERSION >= 104100
17 // StdAir
18 #include <stdair/stdair_file.hpp>
23 
24 #if BOOST_VERSION >= 104100
25 namespace bpt = boost::property_tree;
26 #else // BOOST_VERSION >= 104100
27 namespace bpt {
28  typedef char ptree;
29 }
30 #endif // BOOST_VERSION >= 104100
31 
32 namespace stdair {
33 
35  class BomRoot;
36 
41  public:
42  // /////////////// Getters /////////////////
43 
44  // ///////////// Business Methods //////////
51  void add (const bpt::ptree&);
52 
61  bool addValue (const std::string& iValue,
62  const std::string& iPath);
63 
72  template <typename ValueType>
73  bool exportValue (ValueType& ioValue, const std::string& iPath) const;
74 
82 
83  private:
87  void add (const bpt::ptree&,
88  const std::string&);
89 
90  public:
91  // /////////// Display support method /////////////
96  void toStream (std::ostream& ioOut) const;
97 
102  void fromStream (std::istream& ioIn);
103 
107  const std::string describe() const;
108 
112  const std::string jsonExport() const;
113 
114 
115  // /////////////// Constructors and Destructors /////////////////
116  public:
121 
126 
127  public:
132 
133 
134  private:
135  // /////////////// Attributes /////////////////
139  bpt::ptree _pt;
140  };
141 
142  // ////////////////////////////////////////////////////////////////////
143  template <typename ValueType>
144  bool ConfigHolderStruct::exportValue (ValueType& ioValue,
145  const std::string& iPath) const {
146 
147  bool hasValueBeenSuccessfullyRetrieved = true;
148 
149 #if BOOST_VERSION >= 104100
150  try {
151  // Get the value.
152  // If the path key is not found, an exception is thrown.
153  const std::string lPrefix ("config.");
154  const std::string lFinalPath = lPrefix + iPath;
155  ioValue = _pt.get<ValueType> (lFinalPath);
156 
157  } catch (bpt::ptree_error& bptException) {
158  hasValueBeenSuccessfullyRetrieved = false;
159  }
160 #endif // BOOST_VERSION >= 104100
161 
162  return hasValueBeenSuccessfullyRetrieved;
163 
164  }
165 
166  // ////////////////////////////////////////////////////////////////////
167  //
168  // Specialization of the template method exportValue above for the type
169  // Date_T.
170  //
171  // ////////////////////////////////////////////////////////////////////
172 
173  template<>
174  inline bool ConfigHolderStruct::exportValue<Date_T>
175  (Date_T& ioValue,
176  const std::string& iPath) const {
177 
178  bool hasValueBeenSuccessfullyRetrieved = true;
179 
180 #if BOOST_VERSION >= 104100
181 
182  try {
183 
184  // Get the string date value.
185  // If the path key is not found, an exception is thrown.
186  const std::string lPrefix ("config.");
187  const std::string lFinalPath = lPrefix + iPath;
188  const std::string& lDateStr =
189  _pt.get<std::string> (lFinalPath);
190 
191  // Convert the string into a Date_T.
192  ioValue =
193  boost::gregorian::from_simple_string (lDateStr);
194 
195  } catch (bpt::ptree_error& bptException) {
196  hasValueBeenSuccessfullyRetrieved = false;
197  }
198 #endif // BOOST_VERSION >= 104100
199 
200  return hasValueBeenSuccessfullyRetrieved;
201 
202 
203  }
204 
205 }
206 
207 #endif // __STDAIR_BOM_CONFIGHOLDERSTRUCT_HPP
bool exportValue(ValueType &ioValue, const std::string &iPath) const
Handle on the StdAir library context.
bool addValue(const std::string &iValue, const std::string &iPath)
void fromStream(std::istream &ioIn)
char ptree
Base class for the light structures.
const std::string describe() const
boost::gregorian::date Date_T
Class representing the actual attributes for the Bom root.
Definition: BomRoot.hpp:32
void toStream(std::ostream &ioOut) const
void add(const bpt::ptree &)
const std::string jsonExport() const