1.00.26
C++ Standard Airline IT Object Library
Toggle main menu visibility
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
12
#include <
stdair/stdair_exceptions.hpp
>
13
#include <
stdair/basic/BasConst_Inventory.hpp
>
14
#include <
stdair/basic/BasConst_BomDisplay.hpp
>
15
#include <
stdair/bom/InventoryKey.hpp
>
16
#include <
stdair/bom/FlightDateKey.hpp
>
17
#include <
stdair/bom/SegmentDateKey.hpp
>
18
#include <
stdair/bom/LegDateKey.hpp
>
19
#include <
stdair/bom/ParsedKey.hpp
>
20
#include <
stdair/service/Logger.hpp
>
21
22
namespace
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
// ////////////////////////////////////////////////////////////////////
41
ParsedKey::ParsedKey
() :
_fullKey
(
""
),
_airlineCode
(
""
),
_flightNumber
(
""
),
42
_departureDate
(
""
),
_boardingPoint
(
""
),
43
_offPoint
(
""
),
_boardingTime
(
""
) {
44
}
45
46
// ////////////////////////////////////////////////////////////////////
47
ParsedKey::~ParsedKey
() {
48
}
49
50
// ////////////////////////////////////////////////////////////////////
51
InventoryKey
ParsedKey::getInventoryKey
()
const
{
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
// ////////////////////////////////////////////////////////////////////
62
FlightDateKey
ParsedKey::getFlightDateKey
()
const
{
63
// Check whether the departure date has been parsed correctly.
64
Tokeniser_T
lDateTokens (
_departureDate
,
TokeniserDashSeparator
);
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
// ////////////////////////////////////////////////////////////////////
84
LegDateKey
ParsedKey::getLegKey
()
const
{
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
// ////////////////////////////////////////////////////////////////////
98
SegmentDateKey
ParsedKey::getSegmentKey
()
const
{
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
// ////////////////////////////////////////////////////////////////////
112
const
Duration_T
ParsedKey::getBoardingTime
()
const
{
113
// Check whether the boarding time has been parsed correctly.
114
Tokeniser_T
lTimeTokens (
_boardingTime
,
TokeniserTimeSeparator
);
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
143
<<
DEFAULT_KEY_FLD_DELIMITER
<<
" "
144
<<
_flightNumber
145
<<
DEFAULT_KEY_SUB_FLD_DELIMITER
<<
" "
146
<<
_departureDate
147
<<
DEFAULT_KEY_FLD_DELIMITER
<<
" "
148
<<
_boardingPoint
149
<<
DEFAULT_KEY_SUB_FLD_DELIMITER
<<
" "
150
<<
_offPoint
151
<<
DEFAULT_KEY_FLD_DELIMITER
<<
" "
152
<<
_boardingTime
;
153
154
return
oStr.str();
155
}
156
157
}
BasConst_BomDisplay.hpp
BasConst_Inventory.hpp
FlightDateKey.hpp
InventoryKey.hpp
LegDateKey.hpp
ParsedKey.hpp
SegmentDateKey.hpp
Logger.hpp
STDAIR_LOG_DEBUG
#define STDAIR_LOG_DEBUG(iToBeLogged)
Definition
Logger.hpp:32
STDAIR_LOG_ERROR
#define STDAIR_LOG_ERROR(iToBeLogged)
Definition
Logger.hpp:23
stdair_exceptions.hpp
stdair
Handle on the StdAir library context.
Definition
BasChronometer.cpp:9
stdair::Date_T
boost::gregorian::date Date_T
Definition
stdair_date_time_types.hpp:20
stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
const std::string DEFAULT_KEY_SUB_FLD_DELIMITER
stdair::TokeniserDashSeparator
const boost::char_separator< char > TokeniserDashSeparator("-")
stdair::FlightNumber_T
unsigned short FlightNumber_T
Definition
stdair_basic_types.hpp:34
stdair::Duration_T
boost::posix_time::time_duration Duration_T
Definition
stdair_date_time_types.hpp:17
stdair::TokeniserTimeSeparator
const boost::char_separator< char > TokeniserTimeSeparator(":")
stdair::Tokeniser_T
boost::tokenizer< boost::char_separator< char > > Tokeniser_T
Definition
BomKeyManager.cpp:28
stdair::DEFAULT_KEY_FLD_DELIMITER
const std::string DEFAULT_KEY_FLD_DELIMITER
stdair::FlightDateKey
Key of a given flight-date, made of a flight number and a departure date.
Definition
FlightDateKey.hpp:28
stdair::InventoryKey
Key of a given inventory, made of the airline code.
Definition
InventoryKey.hpp:26
stdair::LegDateKey
Definition
LegDateKey.hpp:16
stdair::ParsedKey::_boardingPoint
std::string _boardingPoint
Definition
ParsedKey.hpp:80
stdair::ParsedKey::_flightNumber
std::string _flightNumber
Definition
ParsedKey.hpp:78
stdair::ParsedKey::toString
const std::string toString() const
Definition
ParsedKey.cpp:139
stdair::ParsedKey::getSegmentKey
SegmentDateKey getSegmentKey() const
Definition
ParsedKey.cpp:98
stdair::ParsedKey::getInventoryKey
InventoryKey getInventoryKey() const
Definition
ParsedKey.cpp:51
stdair::ParsedKey::~ParsedKey
~ParsedKey()
Definition
ParsedKey.cpp:47
stdair::ParsedKey::getBoardingTime
const Duration_T getBoardingTime() const
Definition
ParsedKey.cpp:112
stdair::ParsedKey::_departureDate
std::string _departureDate
Definition
ParsedKey.hpp:79
stdair::ParsedKey::_fullKey
std::string _fullKey
Definition
ParsedKey.hpp:76
stdair::ParsedKey::_airlineCode
std::string _airlineCode
Definition
ParsedKey.hpp:77
stdair::ParsedKey::_offPoint
std::string _offPoint
Definition
ParsedKey.hpp:81
stdair::ParsedKey::getLegKey
LegDateKey getLegKey() const
Definition
ParsedKey.cpp:84
stdair::ParsedKey::toStream
void toStream(std::ostream &ioOut) const
Definition
ParsedKey.cpp:130
stdair::ParsedKey::fromStream
void fromStream(std::istream &ioIn)
Definition
ParsedKey.cpp:135
stdair::ParsedKey::_boardingTime
std::string _boardingTime
Definition
ParsedKey.hpp:82
stdair::ParsedKey::getFlightDateKey
FlightDateKey getFlightDateKey() const
Definition
ParsedKey.cpp:62
stdair::ParsedKey::ParsedKey
ParsedKey()
Definition
ParsedKey.cpp:41
stdair::SegmentDateKey
Key of a given segment-date, made of an origin and a destination airports.
Definition
SegmentDateKey.hpp:24
stdair::KeyNotFoundException
Definition
stdair_exceptions.hpp:126
Generated for StdAir by
1.17.0