StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GuillotineBlock.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  GuillotineBlock::GuillotineBlock()
22  : _key (DEFAULT_GUILLOTINE_NUMBER), _parent (NULL) {
23  assert (false);
24  }
25 
26  // ////////////////////////////////////////////////////////////////////
27  GuillotineBlock::GuillotineBlock (const GuillotineBlock&)
28  : _key (DEFAULT_GUILLOTINE_NUMBER), _parent (NULL) {
29  assert (false);
30  }
31 
32  // ////////////////////////////////////////////////////////////////////
33  GuillotineBlock::
34  GuillotineBlock (const Key_T& iKey) : _key (iKey), _parent (NULL) {
35  }
36 
37  // ////////////////////////////////////////////////////////////////////
39  }
40 
41  // ////////////////////////////////////////////////////////////////////
42  std::string GuillotineBlock::toString() const {
43  std::ostringstream oStr;
44  oStr << describeKey();
45  return oStr.str();
46  }
47 
48  // ////////////////////////////////////////////////////////////////////
50  initSnapshotBlocks (const SegmentCabinIndexMap_T& iSegmentCabinIndexMap,
51  const ValueTypeIndexMap_T& iValueTypeIndexMap) {
52  _segmentCabinIndexMap = iSegmentCabinIndexMap;
53  _valueTypesIndexMap = iValueTypeIndexMap;
54 
55  unsigned int lNumberOfSegmentCabins = _segmentCabinIndexMap.size();
56  unsigned int lNumberOfValueTypes = _valueTypesIndexMap.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*lNumberOfValueTypes]
64  [DEFAULT_MAX_DTD + 2]);
66  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfValueTypes]
67  [DEFAULT_MAX_DTD + 2]);
69  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfValueTypes]
70  [DEFAULT_MAX_DTD + 2]);
72  resize (boost::extents[lNumberOfSegmentCabins*lNumberOfValueTypes]
73  [DEFAULT_MAX_DTD + 2]);
74 
75  }
76 
77  // ////////////////////////////////////////////////////////////////////
79  getBlockIndex (const MapKey_T& iKey) const {
80  ValueTypeIndexMap_T::const_iterator itVTIdx =
81  _valueTypesIndexMap.find (iKey);
82  assert (itVTIdx != _valueTypesIndexMap.end());
83  return itVTIdx->second;
84  }
85 
86  // ////////////////////////////////////////////////////////////////////
88  getBlockNumber (const SegmentCabin& iSegmentCabin) const {
89  SegmentCabinIndexMap_T::const_iterator itSCIdx =
90  _segmentCabinIndexMap.find (&iSegmentCabin);
91  assert (itSCIdx != _segmentCabinIndexMap.end());
92  return itSCIdx->second;
93  }
94 
95  // ////////////////////////////////////////////////////////////////////
98  const BlockNumber_T iSCIdxEnd,
99  const DTD_T iDTD) const {
100  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
101  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
102  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
103 
104  return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
105  }
106 
107  // ////////////////////////////////////////////////////////////////////
110  (const BlockNumber_T iSCIdxBegin, const BlockNumber_T iSCIdxEnd,
111  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
112  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
113  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
114  const unsigned int lValueIdxEnd = (iSCIdxEnd +1) * lNbOfValueTypes;
115 
116  return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
117  }
118 
119  // ////////////////////////////////////////////////////////////////////
122  const BlockNumber_T iSCIdxEnd,
123  const DTD_T iDTD) {
124  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
125  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
126  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
127 
128  return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
129  }
130 
131  // ////////////////////////////////////////////////////////////////////
134  const BlockNumber_T iSCIdxEnd,
135  const DTD_T iDTDBegin,
136  const DTD_T iDTDEnd) {
137  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
138  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
139  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
140 
141  return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
142  }
143 
144  // ////////////////////////////////////////////////////////////////////
147  const BlockNumber_T iSCIdxEnd,
148  const DTD_T iDTD) const {
149  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
150  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
151  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
152 
153  return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
154  }
155 
156  // ////////////////////////////////////////////////////////////////////
159  (const BlockNumber_T iSCIdxBegin, const BlockNumber_T iSCIdxEnd,
160  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
161  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
162  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
163  const unsigned int lValueIdxEnd = (iSCIdxEnd +1) * lNbOfValueTypes;
164 
165  return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
166  }
167 
168  // ////////////////////////////////////////////////////////////////////
171  const BlockNumber_T iSCIdxEnd,
172  const DTD_T iDTD) {
173  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
174  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
175  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
176 
177  return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
178  }
179 
180  // ////////////////////////////////////////////////////////////////////
183  const BlockNumber_T iSCIdxEnd,
184  const DTD_T iDTDBegin,
185  const DTD_T iDTDEnd) {
186  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
187  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
188  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
189 
190  return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
191  }
192 
193  // ////////////////////////////////////////////////////////////////////
196  const BlockNumber_T iSCIdxEnd,
197  const DTD_T iDTD) const {
198  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
199  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
200  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
201 
202  return _productAndPriceOrientedBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
203  }
204 
205  // ////////////////////////////////////////////////////////////////////
208  (const BlockNumber_T iSCIdxBegin, const BlockNumber_T iSCIdxEnd,
209  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
210  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
211  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
212  const unsigned int lValueIdxEnd = (iSCIdxEnd +1) * lNbOfValueTypes;
213 
214  return _productAndPriceOrientedBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
215  }
216 
217  // ////////////////////////////////////////////////////////////////////
220  const BlockNumber_T iSCIdxEnd,
221  const DTD_T iDTD) {
222  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
223  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
224  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
225 
226  return _productAndPriceOrientedBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
227  }
228 
229  // ////////////////////////////////////////////////////////////////////
232  const BlockNumber_T iSCIdxEnd,
233  const DTD_T iDTDBegin,
234  const DTD_T iDTDEnd) {
235  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
236  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
237  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
238 
239  return _productAndPriceOrientedBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
240  }
241 
242  // ////////////////////////////////////////////////////////////////////
245  const BlockNumber_T iSCIdxEnd,
246  const DTD_T iDTD) const {
247  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
248  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
249  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
250 
251  return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
252  }
253 
254  // ////////////////////////////////////////////////////////////////////
257  (const BlockNumber_T iSCIdxBegin, const BlockNumber_T iSCIdxEnd,
258  const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
259  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
260  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
261  const unsigned int lValueIdxEnd = (iSCIdxEnd +1) * lNbOfValueTypes;
262 
263  return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
264  }
265 
266  // ////////////////////////////////////////////////////////////////////
269  const BlockNumber_T iSCIdxEnd,
270  const DTD_T iDTD) {
271  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
272  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
273  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
274 
275  return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
276  }
277 
278  // ////////////////////////////////////////////////////////////////////
281  const BlockNumber_T iSCIdxEnd,
282  const DTD_T iDTDBegin,
283  const DTD_T iDTDEnd) {
284  const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
285  const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
286  const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
287 
288  return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
289  }
290 
291  // ////////////////////////////////////////////////////////////////////
292  void GuillotineBlock::serialisationImplementationExport() const {
293  std::ostringstream oStr;
294  boost::archive::text_oarchive oa (oStr);
295  oa << *this;
296  }
297 
298  // ////////////////////////////////////////////////////////////////////
299  void GuillotineBlock::serialisationImplementationImport() {
300  std::istringstream iStr;
301  boost::archive::text_iarchive ia (iStr);
302  ia >> *this;
303  }
304 
305  // ////////////////////////////////////////////////////////////////////
306  template<class Archive>
307  void GuillotineBlock::serialize (Archive& ioArchive,
308  const unsigned int iFileVersion) {
309  ioArchive & _key;
310  }
311 
312 }
313