SimFQT Logo  1.00.8
C++ Simulated Fare Quote System Library
Loading...
Searching...
No Matches
FareRuleGenerator.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/factory/FacBomManager.hpp>
10#include <stdair/service/Logger.hpp>
11#include <stdair/bom/AirportPair.hpp>
12#include <stdair/bom/PosChannel.hpp>
13#include <stdair/bom/DatePeriod.hpp>
14#include <stdair/bom/TimePeriod.hpp>
15#include <stdair/bom/FareFeatures.hpp>
16#include <stdair/bom/AirlineClassList.hpp>
17// SimFQT
20
21namespace SIMFQT {
22
23 // //////////////////////////////////////////////////////////////////////
24 void FareRuleGenerator::
25 createAirportPair (stdair::BomRoot& ioBomRoot,
26 const FareRuleStruct& iFareRuleStruct) {
27
28 // Create the airport-pair primary key.
29 const stdair::AirportCode_T& lBoardPoint = iFareRuleStruct.getOrigin ();
30 const stdair::AirportCode_T& lOffPoint =
31 iFareRuleStruct.getDestination ();
32 const stdair::AirportPairKey lAirportPairKey (lBoardPoint, lOffPoint);
33
34 // Check that the airport-pair object is not already existing. If an
35 // airport-pair object with the same key has not already been created,
36 // create it and link it to the ioBomRoot object.
37 stdair::AirportPair* lAirportPair_ptr = stdair::BomManager::
38 getObjectPtr<stdair::AirportPair> (ioBomRoot, lAirportPairKey.toString());
39 if (lAirportPair_ptr == NULL) {
40 lAirportPair_ptr =
41 &stdair::FacBom<stdair::AirportPair>::instance().
42 create (lAirportPairKey);
43 stdair::FacBomManager::addToListAndMap (ioBomRoot, *lAirportPair_ptr);
44 stdair::FacBomManager::linkWithParent (ioBomRoot, *lAirportPair_ptr);
45 }
46 // Sanity check.
47 assert (lAirportPair_ptr != NULL);
48
49 stdair::AirportPair& lAirportPair = *lAirportPair_ptr;
50 // Generate the date-period object corresponding to the given
51 // fareRule.
52 createDateRange (lAirportPair, iFareRuleStruct);
53
54 }
55
56 // //////////////////////////////////////////////////////////////////////
57 void FareRuleGenerator::
58 createDateRange (stdair::AirportPair& iAirportPair,
59 const FareRuleStruct& iFareRuleStruct) {
60
61 // Create the fare date-period primary key.
62 const stdair::Date_T& lDateRangeStart =
63 iFareRuleStruct.getDateRangeStart ();
64 const stdair::Date_T& lDateRangeEnd =
65 iFareRuleStruct.getDateRangeEnd ();
66 const stdair::DatePeriod_T lDatePeriod (lDateRangeStart, lDateRangeEnd);
67 const stdair::DatePeriodKey lFareDatePeriodKey (lDatePeriod);
68
69 // Check that the date-period object is not already existing.
70 // If a date-period object with the same key has not already been
71 // created, create it and link it to the airport-pair object.
72 stdair::DatePeriod* lFareDatePeriod_ptr = stdair::BomManager::
73 getObjectPtr<stdair::DatePeriod> (iAirportPair,
74 lFareDatePeriodKey.toString());
75 if (lFareDatePeriod_ptr == NULL) {
76 lFareDatePeriod_ptr = &stdair::FacBom<stdair::DatePeriod>::instance().
77 create (lFareDatePeriodKey);
78 stdair::FacBomManager::addToListAndMap (iAirportPair,
79 *lFareDatePeriod_ptr);
80 stdair::FacBomManager::linkWithParent (iAirportPair,
81 *lFareDatePeriod_ptr);
82 }
83 // Sanity check.
84 assert (lFareDatePeriod_ptr != NULL);
85
86 stdair::DatePeriod& lDateRange = *lFareDatePeriod_ptr;
87 // Generate the point_of_sale-channel object corresponding to
88 // the given fareRule.
89 createPOSChannel (lDateRange, iFareRuleStruct);
90
91 }
92
93 // //////////////////////////////////////////////////////////////////////
94 void FareRuleGenerator::
95 createPOSChannel (stdair::DatePeriod& iDatePeriod,
96 const FareRuleStruct& iFareRuleStruct) {
97
98 // Create the point-of-sale-channel primary key.
99 const stdair::CityCode_T& lPosition = iFareRuleStruct.getPOS ();
100 const stdair::ChannelLabel_T& lChannel =
101 iFareRuleStruct.getChannel ();
102 const stdair::PosChannelKey lFarePosChannelKey (lPosition, lChannel);
103
104 // Check that the point_of_sale-channel object is not already existing.
105 // If a point_of_sale-channel object with the same key has not already
106 // been created, create it and link it to the date-period object.
107 stdair::PosChannel* lFarePosChannel_ptr = stdair::BomManager::
108 getObjectPtr<stdair::PosChannel> (iDatePeriod,
109 lFarePosChannelKey.toString());
110 if (lFarePosChannel_ptr == NULL) {
111 lFarePosChannel_ptr = &stdair::FacBom<stdair::PosChannel>::instance().
112 create (lFarePosChannelKey);
113 stdair::FacBomManager::addToListAndMap (iDatePeriod,
114 *lFarePosChannel_ptr);
115 stdair::FacBomManager::linkWithParent (iDatePeriod,
116 *lFarePosChannel_ptr);
117 }
118 // Sanity check.
119 assert (lFarePosChannel_ptr != NULL);
120
121 stdair::PosChannel& lPosChannel = *lFarePosChannel_ptr;
122 // Generate the time-period object corresponding to the given
123 // fareRule.
124 createTimeRange (lPosChannel, iFareRuleStruct);
125
126 }
127
128
129 // //////////////////////////////////////////////////////////////////////
130 void FareRuleGenerator::
131 createTimeRange (stdair::PosChannel& iPosChannel,
132 const FareRuleStruct& iFareRuleStruct) {
133
134 // Create the fare time-period primary key.
135 const stdair::Time_T& lTimeRangeStart =
136 iFareRuleStruct.getTimeRangeStart ();
137 const stdair::Time_T& lTimeRangeEnd =
138 iFareRuleStruct.getTimeRangeEnd ();
139 const stdair::TimePeriodKey lFareTimePeriodKey (lTimeRangeStart,
140 lTimeRangeEnd);
141
142 // Check that the time-period object is not already existing.
143 // If a time-period object with the same key has not already been
144 // created, create it and link it to the point_of_sale-channel object.
145 stdair::TimePeriod* lFareTimePeriod_ptr = stdair::BomManager::
146 getObjectPtr<stdair::TimePeriod> (iPosChannel,
147 lFareTimePeriodKey.toString());
148 if (lFareTimePeriod_ptr == NULL) {
149 lFareTimePeriod_ptr = &stdair::FacBom<stdair::TimePeriod>::instance().
150 create (lFareTimePeriodKey);
151 stdair::FacBomManager::addToListAndMap (iPosChannel,
152 *lFareTimePeriod_ptr);
153 stdair::FacBomManager::linkWithParent (iPosChannel,
154 *lFareTimePeriod_ptr);
155 }
156 // Sanity check.
157 assert (lFareTimePeriod_ptr != NULL);
158
159 stdair::TimePeriod& lTimeRange = *lFareTimePeriod_ptr;
160 // Generate the fare-features object corresponding to the given
161 // fareRule.
162 createFareFeatures (lTimeRange, iFareRuleStruct);
163
164 }
165
166 // //////////////////////////////////////////////////////////////////////
167 void FareRuleGenerator::
168 createFareFeatures (stdair::TimePeriod& iTimePeriod,
169 const FareRuleStruct& iFareRuleStruct) {
170
171 // Create the fare-features primary key.
172 const stdair::TripType_T& lTripType =
173 iFareRuleStruct.getTripType ();
174 const stdair::DayDuration_T& lAdvancePurchase =
175 iFareRuleStruct.getAdvancePurchase ();
176 const stdair::SaturdayStay_T& lSaturdayStay =
177 iFareRuleStruct.getSaturdayStay ();
178 const stdair::ChangeFees_T& lChangeFees =
179 iFareRuleStruct.getChangeFees ();
180 const stdair::NonRefundable_T& lNonRefundable =
181 iFareRuleStruct.getNonRefundable ();
182 const stdair::DayDuration_T& lMinimumStay =
183 iFareRuleStruct.getMinimumStay ();
184 const stdair::FareFeaturesKey
185 lFareFeaturesKey (lTripType, lAdvancePurchase, lSaturdayStay,
186 lChangeFees, lNonRefundable, lMinimumStay);
187
188 // Check that the fare features object is not already existing.
189 // If a fare features object with the same key has not already been
190 // created, create it and link it to the time-period object.
191 stdair::FareFeatures* lFareFeatures_ptr = stdair::BomManager::
192 getObjectPtr<stdair::FareFeatures> (iTimePeriod,
193 lFareFeaturesKey.toString());
194 if (lFareFeatures_ptr == NULL) {
195 lFareFeatures_ptr = &stdair::FacBom<stdair::FareFeatures>::instance().
196 create (lFareFeaturesKey);
197 assert(lFareFeatures_ptr != NULL);
198 stdair::FacBomManager::addToListAndMap (iTimePeriod,
199 *lFareFeatures_ptr);
200 stdair::FacBomManager::linkWithParent (iTimePeriod,
201 *lFareFeatures_ptr);
202 }
203 // Sanity check.
204 assert(lFareFeatures_ptr != NULL);
205
206 stdair::FareFeatures& lFareFeatures = *lFareFeatures_ptr;
207 // Generate the airline-class list object corresponding to the
208 // given fareRule
209 createAirlineClassList (lFareFeatures, iFareRuleStruct);
210
211 }
212
213 // //////////////////////////////////////////////////////////////////////
214 void FareRuleGenerator::
215 createAirlineClassList (stdair::FareFeatures& iFareFeatures,
216 const FareRuleStruct& iFareRuleStruct) {
217
218 // Create the AirlineClassList primary key.
219 const unsigned int lAirlineListSize =
220 iFareRuleStruct.getAirlineListSize();
221 const unsigned int lClassCodeListSize =
222 iFareRuleStruct.getClassCodeListSize();
223 assert (lAirlineListSize == lClassCodeListSize);
224 const stdair::AirlineClassListKey
225 lAirlineClassListKey (iFareRuleStruct.getAirlineList(),
226 iFareRuleStruct.getClassCodeList());
227 const stdair::Fare_T& lFare = iFareRuleStruct.getFare ();
228
229 // Create the airline class list object and link it to the fare features
230 // object.
231 stdair::AirlineClassList* lAirlineClassList_ptr =
232 &stdair::FacBom<stdair::AirlineClassList>::instance().
233 create (lAirlineClassListKey);
234 lAirlineClassList_ptr->setFare(lFare);
235 stdair::FacBomManager::addToListAndMap (iFareFeatures,
236 *lAirlineClassList_ptr);
237 stdair::FacBomManager::linkWithParent(iFareFeatures,
238 *lAirlineClassList_ptr);
239 }
240
241}
242