StdAir Logo  1.00.21
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
ParsedKey.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6#include <sstream>
7// Boost
8#include <boost/tokenizer.hpp>
9#include <boost/lexical_cast.hpp>
10#include <boost/date_time/gregorian/parsers.hpp>
11// StdAir
21
22namespace stdair {
23
24 // ////////////// Tokenising support ///////////////
28 typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T;
29
33 const boost::char_separator<char> TokeniserDashSeparator ("-");
34
38 const boost::char_separator<char> TokeniserTimeSeparator (":");
39
40 // ////////////////////////////////////////////////////////////////////
45
46 // ////////////////////////////////////////////////////////////////////
49
50 // ////////////////////////////////////////////////////////////////////
52 if (_airlineCode.size() < 2 || _airlineCode.size() > 3) {
53 STDAIR_LOG_ERROR ("No airline code can be found in '" << _fullKey << "'");
54 STDAIR_LOG_DEBUG ("Parsed key: " << toString());
55 throw KeyNotFoundException ("No airline code can be found in '"
56 + _fullKey + "'");
57 }
58 return _airlineCode;
59 }
60
61 // ////////////////////////////////////////////////////////////////////
63 // Check whether the departure date has been parsed correctly.
65
66 if (lDateTokens.begin() == lDateTokens.end()) {
67 STDAIR_LOG_ERROR ("No date can be found in '" << _fullKey << "'");
68 STDAIR_LOG_DEBUG ("Parsed key: " << toString());
69 throw KeyNotFoundException ("No date can be found in '" + _fullKey + "'");
70 }
71
72 const FlightNumber_T lFlightNumber =
73 boost::lexical_cast<FlightNumber_T> (_flightNumber);
74
75 const Date_T lDepartureDate =
76 boost::gregorian::from_simple_string (_departureDate);
77
78 const FlightDateKey oFlightDateKey (lFlightNumber, lDepartureDate);
79
80 return oFlightDateKey;
81 }
82
83 // ////////////////////////////////////////////////////////////////////
85 if (_boardingPoint.size() != 3) {
86 STDAIR_LOG_ERROR ("No airport code can be found in '" << _fullKey << "'");
87 STDAIR_LOG_DEBUG ("Parsed key: " << toString());
88 throw KeyNotFoundException ("No airport code can be found in '"
89 + _fullKey + "'");
90 }
91
92 const LegDateKey oLegDateKey (_boardingPoint);
93
94 return oLegDateKey;
95 }
96
97 // ////////////////////////////////////////////////////////////////////
99 if (_boardingPoint.size() != 3 || _offPoint.size() != 3) {
100 STDAIR_LOG_ERROR ("No airport code can be found in '" << _fullKey << "'");
101 STDAIR_LOG_DEBUG ("Parsed key: " << toString());
102 throw KeyNotFoundException ("No airport code can be found in '"
103 + _fullKey + "'");
104 }
105
106 const SegmentDateKey oSegmentDateKey (_boardingPoint, _offPoint);
107
108 return oSegmentDateKey;
109 }
110
111 // ////////////////////////////////////////////////////////////////////
113 // Check whether the boarding time has been parsed correctly.
115
116 if (lTimeTokens.begin() == lTimeTokens.end()) {
117 STDAIR_LOG_ERROR ("No boarding time can be found in '" << _fullKey << "'");
118 STDAIR_LOG_DEBUG ("Parsed key: " << toString());
119 throw KeyNotFoundException ("No boarding time can be found in '"
120 + _fullKey + "'");
121 }
122
123 const Duration_T oBoardingTime (boost::posix_time::
124 duration_from_string (_boardingTime));
125
126 return oBoardingTime;
127 }
128
129 // ////////////////////////////////////////////////////////////////////
130 void ParsedKey::toStream (std::ostream& ioOut) const {
131 ioOut << "ParsedKey: " << toString();
132 }
133
134 // ////////////////////////////////////////////////////////////////////
135 void ParsedKey::fromStream (std::istream& ioIn) {
136 }
137
138 // ////////////////////////////////////////////////////////////////////
139 const std::string ParsedKey::toString() const {
140 std::ostringstream oStr;
141
142 oStr << _airlineCode
150 << _offPoint
152 << _boardingTime;
153
154 return oStr.str();
155 }
156
157}
#define STDAIR_LOG_DEBUG(iToBeLogged)
Definition Logger.hpp:32
#define STDAIR_LOG_ERROR(iToBeLogged)
Definition Logger.hpp:23
Handle on the StdAir library context.
boost::gregorian::date Date_T
const std::string DEFAULT_KEY_SUB_FLD_DELIMITER
const boost::char_separator< char > TokeniserDashSeparator("-")
unsigned short FlightNumber_T
boost::posix_time::time_duration Duration_T
const boost::char_separator< char > TokeniserTimeSeparator(":")
boost::tokenizer< boost::char_separator< char > > Tokeniser_T
const std::string DEFAULT_KEY_FLD_DELIMITER
Key of a given flight-date, made of a flight number and a departure date.
Key of a given inventory, made of the airline code.
std::string _boardingPoint
Definition ParsedKey.hpp:80
std::string _flightNumber
Definition ParsedKey.hpp:78
const std::string toString() const
SegmentDateKey getSegmentKey() const
Definition ParsedKey.cpp:98
InventoryKey getInventoryKey() const
Definition ParsedKey.cpp:51
const Duration_T getBoardingTime() const
std::string _departureDate
Definition ParsedKey.hpp:79
std::string _fullKey
Definition ParsedKey.hpp:76
std::string _airlineCode
Definition ParsedKey.hpp:77
std::string _offPoint
Definition ParsedKey.hpp:81
LegDateKey getLegKey() const
Definition ParsedKey.cpp:84
void toStream(std::ostream &ioOut) const
void fromStream(std::istream &ioIn)
std::string _boardingTime
Definition ParsedKey.hpp:82
FlightDateKey getFlightDateKey() const
Definition ParsedKey.cpp:62
Key of a given segment-date, made of an origin and a destination airports.