StdAir Logo  1.00.0
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SegmentSnapshotTable.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // Boost
8 #include <boost/multi_array.hpp>
9 // Boost.Serialization
10 #include <boost/archive/text_iarchive.hpp>
11 #include <boost/archive/text_oarchive.hpp>
12 #include <boost/serialization/access.hpp>
13 // StdAir
17 
18 namespace stdair {
19 
20  // ////////////////////////////////////////////////////////////////////
21  SegmentSnapshotTable::SegmentSnapshotTable()
22  : _key (DEFAULT_TABLE_ID), _parent (NULL) {
23  assert (false);
24  }
25 
26  // ////////////////////////////////////////////////////////////////////
27  SegmentSnapshotTable::SegmentSnapshotTable (const SegmentSnapshotTable&)
28  : _key (DEFAULT_TABLE_ID), _parent (NULL) {
29  assert (false);
30  }
31 
32  // ////////////////////////////////////////////////////////////////////
33  SegmentSnapshotTable::
34  SegmentSnapshotTable (const Key_T& iKey) : _key (iKey), _parent (NULL) {
35  }
36 
37  // ////////////////////////////////////////////////////////////////////
39  }
40 
41  // ////////////////////////////////////////////////////////////////////
42  std::string SegmentSnapshotTable::toString() const {
43  std::ostringstream oStr;
44  oStr << describeKey();
45  return oStr.str();
46  }
47 
48  // ////////////////////////////////////////////////////////////////////
50  initSnapshotBlocks (const SegmentCabinIndexMap_T& iSegmentCabinIndexMap,
51  const ClassIndexMap_T& iClassIndexMap) {
52  _segmentCabinIndexMap = iSegmentCabinIndexMap;
53  _classIndexMap = iClassIndexMap;
54 
55  unsigned int lNumberOfSegmentCabins = _segmentCabinIndexMap.size();
56  unsigned int lNumberOfClasses = _classIndexMap.size();
57 
58  // Initialise the snapshot blocks
59  // Normally, the block includes snapshots from DTD MAX to DTD 0, thus
60  // DEFAULT_MAX_DTD + 1 values. However, we would like to add the day
61  // before DTD MAX (this value will be initialised to zero).
63  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfClasses]
64  [DEFAULT_MAX_DTD + 2]);
66  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfClasses]
67  [DEFAULT_MAX_DTD + 2]);
69  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfClasses]
70  [DEFAULT_MAX_DTD + 2]);
72  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfClasses]
73  [DEFAULT_MAX_DTD + 2]);
75  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfClasses]
76  [DEFAULT_MAX_DTD + 2]);
78  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfClasses]
79  [DEFAULT_MAX_DTD + 2]);
81  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfClasses]
82  [DEFAULT_MAX_DTD + 2]);
83 
84  }
85 
86  // ////////////////////////////////////////////////////////////////////
88  getClassIndex (const MapKey_T& iKey) const {
89  ClassIndexMap_T::const_iterator itVTIdx =
90  _classIndexMap.find (iKey);
91  assert (itVTIdx != _classIndexMap.end());
92  return itVTIdx->second;
93  }
94 
95  // ////////////////////////////////////////////////////////////////////
97  getSegmentDataID (const SegmentCabin& iSegmentCabin) const {
98  SegmentCabinIndexMap_T::const_iterator itSCIdx =
99  _segmentCabinIndexMap.find (&iSegmentCabin);
100  assert (itSCIdx != _segmentCabinIndexMap.end());
101  return itSCIdx->second;
102  }
103 
104  // ////////////////////////////////////////////////////////////////////
107  const SegmentDataID_T iSCIdxEnd,
108  const DTD_T iDTD) const {
109  const unsigned int lNbOfClasses = _classIndexMap.size();
110  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
111  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
112 
113  return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
114  }
115 
116  // ////////////////////////////////////////////////////////////////////
119  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
120  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
121  const unsigned int lNbOfClasses = _classIndexMap.size();
122  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
123  const unsigned int lClassIdxEnd = (iSCIdxEnd +1) * lNbOfClasses;
124 
125  return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
126  }
127 
128  // ////////////////////////////////////////////////////////////////////
131  const SegmentDataID_T iSCIdxEnd,
132  const DTD_T iDTD) {
133  const unsigned int lNbOfClasses = _classIndexMap.size();
134  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
135  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
136 
137  return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
138  }
139 
140  // ////////////////////////////////////////////////////////////////////
143  const SegmentDataID_T iSCIdxEnd,
144  const DTD_T iDTDBegin,
145  const DTD_T iDTDEnd) {
146  const unsigned int lNbOfClasses = _classIndexMap.size();
147  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
148  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
149 
150  return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
151  }
152 
153  // ////////////////////////////////////////////////////////////////////
156  const SegmentDataID_T iSCIdxEnd,
157  const DTD_T iDTD) const {
158  const unsigned int lNbOfClasses = _classIndexMap.size();
159  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
160  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
161 
162  return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
163  }
164 
165  // ////////////////////////////////////////////////////////////////////
168  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
169  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
170  const unsigned int lNbOfClasses = _classIndexMap.size();
171  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
172  const unsigned int lClassIdxEnd = (iSCIdxEnd +1) * lNbOfClasses;
173 
174  return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
175  }
176 
177  // ////////////////////////////////////////////////////////////////////
180  const SegmentDataID_T iSCIdxEnd,
181  const DTD_T iDTD) {
182  const unsigned int lNbOfClasses = _classIndexMap.size();
183  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
184  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
185 
186  return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
187  }
188 
189  // ////////////////////////////////////////////////////////////////////
192  const SegmentDataID_T iSCIdxEnd,
193  const DTD_T iDTDBegin,
194  const DTD_T iDTDEnd) {
195  const unsigned int lNbOfClasses = _classIndexMap.size();
196  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
197  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
198 
199  return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
200  }
201 
202  // ////////////////////////////////////////////////////////////////////
205  const SegmentDataID_T iSCIdxEnd,
206  const DTD_T iDTD) const {
207  const unsigned int lNbOfClasses = _classIndexMap.size();
208  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
209  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
210 
211  return _productOrientedNetBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
212  }
213 
214  // ////////////////////////////////////////////////////////////////////
217  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
218  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
219  const unsigned int lNbOfClasses = _classIndexMap.size();
220  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
221  const unsigned int lClassIdxEnd = (iSCIdxEnd +1) * lNbOfClasses;
222 
223  return _productOrientedNetBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
224  }
225 
226  // ////////////////////////////////////////////////////////////////////
229  const SegmentDataID_T iSCIdxEnd,
230  const DTD_T iDTD) {
231  const unsigned int lNbOfClasses = _classIndexMap.size();
232  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
233  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
234 
235  return _productOrientedNetBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
236  }
237 
238  // ////////////////////////////////////////////////////////////////////
241  const SegmentDataID_T iSCIdxEnd,
242  const DTD_T iDTDBegin,
243  const DTD_T iDTDEnd) {
244  const unsigned int lNbOfClasses = _classIndexMap.size();
245  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
246  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
247 
248  return _productOrientedNetBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
249  }
250 
251 
252  // ////////////////////////////////////////////////////////////////////
255  const SegmentDataID_T iSCIdxEnd,
256  const DTD_T iDTD) const {
257  const unsigned int lNbOfClasses = _classIndexMap.size();
258  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
259  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
260 
261  return _priceOrientedNetBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
262  }
263 
264  // ////////////////////////////////////////////////////////////////////
267  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
268  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
269  const unsigned int lNbOfClasses = _classIndexMap.size();
270  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
271  const unsigned int lClassIdxEnd = (iSCIdxEnd +1) * lNbOfClasses;
272 
273  return _priceOrientedNetBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
274  }
275 
276  // ////////////////////////////////////////////////////////////////////
279  const SegmentDataID_T iSCIdxEnd,
280  const DTD_T iDTD) {
281  const unsigned int lNbOfClasses = _classIndexMap.size();
282  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
283  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
284 
285  return _priceOrientedNetBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
286  }
287 
288  // ////////////////////////////////////////////////////////////////////
291  const SegmentDataID_T iSCIdxEnd,
292  const DTD_T iDTDBegin,
293  const DTD_T iDTDEnd) {
294  const unsigned int lNbOfClasses = _classIndexMap.size();
295  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
296  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
297 
298  return _priceOrientedNetBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
299  }
300 
301  // ////////////////////////////////////////////////////////////////////
304  const SegmentDataID_T iSCIdxEnd,
305  const DTD_T iDTD) const {
306  const unsigned int lNbOfClasses = _classIndexMap.size();
307  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
308  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
309 
310  return _productOrientedGrossBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
311  }
312 
313  // ////////////////////////////////////////////////////////////////////
316  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
317  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
318  const unsigned int lNbOfClasses = _classIndexMap.size();
319  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
320  const unsigned int lClassIdxEnd = (iSCIdxEnd +1) * lNbOfClasses;
321 
322  return _productOrientedGrossBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
323  }
324 
325  // ////////////////////////////////////////////////////////////////////
328  const SegmentDataID_T iSCIdxEnd,
329  const DTD_T iDTD) {
330  const unsigned int lNbOfClasses = _classIndexMap.size();
331  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
332  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
333 
334  return _productOrientedGrossBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
335  }
336 
337  // ////////////////////////////////////////////////////////////////////
340  const SegmentDataID_T iSCIdxEnd,
341  const DTD_T iDTDBegin,
342  const DTD_T iDTDEnd) {
343  const unsigned int lNbOfClasses = _classIndexMap.size();
344  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
345  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
346 
347  return _productOrientedGrossBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
348  }
349 
350 
351  // ////////////////////////////////////////////////////////////////////
354  const SegmentDataID_T iSCIdxEnd,
355  const DTD_T iDTD) const {
356  const unsigned int lNbOfClasses = _classIndexMap.size();
357  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
358  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
359 
360  return _priceOrientedGrossBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
361  }
362 
363  // ////////////////////////////////////////////////////////////////////
366  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
367  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
368  const unsigned int lNbOfClasses = _classIndexMap.size();
369  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
370  const unsigned int lClassIdxEnd = (iSCIdxEnd +1) * lNbOfClasses;
371 
372  return _priceOrientedGrossBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
373  }
374 
375  // ////////////////////////////////////////////////////////////////////
378  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
379  const DTD_T iDTD) {
380  const unsigned int lNbOfClasses = _classIndexMap.size();
381  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
382  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
383 
384  return _priceOrientedGrossBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
385  }
386 
387  // ////////////////////////////////////////////////////////////////////
390  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
391  const DTD_T iDTDBegin, const DTD_T iDTDEnd) {
392  const unsigned int lNbOfClasses = _classIndexMap.size();
393  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
394  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
395 
396  return _priceOrientedGrossBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
397  }
398 
399  // ////////////////////////////////////////////////////////////////////
402  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
403  const DTD_T iDTD) const {
404  const unsigned int lNbOfClasses = _classIndexMap.size();
405  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
406  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
407 
408  return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
409  }
410 
411  // ////////////////////////////////////////////////////////////////////
414  (const SegmentDataID_T iSCIdxBegin, const SegmentDataID_T iSCIdxEnd,
415  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
416  const unsigned int lNbOfClasses = _classIndexMap.size();
417  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
418  const unsigned int lClassIdxEnd = (iSCIdxEnd +1) * lNbOfClasses;
419 
420  return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
421  }
422 
423  // ////////////////////////////////////////////////////////////////////
426  const SegmentDataID_T iSCIdxEnd,
427  const DTD_T iDTD) {
428  const unsigned int lNbOfClasses = _classIndexMap.size();
429  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
430  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
431 
432  return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][iDTD] ];
433  }
434 
435  // ////////////////////////////////////////////////////////////////////
438  const SegmentDataID_T iSCIdxEnd,
439  const DTD_T iDTDBegin,
440  const DTD_T iDTDEnd) {
441  const unsigned int lNbOfClasses = _classIndexMap.size();
442  const unsigned int lClassIdxBegin = iSCIdxBegin * lNbOfClasses;
443  const unsigned int lClassIdxEnd = (iSCIdxEnd + 1) * lNbOfClasses;
444 
445  return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lClassIdxBegin, lClassIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
446  }
447 
448  // ////////////////////////////////////////////////////////////////////
449  void SegmentSnapshotTable::serialisationImplementationExport() const {
450  std::ostringstream oStr;
451  boost::archive::text_oarchive oa (oStr);
452  oa << *this;
453  }
454 
455  // ////////////////////////////////////////////////////////////////////
456  void SegmentSnapshotTable::serialisationImplementationImport() {
457  std::istringstream iStr;
458  boost::archive::text_iarchive ia (iStr);
459  ia >> *this;
460  }
461 
462  // ////////////////////////////////////////////////////////////////////
463  template<class Archive>
464  void SegmentSnapshotTable::serialize (Archive& ioArchive,
465  const unsigned int iFileVersion) {
466  ioArchive & _key;
467  }
468 
469 }
470