StdAir Logo  0.45.0
C++ Standard Airline IT Object Library
CmdBomSerialiser.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // Boost.Serialization
00008 #include <boost/archive/text_iarchive.hpp>
00009 #include <boost/archive/text_oarchive.hpp>
00010 #include <boost/serialization/list.hpp>
00011 #include <boost/serialization/map.hpp>
00012 #include <boost/serialization/access.hpp>
00013 // StdAir
00014 #include <stdair/basic/BasConst_General.hpp>
00015 #include <stdair/basic/BasConst_Inventory.hpp>
00016 #include <stdair/bom/BomRoot.hpp>
00017 #include <stdair/bom/Inventory.hpp>
00018 #include <stdair/bom/FlightDate.hpp>
00019 #include <stdair/bom/SegmentDate.hpp>
00020 #include <stdair/bom/SegmentCabin.hpp>
00021 #include <stdair/bom/FareFamily.hpp>
00022 #include <stdair/bom/LegDate.hpp>
00023 #include <stdair/bom/LegCabin.hpp>
00024 #include <stdair/bom/Bucket.hpp>
00025 #include <stdair/factory/FacBomManager.hpp>
00026 #include <stdair/factory/FacBom.hpp>
00027 #include <stdair/command/CmdBomSerialiser.hpp>
00028 #include <stdair/service/Logger.hpp>
00029 
00030 namespace stdair {
00031 
00032   // ////////////////////////////////////////////////////////////////////
00033   template <class Archive, class BOM_OBJECT1, class BOM_OBJECT2>
00034   void serialiseHelper (BOM_OBJECT1& ioObject1, Archive& ioArchive,
00035                         const unsigned int iFileVersion) {
00036 
00050     BomHolder<BOM_OBJECT2>* lBomHolder_ptr =
00051       FacBomManager::getBomHolderPtr<BOM_OBJECT2> (ioObject1);
00052 
00053     if (lBomHolder_ptr == NULL) {
00054       lBomHolder_ptr = &FacBomManager::addBomHolder<BOM_OBJECT2> (ioObject1);
00055     }
00056     assert (lBomHolder_ptr != NULL);
00057 
00061     //ioArchive.register_type (static_cast<Inventory*> (NULL));
00062     ioArchive & lBomHolder_ptr->_bomList;
00063     ioArchive & lBomHolder_ptr->_bomMap;
00064 
00071     typedef typename BomHolder<BOM_OBJECT2>::BomList_T BomList_T;
00072     const BomList_T& lBomList = lBomHolder_ptr->_bomList;
00073     for (typename BomList_T::const_iterator itObject = lBomList.begin();
00074          itObject != lBomList.end(); ++itObject) {
00075       BOM_OBJECT2* lObject2_ptr = *itObject;
00076       assert (lObject2_ptr != NULL);
00077 
00078       if (lObject2_ptr->getParent() == NULL) {
00084         FacBomManager::linkWithParent (ioObject1, *lObject2_ptr);
00085       }
00086     }
00087 
00096     typedef typename BomHolder<BOM_OBJECT2>::BomMap_T BomMap_T;
00097     const BomMap_T& lBomMap = lBomHolder_ptr->_bomMap;
00098     if (lBomList.empty() == true && lBomMap.empty() == false) {
00099 
00100       for (typename BomMap_T::const_iterator itObject = lBomMap.begin();
00101            itObject != lBomMap.end(); ++itObject) {
00102         BOM_OBJECT2* lObject2_ptr = itObject->second;
00103         assert (lObject2_ptr != NULL);
00104 
00105         if (lObject2_ptr->getParent() == NULL) {
00111           FacBomManager::linkWithParent (ioObject1, *lObject2_ptr);
00112         }
00113       }
00114     }
00115   }
00116 
00117   // ////////////////////////////////////////////////////////////////////
00118   void BomRoot::serialisationImplementationExport() const {
00119     std::ostringstream oStr;
00120     boost::archive::text_oarchive oa (oStr);
00121     oa << *this;
00122   }
00123 
00124   // ////////////////////////////////////////////////////////////////////
00125   void BomRoot::serialisationImplementationImport() {
00126     std::istringstream iStr;
00127     boost::archive::text_iarchive ia (iStr);
00128     ia >> *this;
00129   }
00130 
00131   // ////////////////////////////////////////////////////////////////////
00132   template<class Archive>
00133   void BomRoot::serialize (Archive& ioArchive,
00134                            const unsigned int iFileVersion) {
00135     // Serialise the key (by default, equal to " -- ROOT -- ")
00136     ioArchive & _key;
00137 
00138     // Serialise the children of the BomRoot object, i.e., the
00139     // Inventory children
00140     stdair::serialiseHelper<Archive, BomRoot, Inventory> (*this, ioArchive,
00141                                                           iFileVersion);
00142   }
00143 
00144   // ////////////////////////////////////////////////////////////////////
00145   void Inventory::serialisationImplementationExport() const {
00146     std::ostringstream oStr;
00147     boost::archive::text_oarchive oa (oStr);
00148     oa << *this;
00149   }
00150 
00151   // ////////////////////////////////////////////////////////////////////
00152   void Inventory::serialisationImplementationImport() {
00153     std::istringstream iStr;
00154     boost::archive::text_iarchive ia (iStr);
00155     ia >> *this;
00156   }
00157 
00158   // ////////////////////////////////////////////////////////////////////
00159   template<class Archive>
00160   void Inventory::serialize (Archive& ioArchive,
00161                              const unsigned int iFileVersion) {
00162     // Serialise the key (airline code)
00163     ioArchive & _key;
00164 
00165     // Serialise the children of the Inventory object, i.e., the
00166     // FlightDate children
00167     stdair::serialiseHelper<Archive, Inventory, FlightDate> (*this, ioArchive,
00168                                                              iFileVersion);
00169   }
00170 
00171   // ////////////////////////////////////////////////////////////////////
00172   void FlightDate::serialisationImplementationExport() const {
00173     std::ostringstream oStr;
00174     boost::archive::text_oarchive oa (oStr);
00175     oa << *this;
00176   }
00177 
00178   // ////////////////////////////////////////////////////////////////////
00179   void FlightDate::serialisationImplementationImport() {
00180     std::istringstream iStr;
00181     boost::archive::text_iarchive ia (iStr);
00182     ia >> *this;
00183   }
00184 
00185   // ////////////////////////////////////////////////////////////////////
00186   template<class Archive>
00187   void FlightDate::serialize (Archive& ioArchive,
00188                              const unsigned int iFileVersion) {
00189     ioArchive & _key;
00190   }
00191 
00192   // ////////////////////////////////////////////////////////////////////
00193   void SegmentDate::serialisationImplementationExport() const {
00194     std::ostringstream oStr;
00195     boost::archive::text_oarchive oa (oStr);
00196     oa << *this;
00197   }
00198 
00199   // ////////////////////////////////////////////////////////////////////
00200   void SegmentDate::serialisationImplementationImport() {
00201     std::istringstream iStr;
00202     boost::archive::text_iarchive ia (iStr);
00203     ia >> *this;
00204   }
00205 
00206   // ////////////////////////////////////////////////////////////////////
00207   template<class Archive>
00208   void SegmentDate::serialize (Archive& ioArchive,
00209                              const unsigned int iFileVersion) {
00210     ioArchive & _key;
00211   }
00212 
00213   // ////////////////////////////////////////////////////////////////////
00214   void SegmentCabin::serialisationImplementationExport() const {
00215     std::ostringstream oStr;
00216     boost::archive::text_oarchive oa (oStr);
00217     oa << *this;
00218   }
00219 
00220   // ////////////////////////////////////////////////////////////////////
00221   void SegmentCabin::serialisationImplementationImport() {
00222     std::istringstream iStr;
00223     boost::archive::text_iarchive ia (iStr);
00224     ia >> *this;
00225   }
00226 
00227   // ////////////////////////////////////////////////////////////////////
00228   template<class Archive>
00229   void SegmentCabin::serialize (Archive& ioArchive,
00230                                 const unsigned int iFileVersion) {
00231     ioArchive & _key;
00232   }
00233 
00234   // ////////////////////////////////////////////////////////////////////
00235   // Explicit template instantiations
00236   namespace ba = boost::archive;
00237   template void BomRoot::serialize<ba::text_oarchive> (ba::text_oarchive&,
00238                                                        unsigned int);
00239   template void BomRoot::serialize<ba::text_iarchive> (ba::text_iarchive&,
00240                                                        unsigned int);
00241   template void Inventory::serialize<ba::text_oarchive> (ba::text_oarchive&,
00242                                                          unsigned int);
00243   template void Inventory::serialize<ba::text_iarchive> (ba::text_iarchive&,
00244                                                          unsigned int);
00245   template void FlightDate::serialize<ba::text_oarchive> (ba::text_oarchive&,
00246                                                           unsigned int);
00247   template void FlightDate::serialize<ba::text_iarchive> (ba::text_iarchive&,
00248                                                           unsigned int);
00249   template void SegmentDate::serialize<ba::text_oarchive> (ba::text_oarchive&,
00250                                                            unsigned int);
00251   template void SegmentDate::serialize<ba::text_iarchive> (ba::text_iarchive&,
00252                                                            unsigned int);
00253   template void SegmentCabin::serialize<ba::text_oarchive> (ba::text_oarchive&,
00254                                                             unsigned int);
00255   template void SegmentCabin::serialize<ba::text_iarchive> (ba::text_iarchive&,
00256                                                             unsigned int);
00257   // ////////////////////////////////////////////////////////////////////
00258 
00259 }