00001
00002
00003
00004
00005 #include <cassert>
00006 #include <sstream>
00007
00008 #include <boost/multi_array.hpp>
00009
00010 #include <boost/archive/text_iarchive.hpp>
00011 #include <boost/archive/text_oarchive.hpp>
00012 #include <boost/serialization/access.hpp>
00013
00014 #include <stdair/basic/BasConst_Inventory.hpp>
00015 #include <stdair/bom/BomManager.hpp>
00016 #include <stdair/bom/GuillotineBlock.hpp>
00017
00018 namespace stdair {
00019
00020
00021 GuillotineBlock::GuillotineBlock()
00022 : _key (DEFAULT_GUILLOTINE_NUMBER), _parent (NULL) {
00023 assert (false);
00024 }
00025
00026
00027 GuillotineBlock::GuillotineBlock (const GuillotineBlock&)
00028 : _key (DEFAULT_GUILLOTINE_NUMBER), _parent (NULL) {
00029 assert (false);
00030 }
00031
00032
00033 GuillotineBlock::
00034 GuillotineBlock (const Key_T& iKey) : _key (iKey), _parent (NULL) {
00035 }
00036
00037
00038 GuillotineBlock::~GuillotineBlock() {
00039 }
00040
00041
00042 std::string GuillotineBlock::toString() const {
00043 std::ostringstream oStr;
00044 oStr << describeKey();
00045 return oStr.str();
00046 }
00047
00048
00049 void GuillotineBlock::
00050 initSnapshotBlocks (const SegmentCabinIndexMap_T& iSegmentCabinIndexMap,
00051 const ValueTypeIndexMap_T& iValueTypeIndexMap) {
00052 _segmentCabinIndexMap = iSegmentCabinIndexMap;
00053 _valueTypesIndexMap = iValueTypeIndexMap;
00054
00055 unsigned int lNumberOfSegmentCabins = _segmentCabinIndexMap.size();
00056 unsigned int lNumberOfValueTypes = _valueTypesIndexMap.size();
00057
00058
00059
00060
00061
00062 _bookingSnapshotBlock.
00063 resize (boost::extents[lNumberOfSegmentCabins*lNumberOfValueTypes]
00064 [DEFAULT_MAX_DTD + 2]);
00065 _cancellationSnapshotBlock.
00066 resize (boost::extents[lNumberOfSegmentCabins*lNumberOfValueTypes]
00067 [DEFAULT_MAX_DTD + 2]);
00068 _productAndPriceOrientedBookingSnapshotBlock.
00069 resize (boost::extents[lNumberOfSegmentCabins*lNumberOfValueTypes]
00070 [DEFAULT_MAX_DTD + 2]);
00071 _availabilitySnapshotBlock.
00072 resize (boost::extents[lNumberOfSegmentCabins*lNumberOfValueTypes]
00073 [DEFAULT_MAX_DTD + 2]);
00074
00075 }
00076
00077
00078 const BlockIndex_T& GuillotineBlock::
00079 getBlockIndex (const MapKey_T& iKey) const {
00080 ValueTypeIndexMap_T::const_iterator itVTIdx =
00081 _valueTypesIndexMap.find (iKey);
00082 assert (itVTIdx != _valueTypesIndexMap.end());
00083 return itVTIdx->second;
00084 }
00085
00086
00087 const BlockNumber_T& GuillotineBlock::
00088 getBlockNumber (const SegmentCabin& iSegmentCabin) const {
00089 SegmentCabinIndexMap_T::const_iterator itSCIdx =
00090 _segmentCabinIndexMap.find (&iSegmentCabin);
00091 assert (itSCIdx != _segmentCabinIndexMap.end());
00092 return itSCIdx->second;
00093 }
00094
00095
00096 ConstSegmentCabinDTDSnapshotView_T GuillotineBlock::
00097 getConstSegmentCabinDTDBookingSnapshotView (const BlockNumber_T iSCIdxBegin,
00098 const BlockNumber_T iSCIdxEnd,
00099 const DTD_T iDTD) const {
00100 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00101 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00102 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00103
00104 return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
00105 }
00106
00107
00108 ConstSegmentCabinDTDRangeSnapshotView_T GuillotineBlock::
00109 getConstSegmentCabinDTDRangeBookingSnapshotView
00110 (const BlockNumber_T iSCIdxBegin, const BlockNumber_T iSCIdxEnd,
00111 const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
00112 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00113 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00114 const unsigned int lValueIdxEnd = (iSCIdxEnd +1) * lNbOfValueTypes;
00115
00116 return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
00117 }
00118
00119
00120 SegmentCabinDTDSnapshotView_T GuillotineBlock::
00121 getSegmentCabinDTDBookingSnapshotView (const BlockNumber_T iSCIdxBegin,
00122 const BlockNumber_T iSCIdxEnd,
00123 const DTD_T iDTD) {
00124 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00125 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00126 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00127
00128 return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
00129 }
00130
00131
00132 SegmentCabinDTDRangeSnapshotView_T GuillotineBlock::
00133 getSegmentCabinDTDRangeBookingSnapshotView (const BlockNumber_T iSCIdxBegin,
00134 const BlockNumber_T iSCIdxEnd,
00135 const DTD_T iDTDBegin,
00136 const DTD_T iDTDEnd) {
00137 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00138 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00139 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00140
00141 return _bookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
00142 }
00143
00144
00145 ConstSegmentCabinDTDSnapshotView_T GuillotineBlock::
00146 getConstSegmentCabinDTDCancellationSnapshotView (const BlockNumber_T iSCIdxBegin,
00147 const BlockNumber_T iSCIdxEnd,
00148 const DTD_T iDTD) const {
00149 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00150 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00151 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00152
00153 return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
00154 }
00155
00156
00157 ConstSegmentCabinDTDRangeSnapshotView_T GuillotineBlock::
00158 getConstSegmentCabinDTDRangeCancellationSnapshotView
00159 (const BlockNumber_T iSCIdxBegin, const BlockNumber_T iSCIdxEnd,
00160 const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
00161 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00162 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00163 const unsigned int lValueIdxEnd = (iSCIdxEnd +1) * lNbOfValueTypes;
00164
00165 return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
00166 }
00167
00168
00169 SegmentCabinDTDSnapshotView_T GuillotineBlock::
00170 getSegmentCabinDTDCancellationSnapshotView (const BlockNumber_T iSCIdxBegin,
00171 const BlockNumber_T iSCIdxEnd,
00172 const DTD_T iDTD) {
00173 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00174 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00175 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00176
00177 return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
00178 }
00179
00180
00181 SegmentCabinDTDRangeSnapshotView_T GuillotineBlock::
00182 getSegmentCabinDTDRangeCancellationSnapshotView(const BlockNumber_T iSCIdxBegin,
00183 const BlockNumber_T iSCIdxEnd,
00184 const DTD_T iDTDBegin,
00185 const DTD_T iDTDEnd) {
00186 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00187 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00188 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00189
00190 return _cancellationSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
00191 }
00192
00193
00194 ConstSegmentCabinDTDSnapshotView_T GuillotineBlock::
00195 getConstSegmentCabinDTDProductAndPriceOrientedBookingSnapshotView (const BlockNumber_T iSCIdxBegin,
00196 const BlockNumber_T iSCIdxEnd,
00197 const DTD_T iDTD) const {
00198 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00199 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00200 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00201
00202 return _productAndPriceOrientedBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
00203 }
00204
00205
00206 ConstSegmentCabinDTDRangeSnapshotView_T GuillotineBlock::
00207 getConstSegmentCabinDTDRangeProductAndPriceOrientedBookingSnapshotView
00208 (const BlockNumber_T iSCIdxBegin, const BlockNumber_T iSCIdxEnd,
00209 const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
00210 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00211 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00212 const unsigned int lValueIdxEnd = (iSCIdxEnd +1) * lNbOfValueTypes;
00213
00214 return _productAndPriceOrientedBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
00215 }
00216
00217
00218 SegmentCabinDTDSnapshotView_T GuillotineBlock::
00219 getSegmentCabinDTDProductAndPriceOrientedBookingSnapshotView (const BlockNumber_T iSCIdxBegin,
00220 const BlockNumber_T iSCIdxEnd,
00221 const DTD_T iDTD) {
00222 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00223 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00224 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00225
00226 return _productAndPriceOrientedBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
00227 }
00228
00229
00230 SegmentCabinDTDRangeSnapshotView_T GuillotineBlock::
00231 getSegmentCabinDTDRangeProductAndPriceOrientedBookingSnapshotView (const BlockNumber_T iSCIdxBegin,
00232 const BlockNumber_T iSCIdxEnd,
00233 const DTD_T iDTDBegin,
00234 const DTD_T iDTDEnd) {
00235 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00236 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00237 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00238
00239 return _productAndPriceOrientedBookingSnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
00240 }
00241
00242
00243 ConstSegmentCabinDTDSnapshotView_T GuillotineBlock::
00244 getConstSegmentCabinDTDAvailabilitySnapshotView (const BlockNumber_T iSCIdxBegin,
00245 const BlockNumber_T iSCIdxEnd,
00246 const DTD_T iDTD) const {
00247 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00248 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00249 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00250
00251 return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
00252 }
00253
00254
00255 ConstSegmentCabinDTDRangeSnapshotView_T GuillotineBlock::
00256 getConstSegmentCabinDTDRangeAvailabilitySnapshotView
00257 (const BlockNumber_T iSCIdxBegin, const BlockNumber_T iSCIdxEnd,
00258 const DTD_T iDTDBegin, const DTD_T iDTDEnd) const {
00259 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00260 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00261 const unsigned int lValueIdxEnd = (iSCIdxEnd +1) * lNbOfValueTypes;
00262
00263 return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
00264 }
00265
00266
00267 SegmentCabinDTDSnapshotView_T GuillotineBlock::
00268 getSegmentCabinDTDAvailabilitySnapshotView (const BlockNumber_T iSCIdxBegin,
00269 const BlockNumber_T iSCIdxEnd,
00270 const DTD_T iDTD) {
00271 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00272 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00273 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00274
00275 return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][iDTD] ];
00276 }
00277
00278
00279 SegmentCabinDTDRangeSnapshotView_T GuillotineBlock::
00280 getSegmentCabinDTDRangeAvailabilitySnapshotView(const BlockNumber_T iSCIdxBegin,
00281 const BlockNumber_T iSCIdxEnd,
00282 const DTD_T iDTDBegin,
00283 const DTD_T iDTDEnd) {
00284 const unsigned int lNbOfValueTypes = _valueTypesIndexMap.size();
00285 const unsigned int lValueIdxBegin = iSCIdxBegin * lNbOfValueTypes;
00286 const unsigned int lValueIdxEnd = (iSCIdxEnd + 1) * lNbOfValueTypes;
00287
00288 return _availabilitySnapshotBlock [ boost::indices[SnapshotBlockRange_T(lValueIdxBegin, lValueIdxEnd)][SnapshotBlockRange_T(iDTDBegin, iDTDEnd + 1)] ];
00289 }
00290
00291
00292 void GuillotineBlock::serialisationImplementationExport() const {
00293 std::ostringstream oStr;
00294 boost::archive::text_oarchive oa (oStr);
00295 oa << *this;
00296 }
00297
00298
00299 void GuillotineBlock::serialisationImplementationImport() {
00300 std::istringstream iStr;
00301 boost::archive::text_iarchive ia (iStr);
00302 ia >> *this;
00303 }
00304
00305
00306 template<class Archive>
00307 void GuillotineBlock::serialize (Archive& ioArchive,
00308 const unsigned int iFileVersion) {
00309 ioArchive & _key;
00310 }
00311
00312 }
00313