1.00.15
C++ Simulated Airline Inventory Management System Library
Toggle main menu visibility
Loading...
Searching...
No Matches
FRAT5ParserHelper.cpp
Go to the documentation of this file.
1
// //////////////////////////////////////////////////////////////////////
2
// Import section
3
// //////////////////////////////////////////////////////////////////////
4
// STL
5
#include <cassert>
6
#include <ostream>
7
// StdAir
8
#include <stdair/stdair_exceptions.hpp>
9
#include <stdair/stdair_types.hpp>
10
#include <stdair/bom/BomRoot.hpp>
11
#include <stdair/service/Logger.hpp>
12
// #define BOOST_SPIRIT_DEBUG
13
#include <
airinv/command/FRAT5ParserHelper.hpp
>
14
15
//
16
namespace
bsc = boost::spirit::classic;
17
18
namespace
AIRINV
{
19
20
namespace
FRAT5ParserHelper
{
21
22
// //////////////////////////////////////////////////////////////////
23
// Semantic actions
24
// //////////////////////////////////////////////////////////////////
25
26
ParserSemanticAction::
27
ParserSemanticAction
(
FRAT5Struct
& ioFRAT5)
28
:
_frat5
(ioFRAT5) {
29
}
30
31
// //////////////////////////////////////////////////////////////////
32
storeCurveKey::
33
storeCurveKey
(
FRAT5Struct
& ioFRAT5)
34
:
ParserSemanticAction
(ioFRAT5) {
35
}
36
37
// //////////////////////////////////////////////////////////////////
38
void
storeCurveKey::operator()
(
iterator_t
iStr,
39
iterator_t
iStrEnd)
const
{
40
const
std::string lKey (iStr, iStrEnd);
41
_frat5
._key = lKey;
42
//STDAIR_LOG_DEBUG ("Key: " << lKey);
43
}
44
45
// //////////////////////////////////////////////////////////////////
46
storeDTD::storeDTD
(
FRAT5Struct
& ioFRAT5)
47
:
ParserSemanticAction
(ioFRAT5) {
48
}
49
50
// //////////////////////////////////////////////////////////////////
51
void
storeDTD::operator()
(
int
iDTD)
const
{
52
_frat5
._dtd = iDTD;
53
//STDAIR_LOG_DEBUG ("DTD: " << iDTD);
54
}
55
56
// //////////////////////////////////////////////////////////////////
57
storeFRAT5Value::storeFRAT5Value
(
FRAT5Struct
& ioFRAT5)
58
:
ParserSemanticAction
(ioFRAT5) {
59
}
60
61
// //////////////////////////////////////////////////////////////////
62
void
storeFRAT5Value::operator()
(
double
iReal)
const
{
63
const
bool
hasInsertBeenSuccessfull =
64
_frat5
._curve.
65
insert (stdair::FRAT5Curve_T::
66
value_type (
_frat5
._dtd, iReal)).second;
67
if
(hasInsertBeenSuccessfull ==
false
) {
68
std::ostringstream oStr;
69
oStr <<
"The same DTD ('"
<<
_frat5
._dtd
70
<<
"') has probably been given twice"
;
71
STDAIR_LOG_ERROR (oStr.str());
72
throw
stdair::KeyDuplicationException (oStr.str());
73
}
74
75
//STDAIR_LOG_DEBUG ("Value: " << iReal);
76
}
77
78
// //////////////////////////////////////////////////////////////////
79
doEndCurve::
80
doEndCurve
(stdair::BomRoot& ioBomRoot,
81
FRAT5Struct
& ioFRAT5)
82
:
ParserSemanticAction
(ioFRAT5),
83
_bomRoot
(ioBomRoot) {
84
}
85
86
// //////////////////////////////////////////////////////////////////
87
// void doEndCurve::operator() (char iChar) const {
88
void
doEndCurve::operator()
(
iterator_t
iStr,
89
iterator_t
iStrEnd)
const
{
90
// DEBUG: Display the result
91
STDAIR_LOG_DEBUG (
"FRAT5: "
<<
_frat5
.describe());
92
93
// Add the curve to the BomRoot.
94
_bomRoot
.addFRAT5Curve (
_frat5
._key,
_frat5
._curve);
95
96
// As that's the end of a curve, the values must be cleared.
97
_frat5
._curve.clear();
98
}
99
100
101
// ///////////////////////////////////////////////////////////////////
102
//
103
// Utility Parsers
104
//
105
// ///////////////////////////////////////////////////////////////////
107
repeat_p_t
key_p
(
chset_t
(
"0-9A-Z"
).derived(), 1, 10);
108
109
// //////////////////////////////////////////////////////////////////
110
// (Boost Spirit) Grammar Definition
111
// //////////////////////////////////////////////////////////////////
112
113
// //////////////////////////////////////////////////////////////////
114
FRAT5Parser::
115
FRAT5Parser
(stdair::BomRoot& ioBomRoot,
116
FRAT5Struct
& ioFRAT5)
117
:
_bomRoot
(ioBomRoot),
118
_frat5
(ioFRAT5) {
119
}
120
121
// //////////////////////////////////////////////////////////////////
122
template
<
typename
ScannerT>
123
FRAT5Parser::definition<ScannerT>::
124
definition
(
FRAT5Parser
const
& self) {
125
126
curve_list
= *(
not_to_be_parsed
|
curve
)
127
;
128
129
not_to_be_parsed
=
130
bsc::lexeme_d[ bsc::comment_p(
"//"
) | bsc::comment_p(
"/*"
,
"*/"
)
131
| bsc::space_p ]
132
;
133
134
curve
=
key
>>
';'
>>
map
135
>>
curve_end
[
doEndCurve
(self.
_bomRoot
, self.
_frat5
)]
136
;
137
138
curve_end
= bsc::ch_p(
';'
)
139
;
140
141
key
=
142
bsc::lexeme_d[(
key_p
)[
storeCurveKey
(self.
_frat5
)]]
143
;
144
145
map
=
146
value_pair
>> *(
';'
>>
value_pair
)
147
;
148
149
value_pair
= bsc::uint_p[
storeDTD
(self.
_frat5
)]
150
>>
":"
>> bsc::ureal_p[
storeFRAT5Value
(self.
_frat5
)]
151
;
152
153
// BOOST_SPIRIT_DEBUG_NODE (FRAT5Parser);
154
BOOST_SPIRIT_DEBUG_NODE (
curve_list
);
155
BOOST_SPIRIT_DEBUG_NODE (
not_to_be_parsed
);
156
BOOST_SPIRIT_DEBUG_NODE (
key
);
157
BOOST_SPIRIT_DEBUG_NODE (
map
);
158
BOOST_SPIRIT_DEBUG_NODE (
value_pair
);
159
}
160
161
// //////////////////////////////////////////////////////////////////
162
template
<
typename
ScannerT>
163
bsc::rule<ScannerT>
const
&
164
FRAT5Parser::definition<ScannerT>::start
()
const
{
165
return
curve_list
;
166
}
167
}
168
169
171
//
172
// Entry class for the file parser
173
//
175
176
// //////////////////////////////////////////////////////////////////////
177
FRAT5FileParser::
178
FRAT5FileParser
(stdair::BomRoot& ioBomRoot,
179
const
stdair::Filename_T& iFilename)
180
: _filename (iFilename), _bomRoot (ioBomRoot) {
181
init();
182
}
183
184
// //////////////////////////////////////////////////////////////////////
185
void
FRAT5FileParser::init() {
186
// Open the file
187
_startIterator =
iterator_t
(_filename);
188
189
// Check the filename exists and can be open
190
if
(!_startIterator) {
191
std::ostringstream oMessage;
192
oMessage <<
"The file "
<< _filename <<
" can not be open."
<< std::endl;
193
STDAIR_LOG_ERROR (oMessage.str());
194
throw
FRAT5InputFileNotFoundException
(oMessage.str());
195
}
196
197
// Create an EOF iterator
198
_endIterator = _startIterator.make_end();
199
}
200
201
// //////////////////////////////////////////////////////////////////////
202
bool
FRAT5FileParser::generateFRAT5Curves
() {
203
bool
oResult =
false
;
204
205
STDAIR_LOG_DEBUG (
"Parsing FRAT5 input file: "
<< _filename);
206
207
// Initialise the parser (grammar) with the helper/staging structure.
208
FRAT5ParserHelper::FRAT5Parser
lFRAT5Parser (_bomRoot, _frat5);
209
210
// Launch the parsing of the file and, thanks to the doEndCurve
211
// call-back structure, the building of the whole BomRoot BOM
212
// (i.e., including Inventory, FlightDate, LegDate, SegmentDate, etc.)
213
bsc::parse_info<iterator_t> info = bsc::parse (_startIterator, _endIterator,
214
lFRAT5Parser,
215
bsc::space_p - bsc::eol_p);
216
217
// Retrieves whether or not the parsing was successful
218
oResult = info.hit;
219
220
const
bool
isFull = info.full;
221
222
const
std::string hasBeenFullyReadStr = (isFull ==
true
)?
""
:
"not "
;
223
if
(oResult ==
true
&& isFull ==
true
) {
224
STDAIR_LOG_DEBUG (
"Parsing of FRAT5 input file: "
<< _filename
225
<<
" succeeded: read "
<< info.length
226
<<
" characters. The input file has "
227
<< hasBeenFullyReadStr
228
<<
"been fully read. Stop point: "
<< info.stop);
229
230
}
else
{
231
STDAIR_LOG_ERROR (
"Parsing of FRAT5 input file: "
<< _filename
232
<<
" failed: read "
<< info.length
233
<<
" characters. The input file has "
234
<< hasBeenFullyReadStr
235
<<
"been fully read. Stop point: "
<< info.stop);
236
throw
FRAT5FileParsingFailedException
(
"Parsing of FRAT5 input file: "
237
+ _filename +
" failed."
);
238
}
239
240
return
oResult;
241
}
242
243
}
FRAT5ParserHelper.hpp
AIRINV::FRAT5FileParser::FRAT5FileParser
FRAT5FileParser(stdair::BomRoot &ioBomRoot, const stdair::Filename_T &iFilename)
Definition
FRAT5ParserHelper.cpp:178
AIRINV::FRAT5FileParser::generateFRAT5Curves
bool generateFRAT5Curves()
Definition
FRAT5ParserHelper.cpp:202
AIRINV::FRAT5FileParsingFailedException
Definition
AIRINV_Types.hpp:68
AIRINV::FRAT5InputFileNotFoundException
Definition
AIRINV_Types.hpp:130
AIRINV::FRAT5ParserHelper
Definition
FRAT5ParserHelper.cpp:20
AIRINV::FRAT5ParserHelper::key_p
repeat_p_t key_p(chset_t("0-9A-Z").derived(), 1, 10)
AIRINV
Definition
AIRINV_Master_Service.hpp:38
AIRINV::repeat_p_t
boost::spirit::classic::impl::loop_traits< chset_t, unsignedint, unsignedint >::type repeat_p_t
Definition
BasParserTypes.hpp:69
AIRINV::chset_t
boost::spirit::classic::chset< char_t > chset_t
Definition
BasParserTypes.hpp:63
AIRINV::iterator_t
boost::spirit::classic::file_iterator< char_t > iterator_t
Definition
BasParserTypes.hpp:35
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::curve_end
boost::spirit::classic::rule< ScannerT > curve_end
Definition
FRAT5ParserHelper.hpp:100
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::curve_list
boost::spirit::classic::rule< ScannerT > curve_list
Definition
FRAT5ParserHelper.hpp:99
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::start
boost::spirit::classic::rule< ScannerT > const & start() const
Definition
FRAT5ParserHelper.cpp:164
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::value_pair
boost::spirit::classic::rule< ScannerT > value_pair
Definition
FRAT5ParserHelper.hpp:100
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::key
boost::spirit::classic::rule< ScannerT > key
Definition
FRAT5ParserHelper.hpp:100
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::not_to_be_parsed
boost::spirit::classic::rule< ScannerT > not_to_be_parsed
Definition
FRAT5ParserHelper.hpp:100
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::definition
definition(FRAT5Parser const &self)
Definition
FRAT5ParserHelper.cpp:124
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::map
boost::spirit::classic::rule< ScannerT > map
Definition
FRAT5ParserHelper.hpp:100
AIRINV::FRAT5ParserHelper::FRAT5Parser::definition::curve
boost::spirit::classic::rule< ScannerT > curve
Definition
FRAT5ParserHelper.hpp:100
AIRINV::FRAT5ParserHelper::FRAT5Parser
Definition
FRAT5ParserHelper.hpp:90
AIRINV::FRAT5ParserHelper::FRAT5Parser::FRAT5Parser
FRAT5Parser(stdair::BomRoot &, FRAT5Struct &)
Definition
FRAT5ParserHelper.cpp:115
AIRINV::FRAT5ParserHelper::FRAT5Parser::_frat5
FRAT5Struct & _frat5
Definition
FRAT5ParserHelper.hpp:108
AIRINV::FRAT5ParserHelper::FRAT5Parser::_bomRoot
stdair::BomRoot & _bomRoot
Definition
FRAT5ParserHelper.hpp:107
AIRINV::FRAT5ParserHelper::ParserSemanticAction::ParserSemanticAction
ParserSemanticAction(FRAT5Struct &)
Definition
FRAT5ParserHelper.cpp:27
AIRINV::FRAT5ParserHelper::ParserSemanticAction::_frat5
FRAT5Struct & _frat5
Definition
FRAT5ParserHelper.hpp:33
AIRINV::FRAT5ParserHelper::doEndCurve
Definition
FRAT5ParserHelper.hpp:61
AIRINV::FRAT5ParserHelper::doEndCurve::_bomRoot
stdair::BomRoot & _bomRoot
Definition
FRAT5ParserHelper.hpp:67
AIRINV::FRAT5ParserHelper::doEndCurve::operator()
void operator()(iterator_t iStr, iterator_t iStrEnd) const
Definition
FRAT5ParserHelper.cpp:88
AIRINV::FRAT5ParserHelper::doEndCurve::doEndCurve
doEndCurve(stdair::BomRoot &, FRAT5Struct &)
Definition
FRAT5ParserHelper.cpp:80
AIRINV::FRAT5ParserHelper::storeCurveKey
Definition
FRAT5ParserHelper.hpp:37
AIRINV::FRAT5ParserHelper::storeCurveKey::operator()
void operator()(iterator_t iStr, iterator_t iStrEnd) const
Definition
FRAT5ParserHelper.cpp:38
AIRINV::FRAT5ParserHelper::storeCurveKey::storeCurveKey
storeCurveKey(FRAT5Struct &)
Definition
FRAT5ParserHelper.cpp:33
AIRINV::FRAT5ParserHelper::storeDTD
Definition
FRAT5ParserHelper.hpp:45
AIRINV::FRAT5ParserHelper::storeDTD::storeDTD
storeDTD(FRAT5Struct &)
Definition
FRAT5ParserHelper.cpp:46
AIRINV::FRAT5ParserHelper::storeDTD::operator()
void operator()(int iDTD) const
Definition
FRAT5ParserHelper.cpp:51
AIRINV::FRAT5ParserHelper::storeFRAT5Value
Definition
FRAT5ParserHelper.hpp:53
AIRINV::FRAT5ParserHelper::storeFRAT5Value::storeFRAT5Value
storeFRAT5Value(FRAT5Struct &)
Definition
FRAT5ParserHelper.cpp:57
AIRINV::FRAT5ParserHelper::storeFRAT5Value::operator()
void operator()(double iReal) const
Definition
FRAT5ParserHelper.cpp:62
AIRINV::FRAT5Struct
Definition
FRAT5Struct.hpp:15
Generated on
for AirInv by
1.17.0