$treeview $search $mathjax
StdAir Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

stdair/bom/ConfigHolderStruct.hpp

Go to the documentation of this file.
00001 #ifndef __STDAIR_BOM_CONFIGHOLDERSTRUCT_HPP
00002 #define __STDAIR_BOM_CONFIGHOLDERSTRUCT_HPP
00003 
00004 // //////////////////////////////////////////////////////////////////////
00005 // Import section
00006 // //////////////////////////////////////////////////////////////////////
00007 // STL
00008 #include <iosfwd>
00009 #include <string>
00010 // Boost
00011 #include <boost/static_assert.hpp>
00012 #include <boost/type_traits/is_same.hpp>
00013 #if BOOST_VERSION >= 104100
00014 // Boost Property Tree
00015 #include <boost/property_tree/ptree.hpp>
00016 #endif // BOOST_VERSION >= 104100
00017 // StdAir
00018 #include <stdair/stdair_file.hpp>
00019 #include <stdair/stdair_maths_types.hpp>
00020 #include <stdair/stdair_date_time_types.hpp>
00021 #include <stdair/basic/StructAbstract.hpp>
00022 #include <stdair/bom/ConfigHolderTypes.hpp>
00023 
00024 #if BOOST_VERSION >= 104100
00025 namespace bpt = boost::property_tree;
00026 #else // BOOST_VERSION >= 104100
00027 namespace bpt {
00028   typedef char ptree;
00029 }
00030 #endif // BOOST_VERSION >= 104100
00031 
00032 namespace stdair {
00033 
00035   class BomRoot;
00036 
00040   struct ConfigHolderStruct : public StructAbstract {
00041   public:
00042     // /////////////// Getters /////////////////
00043 
00044     // ///////////// Business Methods //////////
00051     void add (const bpt::ptree&);   
00052 
00061     bool addValue (const std::string& iValue, 
00062                    const std::string& iPath);   
00063 
00072     template <typename ValueType> 
00073     bool exportValue (ValueType& ioValue, const std::string& iPath) const;
00074 
00081     void updateAirlineFeatures (BomRoot&);
00082 
00083   private: 
00087     void add (const bpt::ptree&, 
00088               const std::string&);
00089     
00090   public:     
00091     // /////////// Display support method /////////////
00096     void toStream (std::ostream& ioOut) const;
00097 
00102     void fromStream (std::istream& ioIn);
00103 
00107     const std::string describe() const; 
00108 
00112     const std::string jsonExport() const;
00113 
00114     
00115     // /////////////// Constructors and Destructors /////////////////
00116   public:
00120     ConfigHolderStruct ();
00121 
00125     ConfigHolderStruct (const ConfigHolderStruct&);
00126 
00127   public:
00131     ~ConfigHolderStruct();
00132     
00133 
00134   private:
00135     // /////////////// Attributes /////////////////
00139     bpt::ptree _pt;
00140   };
00141 
00142   // ////////////////////////////////////////////////////////////////////
00143   template <typename ValueType> 
00144   bool ConfigHolderStruct::exportValue (ValueType& ioValue,
00145                                         const std::string& iPath) const {
00146   
00147     bool hasValueBeenSuccessfullyRetrieved = true;
00148 
00149 #if BOOST_VERSION >= 104100
00150     try {
00151       // Get the value.
00152       // If the path key is not found, an exception is thrown.
00153       const std::string lPrefix ("config.");
00154       const std::string lFinalPath = lPrefix + iPath;
00155       ioValue = _pt.get<ValueType> (lFinalPath);
00156     
00157     } catch (bpt::ptree_error& bptException) {
00158       hasValueBeenSuccessfullyRetrieved = false;
00159     }
00160 #endif // BOOST_VERSION >= 104100
00161     
00162     return hasValueBeenSuccessfullyRetrieved;
00163     
00164   }
00165   
00166   // ////////////////////////////////////////////////////////////////////
00167   //
00168   // Specialization of the template method exportValue above for the type
00169   // Date_T.
00170   //
00171   // ////////////////////////////////////////////////////////////////////
00172 
00173   template<>
00174   inline bool ConfigHolderStruct::exportValue<Date_T> 
00175   (Date_T& ioValue,
00176    const std::string& iPath) const {     
00177 
00178     bool hasValueBeenSuccessfullyRetrieved = true;
00179 
00180 #if BOOST_VERSION >= 104100
00181     
00182     try { 
00183 
00184       // Get the string date value. 
00185       // If the path key is not found, an exception is thrown.
00186       const std::string lPrefix ("config.");
00187       const std::string lFinalPath = lPrefix + iPath;
00188       const std::string& lDateStr =
00189         _pt.get<std::string> (lFinalPath);
00190       
00191       // Convert the string into a Date_T.
00192       ioValue = 
00193         boost::gregorian::from_simple_string (lDateStr);
00194     
00195     } catch (bpt::ptree_error& bptException) {
00196       hasValueBeenSuccessfullyRetrieved = false;
00197     }
00198 #endif // BOOST_VERSION >= 104100
00199     
00200     return hasValueBeenSuccessfullyRetrieved;
00201 
00202     
00203   }
00204 
00205 }
00206 
00207 #endif // __STDAIR_BOM_CONFIGHOLDERSTRUCT_HPP