StdAir Logo  0.43.0
C++ Standard Airline IT 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::serialisationImplementation() {
00119     std::ostringstream oStr;
00120     boost::archive::text_oarchive oa (oStr);
00121     oa << *this;
00122 
00123     std::istringstream iStr;
00124     boost::archive::text_iarchive ia (iStr);
00125     ia >> *this;
00126   }
00127 
00128   // ////////////////////////////////////////////////////////////////////
00129   template<class Archive>
00130   void BomRoot::serialize (Archive& ioArchive,
00131                            const unsigned int iFileVersion) {
00132     // Serialise the key (by default, equal to " -- ROOT -- ")
00133     ioArchive & _key;
00134 
00135     // Serialise the children of the BomRoot object, i.e., the
00136     // Inventory children
00137     stdair::serialiseHelper<Archive, BomRoot, Inventory> (*this, ioArchive,
00138                                                           iFileVersion);
00139   }
00140 
00141   // ////////////////////////////////////////////////////////////////////
00142   void Inventory::serialisationImplementation() {
00143     std::ostringstream oStr;
00144     boost::archive::text_oarchive oa (oStr);
00145     oa << *this;
00146 
00147     std::istringstream iStr;
00148     boost::archive::text_iarchive ia (iStr);
00149     ia >> *this;
00150   }
00151 
00152   // ////////////////////////////////////////////////////////////////////
00153   template<class Archive>
00154   void Inventory::serialize (Archive& ioArchive,
00155                              const unsigned int iFileVersion) {
00156     // Serialise the key (airline code)
00157     ioArchive & _key;
00158 
00159     // Serialise the children of the Inventory object, i.e., the
00160     // FlightDate children
00161     stdair::serialiseHelper<Archive, Inventory, FlightDate> (*this, ioArchive,
00162                                                              iFileVersion);
00163   }
00164 
00165   // ////////////////////////////////////////////////////////////////////
00166   void FlightDate::serialisationImplementation() {
00167     std::ostringstream oStr;
00168     boost::archive::text_oarchive oa (oStr);
00169     oa << *this;
00170 
00171     std::istringstream iStr;
00172     boost::archive::text_iarchive ia (iStr);
00173     ia >> *this;
00174   }
00175 
00176   // ////////////////////////////////////////////////////////////////////
00177   template<class Archive>
00178   void FlightDate::serialize (Archive& ioArchive,
00179                              const unsigned int iFileVersion) {
00180     ioArchive & _key;
00181   }
00182 
00183   // ////////////////////////////////////////////////////////////////////
00184   void SegmentDate::serialisationImplementation() {
00185     std::ostringstream oStr;
00186     boost::archive::text_oarchive oa (oStr);
00187     oa << *this;
00188 
00189     std::istringstream iStr;
00190     boost::archive::text_iarchive ia (iStr);
00191     ia >> *this;
00192   }
00193 
00194   // ////////////////////////////////////////////////////////////////////
00195   template<class Archive>
00196   void SegmentDate::serialize (Archive& ioArchive,
00197                              const unsigned int iFileVersion) {
00198     ioArchive & _key;
00199   }
00200 
00201   // ////////////////////////////////////////////////////////////////////
00202   void SegmentCabin::serialisationImplementation() {
00203     std::ostringstream oStr;
00204     boost::archive::text_oarchive oa (oStr);
00205     oa << *this;
00206 
00207     std::istringstream iStr;
00208     boost::archive::text_iarchive ia (iStr);
00209     ia >> *this;
00210   }
00211 
00212   // ////////////////////////////////////////////////////////////////////
00213   template<class Archive>
00214   void SegmentCabin::serialize (Archive& ioArchive,
00215                                 const unsigned int iFileVersion) {
00216     ioArchive & _key;
00217   }
00218 
00219   // ////////////////////////////////////////////////////////////////////
00220   // Explicit template instantiations
00221   namespace ba = boost::archive;
00222   template void BomRoot::serialize<ba::text_oarchive> (ba::text_oarchive&,
00223                                                        unsigned int);
00224   template void BomRoot::serialize<ba::text_iarchive> (ba::text_iarchive&,
00225                                                        unsigned int);
00226   template void Inventory::serialize<ba::text_oarchive> (ba::text_oarchive&,
00227                                                          unsigned int);
00228   template void Inventory::serialize<ba::text_iarchive> (ba::text_iarchive&,
00229                                                          unsigned int);
00230   template void FlightDate::serialize<ba::text_oarchive> (ba::text_oarchive&,
00231                                                           unsigned int);
00232   template void FlightDate::serialize<ba::text_iarchive> (ba::text_iarchive&,
00233                                                           unsigned int);
00234   template void SegmentDate::serialize<ba::text_oarchive> (ba::text_oarchive&,
00235                                                            unsigned int);
00236   template void SegmentDate::serialize<ba::text_iarchive> (ba::text_iarchive&,
00237                                                            unsigned int);
00238   template void SegmentCabin::serialize<ba::text_oarchive> (ba::text_oarchive&,
00239                                                             unsigned int);
00240   template void SegmentCabin::serialize<ba::text_iarchive> (ba::text_iarchive&,
00241                                                             unsigned int);
00242   // ////////////////////////////////////////////////////////////////////
00243 
00244 }