AirTSP Logo  1.01.9
C++ Simulated Airline Travel Solution Provider (TSP) Library
Loading...
Searching...
No Matches
BookingRequestParser.hpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <string>
6#include <vector>
7
8namespace airtsp {
9
11 struct Place_T {
12 // Attributes
13 std::string _name;
14 std::string _code;
16 Place_T () : _name (""), _code ("") {}
17 /* Display. */
18 void display() const {
19 std::cout << "Place: " << _name << " (" << _code << ")" << std::endl;
20 }
21 };
22
24 typedef std::vector<Place_T> PlaceList_T;
25
27 struct Date_T {
28 // Attributes
29 boost::gregorian::date _date;
30 unsigned int _reldays;
31 unsigned int _day;
32 unsigned int _month;
33 unsigned int _year;
35 Date_T () : _reldays (14), _day(1), _month(1), _year(1970) {}
36 /* Display. */
37 void display() const {
38 std::cout << "Date: " << _date << " (" << _day << "/" << _month
39 << "/" << _year << "), i.e. in " << _reldays << " days"
40 << std::endl;
41 }
43 boost::gregorian::date getDate() const {
44 return boost::gregorian::date (_year, _month, _day);
45 }
46 };
47
49 typedef std::vector<Date_T> DateList_T;
50
52 struct Airline_T {
53 // Attributes
55 std::string _name;
56 std::string _code;
58 Airline_T () : _isPreferred (true), _name(""), _code("") {}
59 /* Display. */
60 void display() const {
61 const std::string isPreferredStr = (_isPreferred)?"+":"-";
62 std::cout << "Airline: " << isPreferredStr << _name << " (" << _code << ")"
63 << std::endl;
64 }
65 };
66
68 typedef std::vector<Airline_T> AirlineList_T;
69
71 struct Passenger_T {
72 // Attributes
73 typedef enum { ADULT = 0, CHILD, PET, LAST_VALUE } PassengerType_T;
74 static const std::string _labels[LAST_VALUE];
76 unsigned short _number;
79 /* Display. */
80 void display() const {
81 std::cout << "Passenger: " << _number << " (" << _labels[_type] << ")"
82 << std::endl;
83 }
84 };
85
88 { "Adult", "Child", "Pet" };
89
91 typedef std::vector<Passenger_T> PassengerList_T;
92
95 // Attributes
100
103
104 /* Display. */
105 void display() const {
106 std::cout << std::endl;
107
108 for (PlaceList_T::const_iterator itPlace = _placeList.begin();
109 itPlace != _placeList.end(); ++itPlace) {
110 const Place_T& lPlace = *itPlace;
111 lPlace.display();
112 }
113
114 for (DateList_T::const_iterator itDate = _dateList.begin();
115 itDate != _dateList.end(); ++itDate) {
116 const Date_T& lDate = *itDate;
117 lDate.display();
118 }
119
120 for (AirlineList_T::const_iterator itAirline = _airlineList.begin();
121 itAirline != _airlineList.end(); ++itAirline) {
122 const Airline_T& lAirline = *itAirline;
123 lAirline.display();
124 }
125
126 for (PassengerList_T::const_iterator itPassenger = _passengerList.begin();
127 itPassenger != _passengerList.end(); ++itPassenger) {
128 const Passenger_T& lPassenger = *itPassenger;
129 lPassenger.display();
130 }
131
132 std::cout << "-- Staging --" << std::endl;
134 }
135
136 // //// Staging ////
141 };
142
144 //
145 // The booking request grammar (using subrules)
146 //
148
174 SearchString_T parseBookingRequest (const std::string& iSearchString);
175
176}
std::vector< Airline_T > AirlineList_T
std::vector< Date_T > DateList_T
SearchString_T parseBookingRequest(const std::string &iSearchString)
std::vector< Passenger_T > PassengerList_T
std::vector< Place_T > PlaceList_T
boost::gregorian::date getDate() const
boost::gregorian::date _date
static const std::string _labels[LAST_VALUE]