StdAir Logo  1.00.13
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
BomManager.hpp
Go to the documentation of this file.
1#ifndef __STDAIR_BOM_BOMMANAGER_HPP
2#define __STDAIR_BOM_BOMMANAGER_HPP
3
4// //////////////////////////////////////////////////////////////////////
5// Import section
6// //////////////////////////////////////////////////////////////////////
7// STL
8#include <iosfwd>
9#include <string>
10#include <list>
11#include <map>
12// Boost
13#include <boost/static_assert.hpp>
14#include <boost/type_traits/is_same.hpp>
15// StdAir
20// Stdair BOM Objects
24
25namespace stdair {
26
34 class BomManager {
35 friend class FacBomManager;
36
37 public:
41 template <typename OBJECT2, typename OBJECT1>
42 static const typename BomHolder<OBJECT2>::BomList_T& getList(const OBJECT1&);
43
47 template <typename OBJECT2, typename OBJECT1>
48 static const typename BomHolder<OBJECT2>::BomMap_T& getMap (const OBJECT1&);
49
53 template <typename OBJECT2, typename OBJECT1>
54 static bool hasList (const OBJECT1&);
55
59 template <typename OBJECT2, typename OBJECT1>
60 static bool hasMap (const OBJECT1&);
61
67 template <typename PARENT, typename CHILD>
68 static PARENT* getParentPtr (const CHILD&);
69
73 template <typename PARENT, typename CHILD>
74 static PARENT& getParent (const CHILD&);
75
81 template <typename OBJECT2, typename OBJECT1>
82 static OBJECT2* getObjectPtr (const OBJECT1&, const MapKey_T&);
83
87 template <typename OBJECT2, typename OBJECT1>
88 static OBJECT2& getObject (const OBJECT1&, const MapKey_T&);
89
90
91 private:
96 template <typename OBJECT2, typename OBJECT1>
97 static const BomHolder<OBJECT2>& getBomHolder (const OBJECT1&);
98 };
99
100 // ////////////////////////////////////////////////////////////////////
101 // Private method.
102 template <typename OBJECT2, typename OBJECT1>
103 const BomHolder<OBJECT2>& BomManager::getBomHolder (const OBJECT1& iObject1) {
104
105 //
106 // Compile time assertation: this function must never be called with the
107 // following list of couple types:
108 // <SegmentDate, SegmentDate>
109 // <AirlineFeature, Inventory>
110 //
111 BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
112 || boost::is_same<OBJECT2, SegmentDate>::value == false));
113 BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
114 || boost::is_same<OBJECT2, AirlineFeature>::value == false));
115
116 const HolderMap_T& lHolderMap = iObject1.getHolderMap();
117
118 HolderMap_T::const_iterator itHolder = lHolderMap.find (&typeid (OBJECT2));
119
120 if (itHolder == lHolderMap.end()) {
121 const std::string lName (typeid (OBJECT2).name());
122 throw NonInitialisedContainerException ("Cannot find the holder of type "
123 + lName + " within: "
124 + iObject1.describeKey());
125 }
126
127 const BomHolder<OBJECT2>* lBomHolder_ptr =
128 static_cast<const BomHolder<OBJECT2>*> (itHolder->second);
129 assert (lBomHolder_ptr != NULL);
130
131 return *lBomHolder_ptr;
132 }
133
134 // ////////////////////////////////////////////////////////////////////
135 // Public business method.
136 // This method is specialized for the following couple types:
137 // <SegmentDate, SegmentDate>
138 template <typename OBJECT2, typename OBJECT1>
140 getList (const OBJECT1& iObject1) {
141
142 //
143 // Compile time assertation: this function must never be called with the
144 // following list of couple types:
145 // <AirlineFeature, Inventory>
146 //
147 BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
148 || boost::is_same<OBJECT2, AirlineFeature>::value == false));
149
150 const BomHolder<OBJECT2>& lBomHolder = getBomHolder<OBJECT2> (iObject1);
151 return lBomHolder._bomList;
152 }
153
154 // ////////////////////////////////////////////////////////////////////
155 // Public business method.
156 // Compile time assertation to check OBJECT1 and OBJECT2 types.
157 template <typename OBJECT2, typename OBJECT1>
159 getMap (const OBJECT1& iObject1) {
160
161 //
162 // Compile time assertation: this function must never be called with the
163 // following list of couple types:
164 // <SegmentDate, SegmentDate>
165 // <AirlineFeature, Inventory>
166 //
167 BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
168 || boost::is_same<OBJECT2, SegmentDate>::value == false));
169 BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, Inventory>::value == false
170 || boost::is_same<OBJECT2, AirlineFeature>::value == false));
171
172 const BomHolder<OBJECT2>& lBomHolder = getBomHolder<OBJECT2> (iObject1);
173 return lBomHolder._bomMap;
174 }
175
176 // ////////////////////////////////////////////////////////////////////
177 // Public business method.
178 // This method is specialized for the following couple types:
179 // <SegmentDate, SegmentDate>
180 template <typename OBJECT2, typename OBJECT1>
181 bool BomManager::hasList (const OBJECT1& iObject1) {
182
183 const HolderMap_T& lHolderMap = iObject1.getHolderMap();
184 HolderMap_T::const_iterator itHolder = lHolderMap.find (&typeid (OBJECT2));
185
186 if (itHolder == lHolderMap.end()) {
187 return false;
188 }
189 const BomHolder<OBJECT2>* lBomHolder_ptr =
190 static_cast<const BomHolder<OBJECT2>*> (itHolder->second);
191 assert (lBomHolder_ptr != NULL);
192
193 return !lBomHolder_ptr->_bomList.empty();
194 }
195
196 // ////////////////////////////////////////////////////////////////////
197 // Public business method.
198 // This method is specialized for the following couple types:
199 // <SegmentDate, SegmentDate>
200 template <typename OBJECT2, typename OBJECT1>
201 bool BomManager::hasMap (const OBJECT1& iObject1) {
202
203 const HolderMap_T& lHolderMap = iObject1.getHolderMap();
204 HolderMap_T::const_iterator itHolder = lHolderMap.find (&typeid (OBJECT2));
205
206 if (itHolder == lHolderMap.end()) {
207 return false;
208 }
209 const BomHolder<OBJECT2>* lBomHolder_ptr =
210 static_cast<const BomHolder<OBJECT2>*> (itHolder->second);
211 assert (lBomHolder_ptr != NULL);
212
213 return !lBomHolder_ptr->_bomMap.empty();
214 }
215
216 // ////////////////////////////////////////////////////////////////////
217 // Public business method valid for all PARENT and CHILD types.
218 // (No compile time assertation to check PARENT and CHILD types.)
219 template <typename PARENT, typename CHILD>
220 PARENT* BomManager::getParentPtr (const CHILD& iChild) {
221
222 PARENT* const lParent_ptr = static_cast<PARENT* const> (iChild.getParent());
223 return lParent_ptr;
224 }
225
226 // ////////////////////////////////////////////////////////////////////
227 // Public business method valid for all PARENT and CHILD types.
228 // (No compile time assertation to check PARENT and CHILD types.)
229 template <typename PARENT, typename CHILD>
230 PARENT& BomManager::getParent (const CHILD& iChild) {
231
232 PARENT* const lParent_ptr = getParentPtr<PARENT> (iChild);
233 assert (lParent_ptr != NULL);
234 return *lParent_ptr;
235 }
236
237 // ////////////////////////////////////////////////////////////////////
238 // Public business method.
239 // Compile time assertation to check OBJECT1 and OBJECT2 types.
240 template <typename OBJECT2, typename OBJECT1>
241 OBJECT2* BomManager::getObjectPtr (const OBJECT1& iObject1,
242 const MapKey_T& iKey) {
243
244 //
245 // Compile time assertation: this function must never be called with the
246 // following list of couple types:
247 // <SegmentDate, SegmentDate>
248 //
249 BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
250 || boost::is_same<OBJECT2, SegmentDate>::value == false));
251
252 OBJECT2* oBom_ptr = NULL;
253
254 const HolderMap_T& lHolderMap = iObject1.getHolderMap();
255
256 typename HolderMap_T::const_iterator itHolder =
257 lHolderMap.find (&typeid (OBJECT2));
258
259 if (itHolder != lHolderMap.end()) {
260
261 BomHolder<OBJECT2>* const lBomHolder_ptr =
262 static_cast<BomHolder<OBJECT2>* const> (itHolder->second);
263 assert (lBomHolder_ptr != NULL);
264
265 //
266 typedef typename BomHolder<OBJECT2>::BomMap_T BomMap_T;
267 BomMap_T& lBomMap = lBomHolder_ptr->_bomMap;
268 typename BomMap_T::iterator itBom = lBomMap.find (iKey);
269
270 if (itBom != lBomMap.end()) {
271 oBom_ptr = itBom->second;
272 assert (oBom_ptr != NULL);
273 }
274 }
275
276 return oBom_ptr;
277 }
278
279 // ////////////////////////////////////////////////////////////////////
280 // Public business method.
281 // Compile time assertation to check OBJECT1 and OBJECT2 types.
282 template <typename OBJECT2, typename OBJECT1>
283 OBJECT2& BomManager::getObject (const OBJECT1& iObject1,
284 const MapKey_T& iKey) {
285
286 //
287 // Compile time assertation: this function must never be called with the
288 // following list of couple types:
289 // <SegmentDate, SegmentDate>
290 //
291 BOOST_STATIC_ASSERT ((boost::is_same<OBJECT1, SegmentDate>::value == false
292 || boost::is_same<OBJECT2, SegmentDate>::value == false));
293
294 OBJECT2* oBom_ptr = NULL;
295
296 typedef std::map<const MapKey_T, OBJECT2*> BomMap_T;
297 const BomMap_T& lBomMap = getMap<OBJECT2> (iObject1);
298
299 typename BomMap_T::const_iterator itBom = lBomMap.find (iKey);
300
301 if (itBom == lBomMap.end()) {
302 const std::string lName (typeid (OBJECT2).name());
303
304 STDAIR_LOG_ERROR ("Cannot find the objet of type " << lName
305 << " with key " << iKey << " within: "
306 << iObject1.describeKey());
307 assert (false);
308 }
309
310 oBom_ptr = itBom->second;
311 assert (oBom_ptr != NULL);
312
313 return *oBom_ptr;
314 }
315
316 // ////////////////////////////////////////////////////////////////////
317 //
318 // Specialization of the template methods above for a segment
319 // date and its corresponding marketing segment dates.
320 //
321 // ////////////////////////////////////////////////////////////////////
322
323 // Specialization of the template method hasList above for the types
324 // <SegmentDate, SegmentDate>.
325 // Return a boolean saying if the marketing segment date list is empty
326 // or not.
327 template<>
328 inline bool BomManager::hasList<SegmentDate,SegmentDate>
329 (const SegmentDate& ioSegmentDate) {
330
331 const SegmentDateList_T& lMarketingSegmentDateList =
332 ioSegmentDate.getMarketingSegmentDateList ();
333 const bool isMarketingSegmentDateListEmpty =
334 lMarketingSegmentDateList.empty();
335 const bool hasMarketingSegmentDateList =
336 !isMarketingSegmentDateListEmpty;
337 return hasMarketingSegmentDateList;
338 }
339
340 // Specialization of the template method hasList above for the types
341 // <SegmentDate, SegmentDate>.
342 // Return the marketing segment date list.
343 template<>
345 BomManager::getList<SegmentDate,SegmentDate> (const SegmentDate& ioSegmentDate) {
346
347 const SegmentDateList_T& lMarketingSegmentDateList =
348 ioSegmentDate.getMarketingSegmentDateList ();
349 return lMarketingSegmentDateList;
350 }
351
352 // Specialization of the template method hasMap above for the types
353 // <SegmentDate, SegmentDate>.
354 // A segment date does not have a Segment Date Map but it can have a
355 // Segment Date list (containing its marketing segment dates).
356 template<>
357 inline bool BomManager::hasMap<SegmentDate,SegmentDate>
358 (const SegmentDate& ioSegmentDate) {
359
360 const bool hasMap = false;
361 return hasMap;
362 }
363
364 // ////////////////////////////////////////////////////////////////////
365 //
366 // Specialization of the template methods above for an inventory
367 // and its airline features.
368 //
369 // ////////////////////////////////////////////////////////////////////
370
371 // Specialization of the template method hasList above for the types
372 // <AirlineFeature,Inventory>.
373 template<>
374 inline bool BomManager::hasList<AirlineFeature,Inventory>
375 (const Inventory& ioInventory) {
376
377 const bool hasList = false;
378 return hasList;
379 }
380
381 // Specialization of the template method hasMap above for the types
382 // <AirlineFeature,Inventory>.
383 template<>
384 inline bool BomManager::hasMap<AirlineFeature,Inventory>
385 (const Inventory& ioInventory) {
386
387 const bool hasMap = false;
388 return hasMap;
389 }
390
391 // Specialization of the template method getObjectPtr above for the types
392 // <AirlineFeature,Inventory>.
393 template<>
394 inline AirlineFeature* BomManager::getObjectPtr<AirlineFeature,Inventory>
395 (const Inventory& iInventory, const MapKey_T& iKey) {
396
397 AirlineFeature* lAirlineFeature_ptr = iInventory.getAirlineFeature ();
398
399 return lAirlineFeature_ptr;
400 }
401
402 // Specialization of the template method getObject above for the types
403 // <AirlineFeature,Inventory>.
404 template<>
405 inline AirlineFeature& BomManager::getObject<AirlineFeature,Inventory>
406 (const Inventory& iInventory, const MapKey_T& iKey) {
407
408 AirlineFeature* lAirlineFeature_ptr =
409 getObjectPtr<AirlineFeature,Inventory> (iInventory, iKey);
410 assert (lAirlineFeature_ptr != NULL);
411
412 return *lAirlineFeature_ptr;
413 }
414
415
416}
417#endif // __STDAIR_BOM_BOMMANAGER_HPP
#define STDAIR_LOG_ERROR(iToBeLogged)
Definition Logger.hpp:23
Handle on the StdAir library context.
std::list< SegmentDate * > SegmentDateList_T
std::string MapKey_T
Definition key_types.hpp:15
std::map< const std::type_info *, BomAbstract * > HolderMap_T
Class representing various configuration parameters (e.g., revenue management methods such EMSRb or M...
Class representing the holder of BOM object containers (list and map).
Definition BomHolder.hpp:24
std::map< const MapKey_T, BOM * > BomMap_T
Definition BomHolder.hpp:44
std::list< BOM * > BomList_T
Definition BomHolder.hpp:39
Utility class for StdAir-based objects.
static bool hasList(const OBJECT1 &)
static const BomHolder< OBJECT2 >::BomList_T & getList(const OBJECT1 &)
static OBJECT2 & getObject(const OBJECT1 &, const MapKey_T &)
static PARENT * getParentPtr(const CHILD &)
static bool hasMap(const OBJECT1 &)
static const BomHolder< OBJECT2 >::BomMap_T & getMap(const OBJECT1 &)
static PARENT & getParent(const CHILD &)
static OBJECT2 * getObjectPtr(const OBJECT1 &, const MapKey_T &)
Class representing the actual attributes for an airline inventory.
Definition Inventory.hpp:41
AirlineFeature * getAirlineFeature() const
Class representing the actual attributes for an airline segment-date.
const SegmentDateList_T & getMarketingSegmentDateList() const
Utility class for linking StdAir-based objects.