StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
FacBomManager.hpp
Go to the documentation of this file.
1 #ifndef __STDAIR_FAC_FACBOMMANAGER_HPP
2 #define __STDAIR_FAC_FACBOMMANAGER_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <iosfwd>
9 #include <list>
10 #include <map>
11 // Boost
12 #include <boost/static_assert.hpp>
13 #include <boost/type_traits/is_same.hpp>
14 // StdAir
15 #include <stdair/bom/BomHolder.hpp>
19 // Stdair BOM Objects
21 
22 
23 namespace stdair {
24  // Forward declarations.
25  class SegmentCabin;
26 
30  class FacBomManager : public FacAbstract {
31  public:
32  // ///////////// Business methods. ////////////
41  template <typename OBJECT2, typename OBJECT1>
42  static BomHolder<OBJECT2>* getBomHolderPtr (OBJECT1&);
43 
53  template <typename OBJECT2, typename OBJECT1>
54  static BomHolder<OBJECT2>& addBomHolder (OBJECT1&);
55 
67  template <typename OBJECT1, typename OBJECT2>
68  static void addToList (OBJECT1&, OBJECT2&);
69 
82  template <typename OBJECT1, typename OBJECT2>
83  static void addToMap (OBJECT1&, OBJECT2&, const MapKey_T&);
84 
96  template <typename OBJECT1, typename OBJECT2>
97  static void addToMap (OBJECT1&, OBJECT2&);
98 
110  template <typename OBJECT1, typename OBJECT2>
111  static void addToListAndMap (OBJECT1&, OBJECT2&);
112 
125  template <typename OBJECT1, typename OBJECT2>
126  static void addToListAndMap (OBJECT1&, OBJECT2&, const MapKey_T&);
127 
134  template <typename PARENT, typename CHILD>
135  static void linkWithParent (PARENT&, CHILD&);
136 
147  template <typename OBJECT2, typename OBJECT1>
148  static void cloneHolder (OBJECT1&, const OBJECT1&);
149 
150 
151  private:
164  template <typename OBJECT1, typename OBJECT2>
165  static void addToList (BomHolder<OBJECT2>&, OBJECT1&, OBJECT2&);
166 
180  template <typename OBJECT1, typename OBJECT2>
181  static void addToMap (BomHolder<OBJECT2>&, OBJECT1&, OBJECT2&,
182  const MapKey_T&);
183 
192  template <typename OBJECT2, typename OBJECT1>
193  static BomHolder<OBJECT2>& getBomHolder (OBJECT1&);
194 
195  public:
200  static void resetYieldBasedNestingStructure (const SegmentCabin&);
201 
205  static void setAirlineFeature (Inventory& iInventory,
206  AirlineFeature& iAirlineFeature) {
207  iInventory.setAirlineFeature (iAirlineFeature);
208  }
209 
213  static void linkWithOperating (SegmentDate& iSegmentDate,
214  SegmentDate& iOperatingSegmentDate) {
215  iSegmentDate.linkWithOperating (iOperatingSegmentDate);
216  }
217 
218 
219  protected:
226 
227  public:
232  };
233 
234  // ////////////////////////////////////////////////////////////////////
235  // Public business method.
236  // Compile time assertation to check OBJECT1 and OBJECT2 types.
237  template <typename OBJECT2, typename OBJECT1>
239 
240  //
241  // Compile time assertation: this function must never be called with the
242  // following list of couple types:
243  // <SegmentDate, SegmentDate>
244  // <AirlineFeature, Inventory>
245  //
246  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
247  || boost::is_same<OBJECT2, SegmentDate>::value == false));
248  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
249  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
250 
251 
252  BomHolder<OBJECT2>* lBomHolder_ptr =
253  &FacBom<BomHolder<OBJECT2> >::instance().create();
254 
255  const bool hasInsertBeenSuccessful =
256  ioObject1._holderMap.insert (typename HolderMap_T::
257  value_type (&typeid (OBJECT2),
258  lBomHolder_ptr)).second;
259  assert (hasInsertBeenSuccessful == true);
260 
261  return *lBomHolder_ptr;
262  }
263 
264  // ////////////////////////////////////////////////////////////////////
265  // Public business method.
266  // Compile time assertation to check OBJECT1 and OBJECT2 types.
267  template <typename OBJECT2, typename OBJECT1>
269 
270  //
271  // Compile time assertation: this function must never be called with the
272  // following list of couple types:
273  // <SegmentDate, SegmentDate>
274  // <AirlineFeature, Inventory>
275  //
276  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
277  || boost::is_same<OBJECT2, SegmentDate>::value == false));
278  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
279  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
280 
281  BomHolder<OBJECT2>* lBomHolder_ptr = NULL;
282 
283  // Find the corresponding BomHolder within the object1, if existing.
284  HolderMap_T::const_iterator itHolder =
285  ioObject1._holderMap.find (&typeid (OBJECT2));
286 
287  if (itHolder != ioObject1._holderMap.end()) {
288  lBomHolder_ptr = static_cast<BomHolder<OBJECT2>*> (itHolder->second);
289  }
290 
291  return lBomHolder_ptr;
292  }
293 
294  // ////////////////////////////////////////////////////////////////////
295  // Private method.
296  template <typename OBJECT2, typename OBJECT1>
297  BomHolder<OBJECT2>& FacBomManager::getBomHolder (OBJECT1& ioObject1) {
298 
299  //
300  // Compile time assertation: this function must never be called with the
301  // following list of couple types:
302  // <SegmentDate, SegmentDate>
303  // <AirlineFeature, Inventory>
304  //
305  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
306  || boost::is_same<OBJECT2, SegmentDate>::value == false));
307  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
308  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
309 
310  BomHolder<OBJECT2>* lBomHolder_ptr = NULL;
311 
312  // Find the corresponding BomHolder within the object1. If it does
313  // not exist, then create one.
314  HolderMap_T::const_iterator itHolder =
315  ioObject1._holderMap.find (&typeid (OBJECT2));
316 
317  if (itHolder == ioObject1._holderMap.end()) {
318  lBomHolder_ptr = &addBomHolder<OBJECT2, OBJECT1> (ioObject1);
319 
320  } else {
321  lBomHolder_ptr = static_cast<BomHolder<OBJECT2>*> (itHolder->second);
322  }
323 
324  assert (lBomHolder_ptr != NULL);
325 
326  return *lBomHolder_ptr;
327  }
328 
329  // ////////////////////////////////////////////////////////////////////
330  // Private method.
331  template <typename OBJECT1, typename OBJECT2>
332  void FacBomManager::addToList (BomHolder<OBJECT2>& ioBomHolder,
333  OBJECT1& ioObject1, OBJECT2& ioObject2) {
334 
335  //
336  // Compile time assertation: this function must never be called with the
337  // following list of couple types:
338  // <SegmentDate, SegmentDate>
339  // <AirlineFeature, Inventory>
340  //
341  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
342  || boost::is_same<OBJECT2, SegmentDate>::value == false));
343  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
344  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
345 
346  ioBomHolder._bomList.push_back (&ioObject2);
347  }
348 
349  // ////////////////////////////////////////////////////////////////////
350  // Public business method.
351  // This method is specialized for the following couple types:
352  // <SegmentDate, SegmentDate>
353  template <typename OBJECT1, typename OBJECT2>
354  void FacBomManager::addToList (OBJECT1& ioObject1, OBJECT2& ioObject2) {
355 
356  //
357  // Compile time assertation: this function must never be called with the
358  // following list of couple types:
359  // <SegmentDate, SegmentDate>
360  // <AirlineFeature, Inventory>
361  //
362  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
363  || boost::is_same<OBJECT2, SegmentDate>::value == false));
364  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
365  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
366 
367  BomHolder<OBJECT2>& lBomHolder = getBomHolder<OBJECT2> (ioObject1);
368 
369  addToList<OBJECT1, OBJECT2> (lBomHolder, ioObject1, ioObject2);
370  }
371 
372  // ////////////////////////////////////////////////////////////////////
373  // Private method.
374  template <typename OBJECT1, typename OBJECT2>
375  void FacBomManager::addToMap (BomHolder<OBJECT2>& ioBomHolder,
376  OBJECT1& ioObject1, OBJECT2& ioObject2,
377  const MapKey_T& iKey) {
378 
379  //
380  // Compile time assertation: this function must never be called with the
381  // following list of couple types:
382  // <SegmentDate, SegmentDate>
383  // <AirlineFeature, Inventory>
384  //
385  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
386  || boost::is_same<OBJECT2, SegmentDate>::value == false));
387  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
388  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
389 
390  const bool insertionSucceeded =
391  ioBomHolder._bomMap.insert (typename std::map<const MapKey_T, OBJECT2*>::
392  value_type (iKey, &ioObject2)).second;
393 
394  if (insertionSucceeded == false) {
395  // Build a nice message, so that the error be fully explicit
396  std::ostringstream oStr;
397  oStr << "The given object ('" << iKey
398  << "') can not be added to the map of '" << ioObject1.describeKey()
399  << "' object. That map already contains: '";
400 
401  unsigned int idx = 0;
402  for (typename std::map<const MapKey_T, OBJECT2*>::const_iterator iter =
403  ioBomHolder._bomMap.begin();
404  iter != ioBomHolder._bomMap.end(); ++iter, ++idx) {
405  const OBJECT2* lCurrentObject_ptr = iter->second;
406  assert (lCurrentObject_ptr != NULL);
407 
408  if (idx != 0) {
409  oStr << "; ";
410  }
411  oStr << lCurrentObject_ptr->describeKey();
412  }
413  oStr << "'";
414 
415  STDAIR_LOG_ERROR (oStr.str());
416  throw ObjectLinkingException (oStr.str());
417  }
418  }
419 
420  // ////////////////////////////////////////////////////////////////////
421  // Public business method.
422  // Compile time assertation to check OBJECT1 and OBJECT2 types.
423  template <typename OBJECT1, typename OBJECT2> void FacBomManager::
424  addToMap (OBJECT1& ioObject1, OBJECT2& ioObject2, const MapKey_T& iKey) {
425 
426  //
427  // Compile time assertation: this function must never be called with the
428  // following list of couple types:
429  // <SegmentDate, SegmentDate>
430  // <AirlineFeature, Inventory>
431  //
432  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
433  || boost::is_same<OBJECT2, SegmentDate>::value == false));
434  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
435  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
436 
437  BomHolder<OBJECT2>& lBomHolder = getBomHolder<OBJECT2> (ioObject1);
438 
439  addToMap<OBJECT1, OBJECT2> (lBomHolder, ioObject1, ioObject2, iKey);
440  }
441 
442  // Public business method.
443  // Compile time assertation to check OBJECT1 and OBJECT2 types.
444  // ////////////////////////////////////////////////////////////////////
445  template <typename OBJECT1, typename OBJECT2>
446  void FacBomManager::addToMap (OBJECT1& ioObject1, OBJECT2& ioObject2) {
447 
448  //
449  // Compile time assertation: this function must never be called with the
450  // following list of couple types:
451  // <SegmentDate, SegmentDate>
452  // <AirlineFeature, Inventory>
453  //
454  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
455  || boost::is_same<OBJECT2, SegmentDate>::value == false));
456  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
457  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
458 
459  const MapKey_T& lKey = ioObject2.describeKey();
460  addToMap (ioObject1, ioObject2, lKey);
461  }
462 
463  // ////////////////////////////////////////////////////////////////////
464  // Public business method.
465  // Compile time assertation to check OBJECT1 and OBJECT2 types.
466  template <typename OBJECT1, typename OBJECT2>
467  void FacBomManager::addToListAndMap (OBJECT1& ioObject1, OBJECT2& ioObject2,
468  const MapKey_T& iKey) {
469  //
470  // Compile time assertation: this function must never be called with the
471  // following list of couple types:
472  // <SegmentDate, SegmentDate>
473  // <AirlineFeature, Inventory>
474  //
475  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
476  || boost::is_same<OBJECT2, SegmentDate>::value == false));
477  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
478  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
479 
480  BomHolder<OBJECT2>& lBomHolder = getBomHolder<OBJECT2> (ioObject1);
481 
482  addToList<OBJECT1, OBJECT2> (lBomHolder, ioObject1, ioObject2);
483  addToMap<OBJECT1, OBJECT2> (lBomHolder, ioObject1, ioObject2, iKey);
484  }
485 
486  // ////////////////////////////////////////////////////////////////////
487  // Public business method.
488  // Compile time assertation to check OBJECT1 and OBJECT2 types.
489  template <typename OBJECT1, typename OBJECT2> void FacBomManager::
490  addToListAndMap (OBJECT1& ioObject1, OBJECT2& ioObject2) {
491 
492  //
493  // Compile time assertation: this function must never be called with the
494  // following list of couple types:
495  // <SegmentDate, SegmentDate>
496  // <AirlineFeature, Inventory>
497  //
498  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
499  || boost::is_same<OBJECT2, SegmentDate>::value == false));
500  BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
501  || boost::is_same<OBJECT2, AirlineFeature>::value == false));
502 
503  const MapKey_T& lKey = ioObject2.describeKey();
504  addToListAndMap<OBJECT1, OBJECT2> (ioObject1, ioObject2, lKey);
505  }
506 
507  // Public business method valid for all PARENT and CHILD types.
508  // (No compile time assertation to check PARENT and CHILD types.)
509  // ////////////////////////////////////////////////////////////////////
510  template <typename PARENT, typename CHILD> void FacBomManager::
511  linkWithParent (PARENT& ioParent, CHILD& ioChild) {
512  ioChild._parent = &ioParent;
513  }
514 
515  // ////////////////////////////////////////////////////////////////////
516  // Public business method valid for all PARENT and CHILD types.
517  // (No compile time assertation to check PARENT and CHILD types.)
518  template <typename OBJECT2, typename OBJECT1> void FacBomManager::
519  cloneHolder (OBJECT1& ioDest, const OBJECT1& iOri) {
520 
521  const BomHolder<OBJECT2>& lOriginHolder =
522  BomManager::getBomHolder<OBJECT2> (iOri);
523 
524  BomHolder<OBJECT2>& lDestHolder = getBomHolder<OBJECT2> (ioDest);
525  lDestHolder._bomList = lOriginHolder._bomList;
526  lDestHolder._bomMap = lOriginHolder._bomMap;
527  }
528 
529  // ////////////////////////////////////////////////////////////////////
530  //
531  // Specialization of the template method addToList above for the types
532  // <SegmentDate, SegmentDate>.
533  // Add an element to the marketing segment date list of a segment date.
534  //
535  // ////////////////////////////////////////////////////////////////////
536 
537  template<>
538  inline void FacBomManager::addToList <SegmentDate,SegmentDate>
539  (SegmentDate& ioSegmentDate,
540  SegmentDate& ioMarketingSegmentDate) {
541 
542  ioSegmentDate._marketingSegmentDateList.push_back(&ioMarketingSegmentDate);
543  }
544 
545  // ////////////////////////////////////////////////////////////////////
546  //
547  // TODO:
548  // This specialization is needed for all the objects in the current
549  // BOM tree.
550  // (An inventory is the parent of flight dates, a flight date is the
551  // parent of segment dates and leg dates, ...)
552  //
553  // ////////////////////////////////////////////////////////////////////
554 
555 
556 }
557 
558 // ////////////////////////////////////////////////////////////////////
559 
560 #endif // __STDAIR_FAC_FACBOMMANAGER_HPP
static void linkWithParent(PARENT &, CHILD &)
#define STDAIR_LOG_ERROR(iToBeLogged)
Definition: Logger.hpp:23
Utility class for linking StdAir-based objects.
static void addToMap(OBJECT1 &, OBJECT2 &, const MapKey_T &)
Class representing the actual attributes for an airline segment-date.
Definition: SegmentDate.hpp:36
Handle on the StdAir library context.
std::map< const std::type_info *, BomAbstract * > HolderMap_T
Definition: BomAbstract.hpp:63
static void addToListAndMap(OBJECT1 &, OBJECT2 &)
static BomHolder< OBJECT2 > * getBomHolderPtr(OBJECT1 &)
std::string MapKey_T
Definition: key_types.hpp:15
BomList_T _bomList
Definition: BomHolder.hpp:111
Base class for Factory layer.
Definition: FacBom.hpp:22
static void setAirlineFeature(Inventory &iInventory, AirlineFeature &iAirlineFeature)
static void linkWithOperating(SegmentDate &iSegmentDate, SegmentDate &iOperatingSegmentDate)
static void cloneHolder(OBJECT1 &, const OBJECT1 &)
Class representing the actual attributes for an airline inventory.
Definition: Inventory.hpp:34
static void addToList(OBJECT1 &, OBJECT2 &)
Class representing the actual attributes for an airline segment-cabin.
SegmentDateList_T _marketingSegmentDateList
static BomHolder< OBJECT2 > & addBomHolder(OBJECT1 &)
BOM & create()
Definition: FacBom.hpp:112
Class representing the holder of BOM object containers (list and map).
Definition: BomHolder.hpp:24
Class representing various configuration parameters (e.g., revenue management methods such EMSRb or M...
static void resetYieldBasedNestingStructure(const SegmentCabin &)