AirRAC Logo  1.00.0
C++ Simulated Revenue Accounting (RAC) System Library
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
YieldRuleGenerator.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // StdAir
7 #include <stdair/bom/BomManager.hpp>
8 #include <stdair/bom/BomRoot.hpp>
9 #include <stdair/bom/AirportPair.hpp>
10 #include <stdair/bom/PosChannel.hpp>
11 #include <stdair/bom/DatePeriod.hpp>
12 #include <stdair/bom/TimePeriod.hpp>
13 #include <stdair/bom/YieldFeatures.hpp>
14 #include <stdair/bom/AirlineClassList.hpp>
15 #include <stdair/factory/FacBomManager.hpp>
16 #include <stdair/service/Logger.hpp>
17 // AirRAC
20 
21 namespace AIRRAC {
22 
23  // //////////////////////////////////////////////////////////////////////
24  void YieldRuleGenerator::
25  createAirportPair (stdair::BomRoot& ioBomRoot,
26  const YieldRuleStruct& iYieldRuleStruct) {
27 
28  // Set the airport-pair primary key.
29  const stdair::AirportCode_T& lBoardPoint = iYieldRuleStruct.getOrigin ();
30  const stdair::AirportCode_T& lOffPoint = iYieldRuleStruct.getDestination ();
31  const stdair::AirportPairKey lAirportPairKey (lBoardPoint, lOffPoint);
32 
33  // Check that the airport-pair object is not already existing. If an
34  // airport-pair object with the same key has not already been created,
35  // create it and link it to the ioBomRoot object.
36  stdair::AirportPair* lAirportPair_ptr = stdair::BomManager::
37  getObjectPtr<stdair::AirportPair> (ioBomRoot, lAirportPairKey.toString());
38  if (lAirportPair_ptr == NULL) {
39  lAirportPair_ptr = &stdair::FacBom<stdair::AirportPair>::
40  instance().create (lAirportPairKey);
41  stdair::FacBomManager::addToListAndMap (ioBomRoot, *lAirportPair_ptr);
42  stdair::FacBomManager::linkWithParent (ioBomRoot, *lAirportPair_ptr);
43  }
44  // Sanity check.
45  assert (lAirportPair_ptr != NULL);
46 
47  stdair::AirportPair& lAirportPair = *lAirportPair_ptr;
48  // Generate the date-period object corresponding to the given
49  // yieldRule.
50  createDateRange (lAirportPair, iYieldRuleStruct);
51 
52  }
53 
54 
55  // //////////////////////////////////////////////////////////////////////
56  void YieldRuleGenerator::
57  createDateRange (stdair::AirportPair& iAirportPair,
58  const YieldRuleStruct& iYieldRuleStruct) {
59 
60  // Create the yield date-period primary key.
61  const stdair::Date_T& lDateRangeStart =
62  iYieldRuleStruct.getDateRangeStart ();
63  const stdair::Date_T& lDateRangeEnd =
64  iYieldRuleStruct.getDateRangeEnd ();
65  const stdair::DatePeriod_T lDatePeriod (lDateRangeStart, lDateRangeEnd);
66  const stdair::DatePeriodKey lYieldDatePeriodKey (lDatePeriod);
67 
68  // Check that the date-period object is not already existing.
69  // If a date-period object with the same key has not already been
70  // created, create it and link it to the airport-pair object.
71  stdair::DatePeriod* lYieldDatePeriod_ptr = stdair::BomManager::
72  getObjectPtr<stdair::DatePeriod> (iAirportPair,
73  lYieldDatePeriodKey.toString());
74  if (lYieldDatePeriod_ptr == NULL) {
75  lYieldDatePeriod_ptr = &stdair::FacBom<stdair::DatePeriod>::
76  instance().create (lYieldDatePeriodKey);
77  stdair::FacBomManager::
78  addToListAndMap (iAirportPair, *lYieldDatePeriod_ptr);
79  stdair::FacBomManager::
80  linkWithParent (iAirportPair, *lYieldDatePeriod_ptr);
81  }
82  // Sanity check.
83  assert (lYieldDatePeriod_ptr != NULL);
84 
85  stdair::DatePeriod& lDateRange = *lYieldDatePeriod_ptr;
86  // Generate the point_of_sale-channel object corresponding to
87  // the given yieldRule.
88  createPOSChannel (lDateRange, iYieldRuleStruct);
89 
90  }
91 
92  // //////////////////////////////////////////////////////////////////////
93  void YieldRuleGenerator::
94  createPOSChannel (stdair::DatePeriod& iDatePeriod,
95  const YieldRuleStruct& iYieldRuleStruct) {
96 
97  // Create the point-of-sale-channel primary key.
98  const stdair::CityCode_T& lPoS = iYieldRuleStruct.getPOS ();
99  const stdair::ChannelLabel_T& lChannel = iYieldRuleStruct.getChannel ();
100  const stdair::PosChannelKey lYieldPosChannelKey (lPoS, lChannel);
101 
102  // Check that the point_of_sale-channel object is not already existing.
103  // If a point_of_sale-channel object with the same key has not already
104  // been created, create it and link it to the date-period object.
105  stdair::PosChannel* lYieldPosChannel_ptr = stdair::BomManager::
106  getObjectPtr<stdair::PosChannel> (iDatePeriod,
107  lYieldPosChannelKey.toString());
108  if (lYieldPosChannel_ptr == NULL) {
109  lYieldPosChannel_ptr = &stdair::FacBom<stdair::PosChannel>::
110  instance().create (lYieldPosChannelKey);
111  stdair::FacBomManager::
112  addToListAndMap (iDatePeriod, *lYieldPosChannel_ptr);
113  stdair::FacBomManager::
114  linkWithParent (iDatePeriod, *lYieldPosChannel_ptr);
115  }
116  // Sanity check.
117  assert (lYieldPosChannel_ptr != NULL);
118 
119  stdair::PosChannel& lPosChannel = *lYieldPosChannel_ptr;
120  // Generate the time-period object corresponding to the given
121  // yieldRule.
122  createTimeRange (lPosChannel, iYieldRuleStruct);
123 
124  }
125 
126  // //////////////////////////////////////////////////////////////////////
127  void YieldRuleGenerator::
128  createTimeRange (stdair::PosChannel& iPosChannel,
129  const YieldRuleStruct& iYieldRuleStruct) {
130 
131  // Create the yield time-period primary key.
132  const stdair::Time_T& lTimeRangeStart
133  = iYieldRuleStruct.getTimeRangeStart ();
134  const stdair::Time_T& lTimeRangeEnd
135  = iYieldRuleStruct.getTimeRangeEnd ();
136  const stdair::TimePeriodKey lYieldTimePeriodKey (lTimeRangeStart,
137  lTimeRangeEnd);
138 
139  // Check that the time-period object is not already existing.
140  // If a time-period object with the same key has not already been
141  // created, create it and link it to the point_of_sale-channel object.
142  stdair::TimePeriod* lYieldTimePeriod_ptr = stdair::BomManager::
143  getObjectPtr<stdair::TimePeriod> (iPosChannel,
144  lYieldTimePeriodKey.toString());
145  if (lYieldTimePeriod_ptr == NULL) {
146  lYieldTimePeriod_ptr = &stdair::FacBom<stdair::TimePeriod>::
147  instance().create (lYieldTimePeriodKey);
148  stdair::FacBomManager::
149  addToListAndMap (iPosChannel, *lYieldTimePeriod_ptr);
150  stdair::FacBomManager::
151  linkWithParent (iPosChannel, *lYieldTimePeriod_ptr);
152  }
153  // Sanity check.
154  assert (lYieldTimePeriod_ptr != NULL);
155 
156  stdair::TimePeriod& lTimeRange = *lYieldTimePeriod_ptr;
157  // Generate the yield-features object corresponding to the given
158  // yieldRule.
159  createYieldFeatures (lTimeRange, iYieldRuleStruct);
160 
161  }
162 
163  // //////////////////////////////////////////////////////////////////////
164  void YieldRuleGenerator::
165  createYieldFeatures (stdair::TimePeriod& iTimePeriod,
166  const YieldRuleStruct& iYieldRuleStruct) {
167 
168  // Create the yield-features primary key.
169  const stdair::TripType_T& lTripType = iYieldRuleStruct.getTripType ();
170  stdair::CabinCode_T lCabinCode = iYieldRuleStruct.getCabinCode ();
171  const stdair::YieldFeaturesKey lYieldFeaturesKey (lTripType, lCabinCode);
172 
173  // Check that the yield features object is not already existing.
174  // If a yield features object with the same key has not already been
175  // created, create it and link it to the time-period object.
176  stdair::YieldFeatures* lYieldFeatures_ptr = stdair::BomManager::
177  getObjectPtr<stdair::YieldFeatures > (iTimePeriod,
178  lYieldFeaturesKey.toString());
179  if (lYieldFeatures_ptr == NULL) {
180  lYieldFeatures_ptr = &stdair::FacBom<stdair::YieldFeatures>::
181  instance().create (lYieldFeaturesKey);
182  stdair::FacBomManager::
183  addToListAndMap (iTimePeriod, *lYieldFeatures_ptr);
184  stdair::FacBomManager::
185  linkWithParent (iTimePeriod, *lYieldFeatures_ptr);
186  }
187  // Sanity check.
188  assert (lYieldFeatures_ptr != NULL);
189 
190  stdair::YieldFeatures& lYieldFeatures = *lYieldFeatures_ptr;
191  // Generate the airline-class list object corresponding to the
192  // given yieldRule
193  createAirlineClassList (lYieldFeatures, iYieldRuleStruct);
194 
195  }
196 
197  // //////////////////////////////////////////////////////////////////////
198  void YieldRuleGenerator::
199  createAirlineClassList (stdair::YieldFeatures& iYieldFeatures,
200  const YieldRuleStruct& iYieldRuleStruct) {
201 
202  // Create the AirlineClassList primary key.
203  const unsigned int lAirlineListSize =
204  iYieldRuleStruct.getAirlineListSize();
205  const unsigned int lClassCodeListSize =
206  iYieldRuleStruct.getClassCodeListSize();
207  assert (lAirlineListSize == lClassCodeListSize);
208  const stdair::AirlineClassListKey
209  lAirlineClassListKey (iYieldRuleStruct.getAirlineList() ,
210  iYieldRuleStruct.getClassCodeList());
211  const stdair::Yield_T& lYield = iYieldRuleStruct.getYield ();
212 
213  // Create the airline class list object and link it to the yieldures
214  // object.
215  stdair::AirlineClassList* lAirlineClassList_ptr =
216  &stdair::FacBom<stdair::AirlineClassList>::instance().
217  create(lAirlineClassListKey);
218  lAirlineClassList_ptr->setYield (lYield);
219  stdair::FacBomManager::addToListAndMap (iYieldFeatures,
220  *lAirlineClassList_ptr);
221  stdair::FacBomManager::linkWithParent (iYieldFeatures,
222  *lAirlineClassList_ptr);
223  }
224 
225 }
226