StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
CmdBomSerialiser.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // Boost.Serialization
8 #include <boost/archive/text_iarchive.hpp>
9 #include <boost/archive/text_oarchive.hpp>
10 #include <boost/serialization/list.hpp>
11 #include <boost/serialization/map.hpp>
12 #include <boost/serialization/access.hpp>
13 // StdAir
16 #include <stdair/bom/BomRoot.hpp>
17 #include <stdair/bom/Inventory.hpp>
22 #include <stdair/bom/LegDate.hpp>
23 #include <stdair/bom/LegCabin.hpp>
24 #include <stdair/bom/Bucket.hpp>
29 
30 namespace stdair {
31 
32  // ////////////////////////////////////////////////////////////////////
33  template <class Archive, class BOM_OBJECT1, class BOM_OBJECT2>
34  void serialiseHelper (BOM_OBJECT1& ioObject1, Archive& ioArchive,
35  const unsigned int iFileVersion) {
36 
50  BomHolder<BOM_OBJECT2>* lBomHolder_ptr =
51  FacBomManager::getBomHolderPtr<BOM_OBJECT2> (ioObject1);
52 
53  if (lBomHolder_ptr == NULL) {
54  lBomHolder_ptr = &FacBomManager::addBomHolder<BOM_OBJECT2> (ioObject1);
55  }
56  assert (lBomHolder_ptr != NULL);
57 
61  //ioArchive.register_type (static_cast<Inventory*> (NULL));
62  ioArchive & lBomHolder_ptr->_bomList;
63  ioArchive & lBomHolder_ptr->_bomMap;
64 
71  typedef typename BomHolder<BOM_OBJECT2>::BomList_T BomList_T;
72  const BomList_T& lBomList = lBomHolder_ptr->_bomList;
73  for (typename BomList_T::const_iterator itObject = lBomList.begin();
74  itObject != lBomList.end(); ++itObject) {
75  BOM_OBJECT2* lObject2_ptr = *itObject;
76  assert (lObject2_ptr != NULL);
77 
78  if (lObject2_ptr->getParent() == NULL) {
84  FacBomManager::linkWithParent (ioObject1, *lObject2_ptr);
85  }
86  }
87 
96  typedef typename BomHolder<BOM_OBJECT2>::BomMap_T BomMap_T;
97  const BomMap_T& lBomMap = lBomHolder_ptr->_bomMap;
98  if (lBomList.empty() == true && lBomMap.empty() == false) {
99 
100  for (typename BomMap_T::const_iterator itObject = lBomMap.begin();
101  itObject != lBomMap.end(); ++itObject) {
102  BOM_OBJECT2* lObject2_ptr = itObject->second;
103  assert (lObject2_ptr != NULL);
104 
105  if (lObject2_ptr->getParent() == NULL) {
111  FacBomManager::linkWithParent (ioObject1, *lObject2_ptr);
112  }
113  }
114  }
115  }
116 
117  // ////////////////////////////////////////////////////////////////////
118  void BomRoot::serialisationImplementationExport() const {
119  std::ostringstream oStr;
120  boost::archive::text_oarchive oa (oStr);
121  oa << *this;
122  }
123 
124  // ////////////////////////////////////////////////////////////////////
125  void BomRoot::serialisationImplementationImport() {
126  std::istringstream iStr;
127  boost::archive::text_iarchive ia (iStr);
128  ia >> *this;
129  }
130 
131  // ////////////////////////////////////////////////////////////////////
132  template<class Archive>
133  void BomRoot::serialize (Archive& ioArchive,
134  const unsigned int iFileVersion) {
135  // Serialise the key (by default, equal to " -- ROOT -- ")
136  ioArchive & _key;
137 
138  // Serialise the children of the BomRoot object, i.e., the
139  // Inventory children
140  stdair::serialiseHelper<Archive, BomRoot, Inventory> (*this, ioArchive,
141  iFileVersion);
142  }
143 
144  // ////////////////////////////////////////////////////////////////////
145  void Inventory::serialisationImplementationExport() const {
146  std::ostringstream oStr;
147  boost::archive::text_oarchive oa (oStr);
148  oa << *this;
149  }
150 
151  // ////////////////////////////////////////////////////////////////////
152  void Inventory::serialisationImplementationImport() {
153  std::istringstream iStr;
154  boost::archive::text_iarchive ia (iStr);
155  ia >> *this;
156  }
157 
158  // ////////////////////////////////////////////////////////////////////
159  template<class Archive>
160  void Inventory::serialize (Archive& ioArchive,
161  const unsigned int iFileVersion) {
162  // Serialise the key (airline code)
163  ioArchive & _key;
164 
165  // Serialise the children of the Inventory object, i.e., the
166  // FlightDate children
167  stdair::serialiseHelper<Archive, Inventory, FlightDate> (*this, ioArchive,
168  iFileVersion);
169  }
170 
171  // ////////////////////////////////////////////////////////////////////
172  void FlightDate::serialisationImplementationExport() const {
173  std::ostringstream oStr;
174  boost::archive::text_oarchive oa (oStr);
175  oa << *this;
176  }
177 
178  // ////////////////////////////////////////////////////////////////////
179  void FlightDate::serialisationImplementationImport() {
180  std::istringstream iStr;
181  boost::archive::text_iarchive ia (iStr);
182  ia >> *this;
183  }
184 
185  // ////////////////////////////////////////////////////////////////////
186  template<class Archive>
187  void FlightDate::serialize (Archive& ioArchive,
188  const unsigned int iFileVersion) {
189  ioArchive & _key;
190  }
191 
192  // ////////////////////////////////////////////////////////////////////
193  void SegmentDate::serialisationImplementationExport() const {
194  std::ostringstream oStr;
195  boost::archive::text_oarchive oa (oStr);
196  oa << *this;
197  }
198 
199  // ////////////////////////////////////////////////////////////////////
200  void SegmentDate::serialisationImplementationImport() {
201  std::istringstream iStr;
202  boost::archive::text_iarchive ia (iStr);
203  ia >> *this;
204  }
205 
206  // ////////////////////////////////////////////////////////////////////
207  template<class Archive>
208  void SegmentDate::serialize (Archive& ioArchive,
209  const unsigned int iFileVersion) {
210  ioArchive & _key;
211  }
212 
213  // ////////////////////////////////////////////////////////////////////
214  void SegmentCabin::serialisationImplementationExport() const {
215  std::ostringstream oStr;
216  boost::archive::text_oarchive oa (oStr);
217  oa << *this;
218  }
219 
220  // ////////////////////////////////////////////////////////////////////
221  void SegmentCabin::serialisationImplementationImport() {
222  std::istringstream iStr;
223  boost::archive::text_iarchive ia (iStr);
224  ia >> *this;
225  }
226 
227  // ////////////////////////////////////////////////////////////////////
228  template<class Archive>
229  void SegmentCabin::serialize (Archive& ioArchive,
230  const unsigned int iFileVersion) {
231  ioArchive & _key;
232  }
233 
234  // ////////////////////////////////////////////////////////////////////
235  // Explicit template instantiations
236  namespace ba = boost::archive;
237  template void BomRoot::serialize<ba::text_oarchive> (ba::text_oarchive&,
238  unsigned int);
239  template void BomRoot::serialize<ba::text_iarchive> (ba::text_iarchive&,
240  unsigned int);
241  template void Inventory::serialize<ba::text_oarchive> (ba::text_oarchive&,
242  unsigned int);
243  template void Inventory::serialize<ba::text_iarchive> (ba::text_iarchive&,
244  unsigned int);
245  template void FlightDate::serialize<ba::text_oarchive> (ba::text_oarchive&,
246  unsigned int);
247  template void FlightDate::serialize<ba::text_iarchive> (ba::text_iarchive&,
248  unsigned int);
249  template void SegmentDate::serialize<ba::text_oarchive> (ba::text_oarchive&,
250  unsigned int);
251  template void SegmentDate::serialize<ba::text_iarchive> (ba::text_iarchive&,
252  unsigned int);
253  template void SegmentCabin::serialize<ba::text_oarchive> (ba::text_oarchive&,
254  unsigned int);
255  template void SegmentCabin::serialize<ba::text_iarchive> (ba::text_iarchive&,
256  unsigned int);
257  // ////////////////////////////////////////////////////////////////////
258 
259 }
static void linkWithParent(PARENT &, CHILD &)
void serialize(Archive &ar, const unsigned int iFileVersion)
Handle on the StdAir library context.
std::map< const MapKey_T, BOM * > BomMap_T
Definition: BomHolder.hpp:44
std::list< BOM * > BomList_T
Definition: BomHolder.hpp:39
void serialize(Archive &ar, const unsigned int iFileVersion)
BomList_T _bomList
Definition: BomHolder.hpp:111
void serialize(Archive &ar, const unsigned int iFileVersion)
void serialiseHelper(BOM_OBJECT1 &ioObject1, Archive &ioArchive, const unsigned int iFileVersion)
void serialize(Archive &ar, const unsigned int iFileVersion)
Class representing the holder of BOM object containers (list and map).
Definition: BomHolder.hpp:24
void serialize(Archive &ar, const unsigned int iFileVersion)