StdAir Logo  1.00.18
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
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_MACRO >= 104100
14// Boost Property Tree
15#include <boost/property_tree/ptree.hpp>
16#endif // BOOST_VERSION_MACRO >= 104100
17// StdAir
23
24#if BOOST_VERSION_MACRO >= 104100
25namespace bpt = boost::property_tree;
26#else // BOOST_VERSION_MACRO >= 104100
27namespace bpt {
28 typedef char ptree;
29}
30#endif // BOOST_VERSION_MACRO >= 104100
31
32namespace 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_MACRO >= 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_MACRO >= 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<>
175 (Date_T& ioValue,
176 const std::string& iPath) const {
177
178 bool hasValueBeenSuccessfullyRetrieved = true;
179
180#if BOOST_VERSION_MACRO >= 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_MACRO >= 104100
199
200 return hasValueBeenSuccessfullyRetrieved;
201
202
203 }
204
205}
206
207#endif // __STDAIR_BOM_CONFIGHOLDERSTRUCT_HPP
Handle on the StdAir library context.
boost::gregorian::date Date_T
char ptree
Class representing the actual attributes for the Bom root.
Definition BomRoot.hpp:32
const std::string describe() const
void add(const bpt::ptree &)
bool exportValue(ValueType &ioValue, const std::string &iPath) const
bool addValue(const std::string &iValue, const std::string &iPath)
const std::string jsonExport() const
void toStream(std::ostream &ioOut) const
void fromStream(std::istream &ioIn)