OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PORParserHelper.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <vector>
7 #include <fstream>
8 // Boost
9 #include <boost/lexical_cast.hpp>
10 //#define BOOST_SPIRIT_DEBUG
11 #define BOOST_SPIRIT_UNICODE
12 // OpenTREP
16 
17 namespace OPENTREP {
18 
20  namespace bsq = boost::spirit::qi;
21  //namespace bsa = boost::spirit::ascii;
22  namespace bsu = boost::spirit::unicode;
23  namespace bsc = boost::spirit::classic;
24 
25  namespace PorParserHelper {
26 
27  // //////////////////////////////////////////////////////////////////
28  // Semantic actions
29  // //////////////////////////////////////////////////////////////////
30 
32  : _location (ioLocation) {
33  }
34 
35  // //////////////////////////////////////////////////////////////////
37  : ParserSemanticAction (ioLocation) {
38  }
39 
40  // //////////////////////////////////////////////////////////////////
41  void storeIataCode::operator() (std::vector<uchar_t> iChar,
42  bsq::unused_type, bsq::unused_type) const {
43 
44  const std::string lIataCodeStr (iChar.begin(), iChar.end());
45  const OPENTREP::IATACode_T lIataCode (lIataCodeStr);
46  _location.setIataCode (lIataCode);
47 
48  // Reset the values
49  //_location.resetMatrix();
50  //_location._itAltNameShortList.clear();
51 
52  // DEBUG
53  //OPENTREP_LOG_DEBUG ("IATA code: " << _location.getIataCode());
54  }
55 
56  // //////////////////////////////////////////////////////////////////
58  : ParserSemanticAction (ioLocation) {
59  }
60 
61  // //////////////////////////////////////////////////////////////////
62  void storeIcaoCode::operator() (std::vector<uchar_t> iChar,
63  bsq::unused_type, bsq::unused_type) const {
64 
65  const std::string lIcaoCodeStr (iChar.begin(), iChar.end());
66  const OPENTREP::ICAOCode_T lIcaoCode (lIcaoCodeStr);
67  _location.setIcaoCode (lIcaoCode);
68 
69  // DEBUG
70  //OPENTREP_LOG_DEBUG ("ICAO code: " << _location.getIcaoCode());
71  }
72 
73  // //////////////////////////////////////////////////////////////////
75  : ParserSemanticAction (ioLocation) {
76  }
77 
78  // //////////////////////////////////////////////////////////////////
79  void storeFaaCode::operator() (std::vector<uchar_t> iChar,
80  bsq::unused_type, bsq::unused_type) const {
81 
82  const std::string lFaaCodeStr (iChar.begin(), iChar.end());
83  const OPENTREP::FAACode_T lFaaCode (lFaaCodeStr);
84  _location.setFaaCode (lFaaCode);
85 
86  // DEBUG
87  //OPENTREP_LOG_DEBUG ("FAA code: " << _location.getFaaCode());
88  }
89 
90  // //////////////////////////////////////////////////////////////////
92  : ParserSemanticAction (ioLocation) {
93  }
94 
95  // //////////////////////////////////////////////////////////////////
96  void storeGeonamesID::operator() (unsigned int iPorId,
97  bsq::unused_type, bsq::unused_type) const {
98  _location.setGeonamesID (iPorId);
99 
100  // DEBUG
101  //OPENTREP_LOG_DEBUG ("POR ID: " << _location.getPorID());
102  }
103 
104  // //////////////////////////////////////////////////////////////////
106  : ParserSemanticAction (ioLocation) {
107  }
108 
109  // //////////////////////////////////////////////////////////////////
110  void storeEnvelopeID::operator() (unsigned int iEnvelopeID,
111  bsq::unused_type, bsq::unused_type) const {
112  _location.setEnvelopeID (iEnvelopeID);
113 
114  // DEBUG
115  //OPENTREP_LOG_DEBUG ("Envelope ID: " << _location.getEnvelopeID());
116  }
117 
118  // //////////////////////////////////////////////////////////////////
120  : ParserSemanticAction (ioLocation) {
121  }
122 
123  // //////////////////////////////////////////////////////////////////
124  void storeCommonName::operator() (std::vector<uchar_t> iChar,
125  bsq::unused_type, bsq::unused_type) const {
126 
127  const std::string lCommonNameStr (iChar.begin(), iChar.end());
128  const OPENTREP::CommonName_T lCommonName (lCommonNameStr);
129  _location.setCommonName (lCommonName);
130  // DEBUG
131  //OPENTREP_LOG_DEBUG ("Common name: " << _location.getCommonName());
132  }
133 
134  // //////////////////////////////////////////////////////////////////
136  : ParserSemanticAction (ioLocation) {
137  }
138 
139  // //////////////////////////////////////////////////////////////////
140  void storeAsciiName::operator() (std::vector<uchar_t> iChar,
141  bsq::unused_type, bsq::unused_type) const {
142 
143  const std::string lAsciiNameStr (iChar.begin(), iChar.end());
144  const OPENTREP::ASCIIName_T lAsciiName (lAsciiNameStr);
145  _location.setAsciiName (lAsciiName);
146  // DEBUG
147  //OPENTREP_LOG_DEBUG ("ASCII name: " << _location.getAsciiName());
148  }
149 
150  // //////////////////////////////////////////////////////////////////
152  : ParserSemanticAction (ioLocation) {
153  }
154 
155  // //////////////////////////////////////////////////////////////////
156  void storeAltNameShort::operator() (std::vector<uchar_t> iChar,
157  bsq::unused_type,
158  bsq::unused_type)const {
159 
160  const std::string lAltNameShortStr (iChar.begin(), iChar.end());
161  const OPENTREP::AltNameShortListString_T lAltNameShort (lAltNameShortStr);
162  _location._itAltNameShortList.push_back (lAltNameShort);
163  // DEBUG
164  //OPENTREP_LOG_DEBUG ("Alt name short: " << lAltNameShortStr);
165  }
166 
167  // //////////////////////////////////////////////////////////////////
170  : ParserSemanticAction (ioLocation) {
171  }
172 
173  // //////////////////////////////////////////////////////////////////
175  operator() (bsq::unused_type, bsq::unused_type, bsq::unused_type)const {
177  // DEBUG
178  //OPENTREP_LOG_DEBUG ("Alternative name short list: " << _location.getAltNameShortListString());
179  }
180 
181  // //////////////////////////////////////////////////////////////////
183  : ParserSemanticAction (ioLocation) {
184  }
185 
186  // //////////////////////////////////////////////////////////////////
187  void storeTvlPORCode::operator() (std::vector<uchar_t> iChar,
188  bsq::unused_type,
189  bsq::unused_type)const {
190 
191  const std::string lTvlPORCodeStr (iChar.begin(), iChar.end());
192  const OPENTREP::TvlPORListString_T lTvlPORCode (lTvlPORCodeStr);
193  _location._itTvlPORList.push_back (lTvlPORCode);
194  // DEBUG
195  //OPENTREP_LOG_DEBUG ("Travel-related IATA code: " << lTvlPORCodeStr);
196  }
197 
198  // //////////////////////////////////////////////////////////////////
200  : ParserSemanticAction (ioLocation) {
201  }
202 
203  // //////////////////////////////////////////////////////////////////
204  void storeTvlPORListString::operator() (bsq::unused_type, bsq::unused_type,
205  bsq::unused_type)const {
207  // DEBUG
208  //OPENTREP_LOG_DEBUG ("Travel-related POR list: " << _location.getTvlPORListString());
209  }
210 
211  // //////////////////////////////////////////////////////////////////
213  : ParserSemanticAction (ioLocation) {
214  }
215 
216  // //////////////////////////////////////////////////////////////////
217  void storeLatitude::operator() (double iLatitude,
218  bsq::unused_type, bsq::unused_type) const {
219  _location.setLatitude (iLatitude);
220  // DEBUG
221  //OPENTREP_LOG_DEBUG ("Latitude: " << _location.getLatitude());
222  }
223 
224  // //////////////////////////////////////////////////////////////////
226  : ParserSemanticAction (ioLocation) {
227  }
228 
229  // //////////////////////////////////////////////////////////////////
230  void storeLongitude::operator() (double iLongitude,
231  bsq::unused_type, bsq::unused_type) const {
232  _location.setLongitude (iLongitude);
233 
234  // DEBUG
235  //OPENTREP_LOG_DEBUG ("Longitude: " << _location.getLongitude());
236  }
237 
238  // //////////////////////////////////////////////////////////////////
240  : ParserSemanticAction (ioLocation) {
241  }
242 
243  // //////////////////////////////////////////////////////////////////
244  void storeFeatureClass::operator() (std::vector<uchar_t> iChar,
245  bsq::unused_type,
246  bsq::unused_type) const {
247  const std::string lFeatClassStr (iChar.begin(), iChar.end());
248  const FeatureClass_T lFeatClass (lFeatClassStr);
249  _location.setFeatureClass (lFeatClass);
250 
251  // DEBUG
252  //OPENTREP_LOG_DEBUG ("Feature class: " << _location.getFeatureClass());
253  }
254 
255  // //////////////////////////////////////////////////////////////////
257  : ParserSemanticAction (ioLocation) {
258  }
259 
260  // //////////////////////////////////////////////////////////////////
261  void storeFeatureCode::operator() (std::vector<uchar_t> iChar,
262  bsq::unused_type,
263  bsq::unused_type) const {
264  const std::string lFeatCodeStr (iChar.begin(), iChar.end());
265  const FeatureClass_T lFeatCode (lFeatCodeStr);
266  _location.setFeatureCode (lFeatCode);
267 
268  // DEBUG
269  //OPENTREP_LOG_DEBUG ("Feature code: " << _location.getFeatureCode());
270  }
271 
272  // //////////////////////////////////////////////////////////////////
274  : ParserSemanticAction (ioLocation) {
275  }
276 
277  // //////////////////////////////////////////////////////////////////
278  void storePageRank::operator() (double iPageRank,
279  bsq::unused_type, bsq::unused_type) const {
280  _location.setPageRank (100.0 * iPageRank);
281 
282  // DEBUG
283  //OPENTREP_LOG_DEBUG ("PageRank: " << _location.getPageRank());
284  }
285 
286  // //////////////////////////////////////////////////////////////////
288  : ParserSemanticAction (ioLocation) {
289  }
290 
291  // //////////////////////////////////////////////////////////////////
292  void storeDateFrom::operator() (bsq::unused_type,
293  bsq::unused_type, bsq::unused_type) const {
294  /*
295  const OPENTREP::Date_T& lDateFrom = _location.calculateDate();
296  _location.setDateFrom (lDateFrom);
297  */
298 
299  // DEBUG
300  //OPENTREP_LOG_DEBUG ("Date from: " << _location.getDateFrom());
301  }
302 
303  // //////////////////////////////////////////////////////////////////
305  : ParserSemanticAction (ioLocation) {
306  }
307 
308  // //////////////////////////////////////////////////////////////////
309  void storeDateUntil::operator() (bsq::unused_type,
310  bsq::unused_type, bsq::unused_type) const {
311  /*
312  const OPENTREP::Date_T& lDateUntil = _location.calculateDate();
313  _location.setDateUntil (lDateUntil);
314  */
315 
316  // DEBUG
317  //OPENTREP_LOG_DEBUG ("Date until: " << _location.getDateUntil());
318  }
319 
320  // //////////////////////////////////////////////////////////////////
322  : ParserSemanticAction (ioLocation) {
323  }
324 
325  // //////////////////////////////////////////////////////////////////
326  void storeComments::operator() (std::vector<uchar_t> iChar,
327  bsq::unused_type, bsq::unused_type) const {
328  /*
329  const std::string lCommentsStr (iChar.begin(), iChar.end());
330  const CountryCode_T lComments (lCommentsStr);
331  _location.setComments (lComments);
332  */
333 
334  // DEBUG
335  //OPENTREP_LOG_DEBUG ("Comments: " << _location.getComments());
336  }
337 
338  // //////////////////////////////////////////////////////////////////
340  : ParserSemanticAction (ioLocation) {
341  }
342 
343  // //////////////////////////////////////////////////////////////////
344  void storeCountryCode::operator() (std::vector<uchar_t> iChar,
345  bsq::unused_type,
346  bsq::unused_type) const {
347  const std::string lCountryCodeStr (iChar.begin(), iChar.end());
348  const CountryCode_T lCountryCode (lCountryCodeStr);
349  _location.setCountryCode (lCountryCode);
350  // DEBUG
351  //OPENTREP_LOG_DEBUG ("Country code: " << _location.getCountryCode());
352  }
353 
354  // //////////////////////////////////////////////////////////////////
356  : ParserSemanticAction (ioLocation) {
357  }
358 
359  // //////////////////////////////////////////////////////////////////
360  void storeAltCountryCode::operator() (std::vector<uchar_t> iChar,
361  bsq::unused_type,
362  bsq::unused_type) const {
363  const std::string lCountryCodeStr (iChar.begin(), iChar.end());
364  const CountryCode_T lCountryCode (lCountryCodeStr);
365  _location.setAltCountryCode (lCountryCode);
366  // DEBUG
367  //OPENTREP_LOG_DEBUG ("Alt country code: " << _location.getAltCountryCode());
368  }
369 
370  // //////////////////////////////////////////////////////////////////
372  : ParserSemanticAction (ioLocation) {
373  }
374 
375  // //////////////////////////////////////////////////////////////////
376  void storeCountryName::operator() (std::vector<uchar_t> iChar,
377  bsq::unused_type,
378  bsq::unused_type) const {
379  const std::string lCountryNameStr (iChar.begin(), iChar.end());
380  const CountryName_T lCountryName (lCountryNameStr);
381  _location.setCountryName (lCountryName);
382  // DEBUG
383  //OPENTREP_LOG_DEBUG ("Country name: " << _location.getCountryName());
384  }
385 
386  // //////////////////////////////////////////////////////////////////
388  : ParserSemanticAction (ioLocation) {
389  }
390 
391  // //////////////////////////////////////////////////////////////////
392  void storeContinentName::operator() (std::vector<uchar_t> iChar,
393  bsq::unused_type,
394  bsq::unused_type) const {
395  const std::string lContinentNameStr (iChar.begin(), iChar.end());
396  const ContinentName_T lContinentName (lContinentNameStr);
397  _location.setContinentName (lContinentName);
398  // DEBUG
399  //OPENTREP_LOG_DEBUG ("Continent name: " << _location.getContinentName());
400  }
401 
402  // //////////////////////////////////////////////////////////////////
404  : ParserSemanticAction (ioLocation) {
405  }
406 
407  // //////////////////////////////////////////////////////////////////
408  void storeAdm1Code::operator() (std::vector<uchar_t> iChar,
409  bsq::unused_type,
410  bsq::unused_type) const {
411  const std::string lAdmCodeStr (iChar.begin(), iChar.end());
412  const Admin1Code_T lAdmCode (lAdmCodeStr);
413  _location.setAdmin1Code (lAdmCode);
414  // DEBUG
415  //OPENTREP_LOG_DEBUG ("Adm1 code: " << _location.getAdmin1Code());
416  }
417 
418  // //////////////////////////////////////////////////////////////////
420  : ParserSemanticAction (ioLocation) {
421  }
422 
423  // //////////////////////////////////////////////////////////////////
424  void storeAdm1UtfName::operator() (std::vector<uchar_t> iChar,
425  bsq::unused_type,
426  bsq::unused_type) const {
427  const std::string lAdmNameStr (iChar.begin(), iChar.end());
428  const Admin1UTFName_T lAdmName (lAdmNameStr);
429  _location.setAdmin1UtfName (lAdmName);
430  // DEBUG
431  //OPENTREP_LOG_DEBUG ("Adm1 UTF8 name: " << _location.getAdmin1UtfName());
432  }
433 
434  // //////////////////////////////////////////////////////////////////
436  : ParserSemanticAction (ioLocation) {
437  }
438 
439  // //////////////////////////////////////////////////////////////////
440  void storeAdm1AsciiName::operator() (std::vector<uchar_t> iChar,
441  bsq::unused_type,
442  bsq::unused_type) const {
443  const std::string lAdmNameStr (iChar.begin(), iChar.end());
444  const Admin1ASCIIName_T lAdmName (lAdmNameStr);
445  _location.setAdmin1AsciiName (lAdmName);
446  // DEBUG
447  //OPENTREP_LOG_DEBUG("Adm1 ASCII name: "<< _location.getAdmin1AsciiName());
448  }
449 
450  // //////////////////////////////////////////////////////////////////
452  : ParserSemanticAction (ioLocation) {
453  }
454 
455  // //////////////////////////////////////////////////////////////////
456  void storeAdm2Code::operator() (std::vector<uchar_t> iChar,
457  bsq::unused_type,
458  bsq::unused_type) const {
459  const std::string lAdmCodeStr (iChar.begin(), iChar.end());
460  const Admin2Code_T lAdmCode (lAdmCodeStr);
461  _location.setAdmin2Code (lAdmCode);
462  // DEBUG
463  //OPENTREP_LOG_DEBUG ("Adm2 code: " << _location.getAdmin2Code());
464  }
465 
466  // //////////////////////////////////////////////////////////////////
468  : ParserSemanticAction (ioLocation) {
469  }
470 
471  // //////////////////////////////////////////////////////////////////
472  void storeAdm2UtfName::operator() (std::vector<uchar_t> iChar,
473  bsq::unused_type,
474  bsq::unused_type) const {
475  const std::string lAdmNameStr (iChar.begin(), iChar.end());
476  const Admin2UTFName_T lAdmName (lAdmNameStr);
477  _location.setAdmin2UtfName (lAdmName);
478  // DEBUG
479  //OPENTREP_LOG_DEBUG ("Adm2 UTF8 name: " << _location.getAdmin2UtfName());
480  }
481 
482  // //////////////////////////////////////////////////////////////////
484  : ParserSemanticAction (ioLocation) {
485  }
486 
487  // //////////////////////////////////////////////////////////////////
488  void storeAdm2AsciiName::operator() (std::vector<uchar_t> iChar,
489  bsq::unused_type,
490  bsq::unused_type) const {
491  const std::string lAdmNameStr (iChar.begin(), iChar.end());
492  const Admin2ASCIIName_T lAdmName (lAdmNameStr);
493  _location.setAdmin2AsciiName (lAdmName);
494  // DEBUG
495  //OPENTREP_LOG_DEBUG("Adm2 ASCII name: "<< _location.getAdmin2AsciiName());
496  }
497 
498  // //////////////////////////////////////////////////////////////////
500  : ParserSemanticAction (ioLocation) {
501  }
502 
503  // //////////////////////////////////////////////////////////////////
504  void storeAdm3Code::operator() (std::vector<uchar_t> iChar,
505  bsq::unused_type,
506  bsq::unused_type) const {
507  const std::string lAdmCodeStr (iChar.begin(), iChar.end());
508  const Admin3Code_T lAdmCode (lAdmCodeStr);
509  _location.setAdmin3Code (lAdmCode);
510  // DEBUG
511  //OPENTREP_LOG_DEBUG ("Adm3 code: " << _location.getAdmin3Code());
512  }
513 
514  // //////////////////////////////////////////////////////////////////
516  : ParserSemanticAction (ioLocation) {
517  }
518 
519  // //////////////////////////////////////////////////////////////////
520  void storeAdm4Code::operator() (std::vector<uchar_t> iChar,
521  bsq::unused_type,
522  bsq::unused_type) const {
523  const std::string lAdmCodeStr (iChar.begin(), iChar.end());
524  const Admin4Code_T lAdmCode (lAdmCodeStr);
525  _location.setAdmin4Code (lAdmCode);
526  // DEBUG
527  //OPENTREP_LOG_DEBUG ("Adm4 code: " << _location.getAdmin4Code());
528  }
529 
530  // //////////////////////////////////////////////////////////////////
532  : ParserSemanticAction (ioLocation) {
533  }
534 
535  // //////////////////////////////////////////////////////////////////
536  void storePopulation::operator() (unsigned int iPopulation,
537  bsq::unused_type, bsq::unused_type) const {
538  _location.setPopulation (iPopulation);
539  // DEBUG
540  //OPENTREP_LOG_DEBUG ("Population: " << _location.getPopulation());
541  }
542 
543  // //////////////////////////////////////////////////////////////////
545  : ParserSemanticAction (ioLocation) {
546  }
547 
548  // //////////////////////////////////////////////////////////////////
549  void storeElevation::operator() (int iElevation,
550  bsq::unused_type, bsq::unused_type) const {
551  _location.setElevation (iElevation);
552  // DEBUG
553  //OPENTREP_LOG_DEBUG ("Elevation: " << _location.getElevation());
554  }
555 
556  // //////////////////////////////////////////////////////////////////
558  : ParserSemanticAction (ioLocation) {
559  }
560 
561  // //////////////////////////////////////////////////////////////////
562  void storeGTopo30::operator() (int iGTopo30,
563  bsq::unused_type, bsq::unused_type) const {
564  _location.setGTopo30 (iGTopo30);
565  // DEBUG
566  //OPENTREP_LOG_DEBUG ("GTopo30: " << _location.getGTopo30());
567  }
568 
569  // //////////////////////////////////////////////////////////////////
571  : ParserSemanticAction (ioLocation) {
572  }
573 
574  // //////////////////////////////////////////////////////////////////
575  void storeTimeZone::operator() (std::vector<uchar_t> iChar,
576  bsq::unused_type,
577  bsq::unused_type) const {
578  const std::string lTimeZoneStr (iChar.begin(), iChar.end());
579  const TimeZone_T lTimeZone (lTimeZoneStr);
580  _location.setTimeZone (lTimeZone);
581  // DEBUG
582  //OPENTREP_LOG_DEBUG ("Time-zone code: " << _location.getTimeZone());
583  }
584 
585  // //////////////////////////////////////////////////////////////////
587  : ParserSemanticAction (ioLocation) {
588  }
589 
590  // //////////////////////////////////////////////////////////////////
591  void storeGMTOffset::operator() (float iOffset,
592  bsq::unused_type, bsq::unused_type) const {
593  _location.setGMTOffset (iOffset);
594  // DEBUG
595  //OPENTREP_LOG_DEBUG ("GMT offset: " << _location.getGMTOffset());
596  }
597 
598  // //////////////////////////////////////////////////////////////////
600  : ParserSemanticAction (ioLocation) {
601  }
602 
603  // //////////////////////////////////////////////////////////////////
604  void storeDSTOffset::operator() (float iOffset,
605  bsq::unused_type, bsq::unused_type) const {
606  _location.setDSTOffset (iOffset);
607  // DEBUG
608  //OPENTREP_LOG_DEBUG ("DST offset: " << _location.getDSTOffset());
609  }
610 
611  // //////////////////////////////////////////////////////////////////
613  : ParserSemanticAction (ioLocation) {
614  }
615 
616  // //////////////////////////////////////////////////////////////////
617  void storeRawOffset::operator() (float iOffset,
618  bsq::unused_type, bsq::unused_type) const {
619  _location.setRawOffset (iOffset);
620  // DEBUG
621  //OPENTREP_LOG_DEBUG ("Raw offset: " << _location.getRawOffset());
622  }
623 
624  // //////////////////////////////////////////////////////////////////
626  : ParserSemanticAction (ioLocation) {
627  }
628 
629  // //////////////////////////////////////////////////////////////////
630  void storeModDate::operator() (bsq::unused_type,
631  bsq::unused_type, bsq::unused_type) const {
632  const OPENTREP::Date_T& lModDate = _location.calculateDate();
633  _location.setModificationDate (lModDate);
634  // DEBUG
635  //OPENTREP_LOG_DEBUG ("Modification date: " << _location.getModificationDate());
636  }
637 
638  // //////////////////////////////////////////////////////////////////
640  : ParserSemanticAction (ioLocation) {
641  }
642 
643  // //////////////////////////////////////////////////////////////////
644  void storeCityCode::operator() (std::vector<uchar_t> iChar,
645  bsq::unused_type, bsq::unused_type) const {
646 
647  const std::string lCityCodeStr (iChar.begin(), iChar.end());
648  const OPENTREP::CityCode_T lCityCode (lCityCodeStr);
649  _location.setCityCode (lCityCode);
650  // DEBUG
651  //OPENTREP_LOG_DEBUG ("City code: " << _location.getCityCode());
652  }
653 
654  // //////////////////////////////////////////////////////////////////
656  : ParserSemanticAction (ioLocation) {
657  }
658 
659  // //////////////////////////////////////////////////////////////////
660  void storeCityUtfName::operator() (std::vector<uchar_t> iChar,
661  bsq::unused_type,
662  bsq::unused_type) const {
663 
664  const std::string lCityUtfNameStr (iChar.begin(), iChar.end());
665  const OPENTREP::CityUTFName_T lCityUtfName (lCityUtfNameStr);
666  _location.setCityUtfName (lCityUtfName);
667  // DEBUG
668  //OPENTREP_LOG_DEBUG ("City UTF8 name: " << _location.getCityUtfName());
669  }
670 
671  // //////////////////////////////////////////////////////////////////
673  : ParserSemanticAction (ioLocation) {
674  }
675 
676  // //////////////////////////////////////////////////////////////////
677  void storeCityAsciiName::operator() (std::vector<uchar_t> iChar,
678  bsq::unused_type,
679  bsq::unused_type) const {
680 
681  const std::string lCityAsciiNameStr (iChar.begin(), iChar.end());
682  const OPENTREP::CityASCIIName_T lCityAsciiName (lCityAsciiNameStr);
683  _location.setCityAsciiName (lCityAsciiName);
684  // DEBUG
685  //OPENTREP_LOG_DEBUG("City ASCII name: " << _location.getCityAsciiName());
686  }
687 
688  // //////////////////////////////////////////////////////////////////
690  : ParserSemanticAction (ioLocation) {
691  }
692 
693  // //////////////////////////////////////////////////////////////////
694  void storeCityGeonamesID::operator() (unsigned int iCtyId,
695  bsq::unused_type,
696  bsq::unused_type) const {
697 
698  _location.setCityGeonamesID (iCtyId);
699  // DEBUG
700  //OPENTREP_LOG_DEBUG ("City Geonames ID: " << _location.getCityGeonamesID());
701  }
702 
703  // //////////////////////////////////////////////////////////////////
705  : ParserSemanticAction (ioLocation) {
706  }
707 
708  // //////////////////////////////////////////////////////////////////
709  void storeStateCode::operator() (std::vector<uchar_t> iChar,
710  bsq::unused_type, bsq::unused_type) const {
711 
712  const std::string lStateCodeStr (iChar.begin(), iChar.end());
713  const OPENTREP::StateCode_T lStateCode (lStateCodeStr);
714  _location.setStateCode (lStateCode);
715  // DEBUG
716  //OPENTREP_LOG_DEBUG ("State code: " << _location.getStateCode());
717  }
718 
719  // //////////////////////////////////////////////////////////////////
721  : ParserSemanticAction (ioLocation) {
722  }
723 
724  // //////////////////////////////////////////////////////////////////
725  void storePORType::operator() (std::vector<uchar_t> iChar,
726  bsq::unused_type, bsq::unused_type) const {
727  const std::string lIATATypeStr (iChar.begin(), iChar.end());
728  const IATAType lIATAType (lIATATypeStr);
729  _location.setIataType (lIATAType);
730  // DEBUG
731  //OPENTREP_LOG_DEBUG ("IATA type: " << _location.getIataType());
732  }
733 
734  // //////////////////////////////////////////////////////////////////
736  : ParserSemanticAction (ioLocation) {
737  }
738 
739  // //////////////////////////////////////////////////////////////////
740  void storeWikiLink::operator() (std::vector<uchar_t> iChar,
741  bsq::unused_type, bsq::unused_type) const {
742 
743  const std::string lWikiLinkStr (iChar.begin(), iChar.end());
744  const OPENTREP::WikiLink_T lWikiLink (lWikiLinkStr);
745  _location.setWikiLink (lWikiLink);
746  // DEBUG
747  // OPENTREP_LOG_DEBUG ("Wiki link: " << _location.getWikiLink());
748  }
749 
750  // //////////////////////////////////////////////////////////////////
752  : ParserSemanticAction (ioLocation) {
753  }
754 
755  // //////////////////////////////////////////////////////////////////
756  void storeAltLangCodeFull::operator() (std::vector<uchar_t> iChar,
757  bsq::unused_type, bsq::unused_type) const {
758 
759  const std::string lAltLangCodeStr (iChar.begin(), iChar.end());
760  const OPENTREP::LanguageCode_T lAltLangCode (lAltLangCodeStr);
761  _location._itLanguageCode = lAltLangCode;
762  // DEBUG
763  //OPENTREP_LOG_DEBUG ("Alt lang full code: " << _location._itLanguageCode);
764  }
765 
766  // //////////////////////////////////////////////////////////////////
768  : ParserSemanticAction (ioLocation) {
769  }
770 
771  // //////////////////////////////////////////////////////////////////
772  void storeAltLangCode2Char::operator() (std::vector<uchar_t> iChar,
773  bsq::unused_type, bsq::unused_type) const {
774 
775  const std::string lAltLangCodeStr (iChar.begin(), iChar.end());
776  _location._itLangCode2Char = lAltLangCodeStr;
779  // DEBUG
780  //OPENTREP_LOG_DEBUG ("Alt lang 2-char code: " << _location._itLangCode2Char);
781  }
782 
783  // //////////////////////////////////////////////////////////////////
785  : ParserSemanticAction (ioLocation) {
786  }
787 
788  // //////////////////////////////////////////////////////////////////
789  void storeAltLangCodeExt::operator() (std::vector<uchar_t> iChar,
790  bsq::unused_type, bsq::unused_type) const {
791 
792  const std::string lAltLangCodeStr (iChar.begin(), iChar.end());
793  std::ostringstream oStr;
794  oStr << _location._itLangCode2Char << "-" << lAltLangCodeStr;
795  _location._itLangCodeExt = oStr.str();
796  // DEBUG
797  //OPENTREP_LOG_DEBUG ("Alt lang 2-char code: " << _location._itLangCodeExt);
798  }
799 
800  // //////////////////////////////////////////////////////////////////
802  : ParserSemanticAction (ioLocation) {
803  }
804 
805  // //////////////////////////////////////////////////////////////////
806  void storeAltLangCodeHist::operator() (std::vector<uchar_t> iChar,
807  bsq::unused_type, bsq::unused_type) const {
808 
809  const std::string lAltLangCodeStr (iChar.begin(), iChar.end());
810  std::ostringstream oStr;
811  oStr << _location._itLangCode2Char << "_" << lAltLangCodeStr;
812  _location._itLangCodeHist = oStr.str();
813  // DEBUG
814  //OPENTREP_LOG_DEBUG ("Alt lang 2-char code: " << _location._itLangCodeHist);
815  }
816 
817  // //////////////////////////////////////////////////////////////////
819  : ParserSemanticAction (ioLocation) {
820  }
821 
822  // //////////////////////////////////////////////////////////////////
823  void storeAltName::operator() (std::vector<uchar_t> iChar,
824  bsq::unused_type, bsq::unused_type) const {
825 
826  const std::string lAltNameStr (iChar.begin(), iChar.end());
827  const OPENTREP::AltNameShortListString_T lAltName (lAltNameStr);
828  //_location.addName (_location._itLanguageCodeNum, lAltName);
830  // Reset the values
831  //_location._itLanguageCodeNum = OPENTREP::Language::LAST_VALUE;
833  // DEBUG
834  //OPENTREP_LOG_DEBUG ("Alt name: " << _location.getAltNameShortList());
835  }
836 
837 
838  // //////////////////////////////////////////////////////////////////
840  : ParserSemanticAction (ioLocation) {
841  }
842 
843  // //////////////////////////////////////////////////////////////////
844  void doEndPor::operator() (bsq::unused_type,
845  bsq::unused_type, bsq::unused_type) const {
846  // DEBUG
847  //OPENTREP_LOG_DEBUG ("Do End. Location structure: " << _location);
848  }
849 
850  // ///////////////////////////////////////////////////////////////////
851  //
852  // Utility Parsers
853  //
854  // ///////////////////////////////////////////////////////////////////
855 
858 
861 
864 
867 
871 
874 
878 
883 
888 
891 
893  //
894  // (Boost Spirit) Grammar Definition
895  //
897 
1068  template <typename Iterator>
1069  struct LocationParser : public bsq::grammar<Iterator, bsu::blank_type> {
1070 
1071  LocationParser (Location& ioPORRule) :
1072  LocationParser::base_type(start), _location(ioPORRule) {
1073 
1074  start = bsq::eps
1075  >> *(header | por_rule);
1076 
1077  header = bsq::lit("iata_code") >> +(bsu::char_ - bsq::eoi - bsq::eol)
1078  >> (bsq::eoi | bsq::eol);
1079 
1080  por_rule = por_key
1081  >> '^' >> por_details
1082  >> '^' >> -alt_name_section
1084  // >> +( '^' >> segment )
1085 
1086  por_rule_end = bsq::eps;
1087 
1088  por_key = iata_code
1089  >> '^' >> -icao_code
1090  >> '^' >> -faa_code
1091  >> '^' >> is_geonames
1092  >> '^' >> geoname_id
1093  >> '^' >> -envelope_id
1094  ;
1095 
1097  >> '^' >> ascii_name
1098  >> '^' >> -latitude
1099  >> '^' >> -longitude
1100  >> '^' >> feat_class
1101  >> '^' >> feat_code
1102  >> '^' >> -page_rank
1103  >> '^' >> -date_from
1104  >> '^' >> -date_until
1105  >> '^' >> -comments
1106  >> '^' >> country_code
1107  >> '^' >> -country_code2
1108  >> '^' >> country_name
1109  >> '^' >> -continent_name
1110  >> '^' >> -adm1_code
1111  >> '^' >> -adm1_name_utf
1112  >> '^' >> -adm1_name_ascii
1113  >> '^' >> -adm2_code
1114  >> '^' >> -adm2_name_utf
1115  >> '^' >> -adm2_name_ascii
1116  >> '^' >> -adm3_code
1117  >> '^' >> -adm4_code
1118  >> '^' >> -population
1119  >> '^' >> -elevation
1120  >> '^' >> -gtopo30
1121  >> '^' >> -time_zone
1122  >> '^' >> -gmt_offset
1123  >> '^' >> -dst_offset
1124  >> '^' >> -raw_offset
1125  >> '^' >> (mod_date | bsq::lit("-1"))
1126  >> '^' >> city_code_list
1127  >> '^' >> -city_name_list
1128  >> '^' >> -city_detail_list
1130  >> '^' >> -state_code
1131  >> '^' >> por_type
1132  >> '^' >> -wiki_link
1133  ;
1134  // >> '^' >> -alt_name_short_list[storeAltNameShortListString(_location)]
1135 
1136  iata_code =
1137  bsq::repeat(3)[bsu::char_('A', 'Z')][storeIataCode(_location)];
1138 
1139  icao_code =
1140  bsq::repeat(4)[bsu::char_("A-Z0-9")][storeIcaoCode(_location)];
1141 
1142  faa_code =
1143  bsq::repeat(1,4)[bsu::char_("A-Z0-9")][storeFaaCode(_location)];
1144 
1146 
1147  envelope_id = uint1_4_p[storeEnvelopeID(_location)];
1148 
1150 
1151  common_name =
1152  (bsq::no_skip[+~bsu::char_('^')]
1153  - (bsq::eoi|bsq::eol))[storeCommonName(_location)]
1154  ;
1155 
1156  ascii_name =
1157  (bsq::no_skip[+~bsu::char_('^')]
1158  - (bsq::eoi|bsq::eol))[storeAsciiName(_location)]
1159  ;
1160 
1162 
1163  alt_name_short =
1164  (bsq::no_skip[+~bsu::char_("^,")]
1165  - (bsq::eoi|bsq::eol))[storeAltNameShort(_location)]
1166  ;
1167 
1169 
1170  tvl_por_code =
1171  (bsq::no_skip[+~bsu::char_("^,")]
1172  - (bsq::eoi|bsq::eol))[storeTvlPORCode(_location)]
1173  ;
1174 
1175  latitude = bsq::double_[storeLatitude(_location)];
1176 
1177  longitude = bsq::double_[storeLongitude(_location)];
1178 
1179  feat_class =
1180  bsq::repeat(1)[bsu::char_("A-Z")][storeFeatureClass(_location)]
1181  ;
1182 
1183  feat_code =
1184  bsq::repeat(2,5)[bsu::char_("A-Z1-5")][storeFeatureCode(_location)]
1185  ;
1186 
1187  page_rank = bsq::double_[storePageRank(_location)];
1188 
1190 
1192 
1193  comments =
1194  (bsq::no_skip[+~bsu::char_('^')]
1195  - (bsq::eoi|bsq::eol))[storeComments(_location)]
1196  ;
1197 
1198  country_code =
1199  bsq::repeat(2,3)[bsu::char_("A-Z")][storeCountryCode(_location)]
1200  ;
1201 
1202  country_code2 =
1203  (bsq::no_skip[+~bsu::char_('^')]
1204  - (bsq::eoi|bsq::eol))[storeAltCountryCode(_location)]
1205  ;
1206 
1207  country_name =
1208  (bsq::no_skip[+~bsu::char_('^')]
1209  - (bsq::eoi|bsq::eol))[storeCountryName(_location)]
1210  ;
1211 
1212  continent_name =
1213  (bsq::no_skip[+~bsu::char_('^')]
1214  - (bsq::eoi|bsq::eol))[storeContinentName(_location)]
1215  ;
1216 
1217  adm1_code =
1218  (bsq::no_skip[+~bsu::char_('^')]
1219  - (bsq::eoi|bsq::eol))[storeAdm1Code(_location)]
1220  ;
1221 
1222  adm1_name_utf =
1223  (bsq::no_skip[+~bsu::char_('^')]
1224  - (bsq::eoi|bsq::eol))[storeAdm1UtfName(_location)]
1225  ;
1226 
1227  adm1_name_ascii =
1228  (bsq::no_skip[+~bsu::char_('^')]
1229  - (bsq::eoi|bsq::eol))[storeAdm1AsciiName(_location)]
1230  ;
1231 
1232  adm2_code =
1233  (bsq::no_skip[+~bsu::char_('^')]
1234  - (bsq::eoi|bsq::eol))[storeAdm2Code(_location)]
1235  ;
1236 
1237  adm2_name_utf =
1238  (bsq::no_skip[+~bsu::char_('^')]
1239  - (bsq::eoi|bsq::eol))[storeAdm2UtfName(_location)]
1240  ;
1241 
1242  adm2_name_ascii =
1243  (bsq::no_skip[+~bsu::char_('^')]
1244  - (bsq::eoi|bsq::eol))[storeAdm2AsciiName(_location)]
1245  ;
1246 
1247  adm3_code =
1248  (bsq::no_skip[+~bsu::char_('^')]
1249  - (bsq::eoi|bsq::eol))[storeAdm3Code(_location)]
1250  ;
1251 
1252  adm4_code =
1253  (bsq::no_skip[+~bsu::char_('^')]
1254  - (bsq::eoi|bsq::eol))[storeAdm4Code(_location)]
1255  ;
1256 
1258 
1260 
1262 
1263  time_zone =
1264  (bsq::no_skip[+~bsu::char_('^')]
1265  - (bsq::eoi|bsq::eol))[storeTimeZone(_location)]
1266  ;
1267 
1268  gmt_offset = bsq::float_[storeGMTOffset(_location)];
1269 
1270  dst_offset = bsq::float_[storeDSTOffset(_location)];
1271 
1272  raw_offset = bsq::float_[storeRawOffset(_location)];
1273 
1275 
1276  date = bsq::lexeme
1277  [year_p[boost::phoenix::ref(_location._itYear) = bsq::labels::_1]
1278  >> '-'
1279  >> month_p[boost::phoenix::ref(_location._itMonth) = bsq::labels::_1]
1280  >> '-'
1281  >> day_p[boost::phoenix::ref(_location._itDay) = bsq::labels::_1] ];
1282 
1283  city_code_list = city_code % ',';
1284 
1285  city_code =
1286  bsq::repeat(3)[bsu::char_('A', 'Z')][storeCityCode(_location)]
1287  ;
1288 
1289  city_name_list = city_name_utf % '=';
1290 
1291  city_name_utf =
1292  (bsq::no_skip[+~bsu::char_("^|=")]
1293  - (bsq::eoi|bsq::eol))[storeCityUtfName(_location)]
1294  ;
1295 
1296  city_name_ascii =
1297  (bsq::no_skip[+~bsu::char_("^|=")]
1298  - (bsq::eoi|bsq::eol))[storeCityAsciiName(_location)]
1299  ;
1300 
1302 
1303  city_details =
1304  city_code
1305  >> '|' >> city_geoname_id
1306  >> '|' >> city_name_utf
1307  >> '|' >> city_name_ascii
1308  ;
1309 
1311 
1312  state_code =
1313  (bsq::no_skip[+~bsu::char_('^')]
1314  - (bsq::eoi|bsq::eol))[storeStateCode(_location)]
1315  ;
1316 
1317  por_type =
1318  bsq::repeat(1,3)[bsu::char_("ABCGHOPRZ")][storePORType(_location)]
1319  ;
1320 
1321  wiki_link =
1322  (bsq::no_skip[+~bsu::char_('^')]
1323  - (bsq::eoi|bsq::eol))[storeWikiLink(_location)]
1324  ;
1325 
1327 
1329  -alt_lang_code
1330  >> '|' >> alt_name
1331  >> '|' >> -alt_name_qualifiers
1332  ;
1333 
1334  alt_lang_code =
1335  (+~bsu::char_("|=")
1336  - (bsq::eoi|bsq::eol))[storeAltLangCodeFull(_location)]
1337  ;
1338 
1340 
1341  lang_code_opt = -(lang_code_ext | lang_code_hist);
1342 
1343  lang_code_2char =
1344  bsq::repeat(2,4)[bsu::char_("a-z")][storeAltLangCode2Char(_location)]
1345  ;
1346 
1347  lang_code_ext =
1348  '-' >> bsq::repeat(1,4)[bsu::char_('A', 'Z')][storeAltLangCodeExt(_location)];
1349 
1350  lang_code_hist =
1351  '_' >> bsq::repeat(1,4)[bsu::char_("a-z0-9")][storeAltLangCodeHist(_location)];
1352 
1353  alt_name =
1354  (bsq::no_skip[+~bsu::char_("|=")]
1355  - (bsq::eoi|bsq::eol))[storeAltName(_location)]
1356  ;
1357 
1358  alt_name_qualifiers =
1359  bsq::repeat(1,4)[bsu::char_("shpc")]
1360  ;
1361 
1362  //BOOST_SPIRIT_DEBUG_NODE (LocationParser);
1363  BOOST_SPIRIT_DEBUG_NODE (start);
1364  BOOST_SPIRIT_DEBUG_NODE (header);
1365  BOOST_SPIRIT_DEBUG_NODE (por_rule);
1366  BOOST_SPIRIT_DEBUG_NODE (por_rule_end);
1367  BOOST_SPIRIT_DEBUG_NODE (por_key);
1368  BOOST_SPIRIT_DEBUG_NODE (por_details);
1369  BOOST_SPIRIT_DEBUG_NODE (iata_code);
1370  BOOST_SPIRIT_DEBUG_NODE (icao_code);
1371  BOOST_SPIRIT_DEBUG_NODE (faa_code);
1372  BOOST_SPIRIT_DEBUG_NODE (geoname_id);
1373  BOOST_SPIRIT_DEBUG_NODE (envelope_id);
1374  BOOST_SPIRIT_DEBUG_NODE (is_geonames);
1375  BOOST_SPIRIT_DEBUG_NODE (common_name);
1376  BOOST_SPIRIT_DEBUG_NODE (ascii_name);
1377  BOOST_SPIRIT_DEBUG_NODE (alt_name_short_list);
1378  BOOST_SPIRIT_DEBUG_NODE (alt_name_short);
1379  BOOST_SPIRIT_DEBUG_NODE (alt_name_sep);
1380  BOOST_SPIRIT_DEBUG_NODE (tvl_por_code_list);
1381  BOOST_SPIRIT_DEBUG_NODE (tvl_por_code);
1382  BOOST_SPIRIT_DEBUG_NODE (tvl_por_sep);
1383  BOOST_SPIRIT_DEBUG_NODE (latitude);
1384  BOOST_SPIRIT_DEBUG_NODE (longitude);
1385  BOOST_SPIRIT_DEBUG_NODE (feat_class);
1386  BOOST_SPIRIT_DEBUG_NODE (feat_code);
1387  BOOST_SPIRIT_DEBUG_NODE (page_rank);
1388  BOOST_SPIRIT_DEBUG_NODE (date_from);
1389  BOOST_SPIRIT_DEBUG_NODE (date_until);
1390  BOOST_SPIRIT_DEBUG_NODE (comments);
1391  BOOST_SPIRIT_DEBUG_NODE (country_code);
1392  BOOST_SPIRIT_DEBUG_NODE (country_code2);
1393  BOOST_SPIRIT_DEBUG_NODE (country_name);
1394  BOOST_SPIRIT_DEBUG_NODE (continent_name);
1395  BOOST_SPIRIT_DEBUG_NODE (adm1_code);
1396  BOOST_SPIRIT_DEBUG_NODE (adm1_name_utf);
1397  BOOST_SPIRIT_DEBUG_NODE (adm1_name_ascii);
1398  BOOST_SPIRIT_DEBUG_NODE (adm2_code);
1399  BOOST_SPIRIT_DEBUG_NODE (adm2_name_utf);
1400  BOOST_SPIRIT_DEBUG_NODE (adm2_name_ascii);
1401  BOOST_SPIRIT_DEBUG_NODE (adm3_code);
1402  BOOST_SPIRIT_DEBUG_NODE (adm4_code);
1403  BOOST_SPIRIT_DEBUG_NODE (population);
1404  BOOST_SPIRIT_DEBUG_NODE (elevation);
1405  BOOST_SPIRIT_DEBUG_NODE (gtopo30);
1406  BOOST_SPIRIT_DEBUG_NODE (time_zone);
1407  BOOST_SPIRIT_DEBUG_NODE (gmt_offset);
1408  BOOST_SPIRIT_DEBUG_NODE (raw_offset);
1409  BOOST_SPIRIT_DEBUG_NODE (dst_offset);
1410  BOOST_SPIRIT_DEBUG_NODE (mod_date);
1411  BOOST_SPIRIT_DEBUG_NODE (date);
1412  BOOST_SPIRIT_DEBUG_NODE (city_code_list);
1413  BOOST_SPIRIT_DEBUG_NODE (city_name_list);
1414  BOOST_SPIRIT_DEBUG_NODE (city_detail_list);
1415  BOOST_SPIRIT_DEBUG_NODE (city_details);
1416  BOOST_SPIRIT_DEBUG_NODE (city_geoname_id);
1417  BOOST_SPIRIT_DEBUG_NODE (city_code);
1418  BOOST_SPIRIT_DEBUG_NODE (city_name_utf);
1419  BOOST_SPIRIT_DEBUG_NODE (city_name_ascii);
1420  BOOST_SPIRIT_DEBUG_NODE (state_code);
1421  BOOST_SPIRIT_DEBUG_NODE (por_type);
1422  BOOST_SPIRIT_DEBUG_NODE (wiki_link);
1423  BOOST_SPIRIT_DEBUG_NODE (alt_name_section);
1424  BOOST_SPIRIT_DEBUG_NODE (alt_name_details);
1425  BOOST_SPIRIT_DEBUG_NODE (alt_lang_code);
1426  BOOST_SPIRIT_DEBUG_NODE (alt_lang_code_ftd);
1427  BOOST_SPIRIT_DEBUG_NODE (alt_name);
1428  BOOST_SPIRIT_DEBUG_NODE (alt_name_qualifiers);
1429  BOOST_SPIRIT_DEBUG_NODE (lang_code_opt);
1430  BOOST_SPIRIT_DEBUG_NODE (lang_code_2char);
1431  BOOST_SPIRIT_DEBUG_NODE (lang_code_ext);
1432  BOOST_SPIRIT_DEBUG_NODE (lang_code_hist);
1433  }
1434 
1435  // Instantiation of rules
1436  bsq::rule<Iterator, bsu::blank_type>
1449  mod_date, date,
1453  state_code,
1458  destination;
1459 
1460  // Parser Context
1462  };
1463  }
1464 
1465 
1467  //
1468  // Entry class for the string parser
1469  //
1471 
1472  // //////////////////////////////////////////////////////////////////////
1473  PORStringParser::PORStringParser (const std::string& iString)
1474  : _string (iString) {
1475  init();
1476  }
1477 
1478  // //////////////////////////////////////////////////////////////////////
1479  void PORStringParser::init() {
1480  // Store the raw data string
1481  _location.setRawDataString (_string);
1482  }
1483 
1484  // //////////////////////////////////////////////////////////////////////
1486  }
1487 
1488  // //////////////////////////////////////////////////////////////////////
1490  // DEBUG
1491  // OPENTREP_LOG_DEBUG ("Parsing POR string: '" << _string << "'");
1492 
1493  // String to be parsed
1494  std::istringstream stringToBeParsed (_string);
1495 
1496  // Create an input iterator
1497  OPENTREP::base_iterator_t iStr (stringToBeParsed);
1498 
1499  // Convert input iterator to an iterator usable by spirit parser
1500  OPENTREP::iterator_t fwd_start(boost::spirit::make_default_multi_pass(iStr));
1501  OPENTREP::iterator_t fwd_end;
1502 
1503  // Initialise the positional iterators
1504  OPENTREP::pos_iterator_t pos_start (fwd_start, fwd_end, _string);
1505  OPENTREP::pos_iterator_t pos_end;
1506 
1507  // Initialise the parser (grammar) with the helper/staging structure.
1509 
1510  // Launch the parsing of the file and, thanks to the doEndPor
1511  // call-back structure, the building of the whole BomRoot BOM
1512  bool hasParsingBeenSuccesful = false;
1513  try {
1514 
1515  hasParsingBeenSuccesful = bsq::phrase_parse (fwd_start, fwd_end,
1516  lPORParser, bsu::blank);
1517 
1518  } catch (const bsq::expectation_failure<pos_iterator_t>& e) {
1519  const bsc::file_position_base<std::string>& pos = e.first.get_position();
1520  std::ostringstream oStr;
1521  oStr << "Parse error on POR string '" << _string
1522  << "', position " << pos.column << std::endl
1523  << "'" << e.first.get_currentline() << "'" << std::endl
1524  << std::setw(pos.column) << " " << "^- here";
1525  OPENTREP_LOG_ERROR (oStr.str());
1526  throw PorFileParsingException (oStr.str());
1527  }
1528 
1529  if (hasParsingBeenSuccesful == false) {
1530  OPENTREP_LOG_ERROR ("Parsing of POR input string: '" << _string
1531  << "' failed");
1532  throw PorFileParsingException ("Parsing of POR input string: '"
1533  + _string + "' failed");
1534  }
1535 
1536  if (fwd_start != fwd_end) {
1537  OPENTREP_LOG_ERROR ("Parsing of POR input string: '" << _string
1538  << "' failed");
1539  throw PorFileParsingException ("Parsing of POR input file: '"
1540  + _string + "' failed");
1541  }
1542 
1543  //
1544  if (hasParsingBeenSuccesful == true && fwd_start == fwd_end) {
1545  // DEBUG
1546  /*
1547  OPENTREP_LOG_DEBUG ("Parsing of POR input string: '" << _string
1548  << "' succeeded");
1549  */
1550  }
1551 
1552  return _location;
1553  }
1554 
1555 
1557  //
1558  // Entry class for the file parser
1559  //
1561 
1562  // //////////////////////////////////////////////////////////////////////
1564  : _filename (iFilename) {
1565  init();
1566  }
1567 
1568  // //////////////////////////////////////////////////////////////////////
1569  void PORFileParser::init() {
1570  }
1571 
1572  // //////////////////////////////////////////////////////////////////////
1574 
1575  OPENTREP_LOG_DEBUG ("Parsing por input file: " << _filename);
1576 
1577  // File to be parsed
1578  const char* lFilenameStr = _filename.c_str();
1579  std::ifstream fileToBeParsed (lFilenameStr, std::ios_base::in);
1580 
1581  // Check if the filename exist and can be open
1582  if (fileToBeParsed.is_open() == false) {
1583  OPENTREP_LOG_ERROR ("The por file " << _filename << " can not be open."
1584  << std::endl);
1585 
1586  throw FileNotFoundException ("The file " + _filename
1587  + " does not exist or can not be read");
1588  }
1589 
1590  // Create an input iterator
1591  OPENTREP::base_iterator_t iStr (fileToBeParsed);
1592 
1593  // Convert input iterator to an iterator usable by spirit parser
1594  OPENTREP::iterator_t start (boost::spirit::make_default_multi_pass (iStr));
1596 
1597  // Initialise the parser (grammar) with the helper/staging structure.
1599 
1600  // Launch the parsing of the file and, thanks to the doEndPor
1601  // call-back structure, the building of the whole BomRoot BOM
1602  const bool hasParsingBeenSuccesful =
1603  bsq::phrase_parse (start, end, lPORParser, bsu::blank);
1604 
1605  if (hasParsingBeenSuccesful == false) {
1606  OPENTREP_LOG_ERROR ("Parsing of por input file: " << _filename
1607  << " failed");
1608  throw PorFileParsingException ("Parsing of por input file: "
1609  + _filename + " failed");
1610  }
1611 
1612  if (start != end) {
1613  OPENTREP_LOG_ERROR ("Parsing of por input file: " << _filename
1614  << " failed");
1615  throw PorFileParsingException ("Parsing of por input file: "
1616  + _filename + " failed");
1617  }
1618 
1619  if (hasParsingBeenSuccesful == true && start == end) {
1620  OPENTREP_LOG_DEBUG ("Parsing of por input file: " << _filename
1621  << " succeeded");
1622  }
1623  }
1624 
1625 }
bsq::rule< Iterator, bsu::blank_type > alt_name_details
void setStateCode(const std::string &iStateCode)
Definition: Location.hpp:589
bsq::rule< Iterator, bsu::blank_type > adm3_code
TvlPORList_T _itTvlPORList
Definition: Location.hpp:1288
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > alt_name
bsq::rule< Iterator, bsu::blank_type > date_until
void setAdmin4Code(const std::string &iAdminCode)
Definition: Location.hpp:715
void setCityAsciiName(const std::string &iCityAsciiName)
Definition: Location.hpp:554
void operator()(double, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
#define OPENTREP_LOG_ERROR(iToBeLogged)
Definition: Logger.hpp:23
void setAltCountryCode(const std::string &iCountryCode)
Definition: Location.hpp:575
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void consolidateAltNameShortListString()
Definition: Location.cpp:313
#define OPENTREP_LOG_DEBUG(iToBeLogged)
Definition: Logger.hpp:32
OPENTREP::month_p_t month_p
void setFeatureCode(const std::string &iFeatCode)
Definition: Location.hpp:659
void setAdmin1AsciiName(const std::string &iAdminName)
Definition: Location.hpp:680
void operator()(std::vector< boost::uint32_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(unsigned int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setFeatureClass(const std::string &iFeatClass)
Definition: Location.hpp:652
void setGTopo30(const GTopo30_T &iGTopo30)
Definition: Location.hpp:736
void operator()(unsigned int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
boost::spirit::qi::uint_parser< month_t, 10, 2, 2 > month_p_t
bsq::rule< Iterator, bsu::blank_type > lang_code_ext
bsq::rule< Iterator, bsu::blank_type > tvl_por_code
std::istreambuf_iterator< char > base_iterator_t
std::string _itLangCodeExt
Definition: Location.hpp:1285
bsq::rule< Iterator, bsu::blank_type > continent_name
boost::spirit::qi::int_parser< int, 10, 0, 5 > int0_5_p_t
void operator()(int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
OPENTREP::uint0_9_p_t uint0_9_p
Date_T calculateDate() const
Definition: Location.cpp:307
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
boost::spirit::qi::uint_parser< second_t, 10, 2, 2 > second_p_t
void setCountryName(const std::string &iCountryName)
Definition: Location.hpp:582
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > adm2_name_utf
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
LanguageCode_T _itLanguageCode
Definition: Location.hpp:1283
boost::spirit::qi::uint_parser< hour_t, 10, 2, 2 > hour_p_t
bsq::rule< Iterator, bsu::blank_type > tvl_por_code_list
bsq::rule< Iterator, bsu::blank_type > alt_name_section
Structure modelling a (geographical) location.
Definition: Location.hpp:24
bsq::rule< Iterator, bsu::blank_type > latitude
bsq::rule< Iterator, bsu::blank_type > faa_code
void setEnvelopeID(const EnvelopeID_T &iEnvelopeID)
Definition: Location.hpp:512
void setLongitude(const Longitude_T &iLongitude)
Definition: Location.hpp:645
bsq::rule< Iterator, bsu::blank_type > iata_code
bsq::rule< Iterator, bsu::blank_type > city_name_utf
bsq::rule< Iterator, bsu::blank_type > feat_class
bsq::rule< Iterator, bsu::blank_type > dst_offset
boost::spirit::qi::uint_parser< int, 10, 2, 2 > uint2_p_t
bsq::rule< Iterator, bsu::blank_type > common_name
bsq::rule< Iterator, bsu::blank_type > alt_name_qualifiers
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > lang_code_2char
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
OPENTREP::uint1_4_p_t uint1_4_p
bsq::rule< Iterator, bsu::blank_type > city_code
bsq::rule< Iterator, bsu::blank_type > alt_name_short
OPENTREP::uint1_9_p_t uint1_9_p
bsq::rule< Iterator, bsu::blank_type > adm1_code
bsq::rule< Iterator, bsu::blank_type > city_name_list
boost::spirit::qi::uint_parser< int, 10, 1, 9 > uint1_9_p_t
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
OPENTREP::second_p_t second_p
PORStringParser(const std::string &iString)
boost::spirit::qi::int_parser< int, 10, 1, 5 > int1_5_p_t
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setGeonamesID(const GeonamesID_T &iGeonamesID)
Definition: Location.hpp:462
bsq::rule< Iterator, bsu::blank_type > gtopo30
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setFaaCode(const std::string &iFaaCode)
Definition: Location.hpp:476
bsq::rule< Iterator, bsu::blank_type > por_rule
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
boost::gregorian::date Date_T
bsq::rule< Iterator, bsu::blank_type > country_code2
OPENTREP::uint2_p_t uint2_p
void operator()(std::vector< boost::uint32_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setDSTOffset(const DSTOffset_T &iOffset)
Definition: Location.hpp:624
bsq::rule< Iterator, bsu::blank_type > por_rule_end
void setAdmin2AsciiName(const std::string &iAdminName)
Definition: Location.hpp:701
void operator()(float, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > geoname_id
bsq::rule< Iterator, bsu::blank_type > city_name_ascii
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
OPENTREP::minute_p_t minute_p
void setWikiLink(const std::string &iWikiLink)
Definition: Location.hpp:757
bsq::rule< Iterator, bsu::blank_type > icao_code
void setCountryCode(const std::string &iCountryCode)
Definition: Location.hpp:568
bsq::rule< Iterator, bsu::blank_type > date_from
OPENTREP::uint1_p_t uint1_p
bsq::rule< Iterator, bsu::blank_type > wiki_link
void setCityCode(const std::string &iCityCode)
Definition: Location.hpp:540
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > mod_date
bsq::rule< Iterator, bsu::blank_type > elevation
void setGMTOffset(const GMTOffset_T &iOffset)
Definition: Location.hpp:617
boost::spirit::qi::uint_parser< year_t, 10, 4, 4 > year_p_t
boost::spirit::qi::uint_parser< int, 10, 1, 1 > uint1_p_t
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setTimeZone(const std::string &iTimeZone)
Definition: Location.hpp:610
OPENTREP::boolean_p_t boolean_p
void setIcaoCode(const std::string &iIcaoCode)
Definition: Location.hpp:469
bsq::rule< Iterator, bsu::blank_type > por_type
bsq::rule< Iterator, bsu::blank_type > tvl_por_sep
boost::spirit::qi::bool_parser< bool, short_bool_policies > boolean_p_t
boost::spirit::qi::uint_parser< int, 10, 1, 2 > int1_2_p_t
void setModificationDate(const Date_T &iModDate)
Definition: Location.hpp:750
bsq::rule< Iterator, bsu::blank_type > population
bsq::rule< Iterator, bsu::blank_type > gmt_offset
void operator()(unsigned int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > ascii_name
bsq::rule< Iterator, bsu::blank_type > raw_offset
bsq::rule< Iterator, bsu::blank_type > city_code_list
bsq::rule< Iterator, bsu::blank_type > city_detail_list
void setCommonName(const std::string &iName)
Definition: Location.hpp:484
boost::spirit::qi::uint_parser< int, 10, 4, 4 > uint4_p_t
boost::spirit::qi::uint_parser< day_t, 10, 2, 2 > day_p_t
bsq::rule< Iterator, bsu::blank_type > destination
bsq::rule< Iterator, bsu::blank_type > state_code
void setAsciiName(const std::string &iName)
Definition: Location.hpp:491
bsq::rule< Iterator, bsu::blank_type > lang_code_hist
bsq::rule< Iterator, bsu::blank_type > adm4_code
AltNameShortList_T _itAltNameShortList
Definition: Location.hpp:1287
void setAdmin1UtfName(const std::string &iAdminName)
Definition: Location.hpp:673
bsq::rule< Iterator, bsu::blank_type > header
std::string _itLangCodeHist
Definition: Location.hpp:1286
OPENTREP::int1_2_p_t int1_2_p
bsq::rule< Iterator, bsu::blank_type > time_zone
void operator()(std::vector< boost::uint32_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
boost::spirit::qi::uint_parser< int, 10, 1, 4 > uint1_4_p_t
void setContinentName(const std::string &iContinentName)
Definition: Location.hpp:603
void operator()(double, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
OPENTREP::uint4_p_t uint4_p
bsq::rule< Iterator, bsu::blank_type > comments
void setIataCode(const std::string &iIataCode)
Definition: Location.hpp:448
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > por_key
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setAdmin3Code(const std::string &iAdminCode)
Definition: Location.hpp:708
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
boost::spirit::qi::uint_parser< minute_t, 10, 2, 2 > minute_p_t
void operator()(std::vector< boost::uint32_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > longitude
void setLatitude(const Latitude_T &iLatitude)
Definition: Location.hpp:638
bsq::rule< Iterator, bsu::blank_type > por_details
void setAdmin1Code(const std::string &iAdminCode)
Definition: Location.hpp:666
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
OPENTREP::int1_5_p_t int1_5_p
void setPageRank(const PageRank_T &iPageRank)
Definition: Location.hpp:743
void consolidateTvlPORListString()
Definition: Location.cpp:331
bsq::rule< Iterator, bsu::blank_type > adm1_name_ascii
bsq::rule< Iterator, bsu::blank_type > start
bsq::rule< Iterator, bsu::blank_type > adm1_name_utf
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
boost::spirit::multi_pass< base_iterator_t > iterator_t
void setCityGeonamesID(const GeonamesID_T &iGeonamesID)
Definition: Location.hpp:561
void operator()(double, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
boost::spirit::qi::uint_parser< int, 10, 0, 9 > uint0_9_p_t
Enumeration of output types.
Definition: IATAType.hpp:22
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< boost::uint32_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > date
boost::spirit::classic::position_iterator2< iterator_t > pos_iterator_t
void operator()(float, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > envelope_id
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setElevation(const Elevation_T &iElevation)
Definition: Location.hpp:729
void operator()(unsigned int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setCityUtfName(const std::string &iCityUtfName)
Definition: Location.hpp:547
bsq::rule< Iterator, bsu::blank_type > country_name
bsq::rule< Iterator, bsu::blank_type > alt_lang_code
PORFileParser(const PORFilePath_T &iFilename)
void setRawDataString(const std::string &iRawDataString)
Definition: Location.hpp:832
bsq::rule< Iterator, bsu::blank_type > is_geonames
void addName(const LanguageCode_T &iLanguageCode, const std::string &iName)
Definition: Location.hpp:767
bsq::rule< Iterator, bsu::blank_type > city_geoname_id
bsq::rule< Iterator, bsu::blank_type > country_code
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
const Location & generateLocation()
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(float, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
bsq::rule< Iterator, bsu::blank_type > city_details
bsq::rule< Iterator, bsu::blank_type > alt_name_sep
std::string _itLangCode2Char
Definition: Location.hpp:1284
bsq::rule< Iterator, bsu::blank_type > adm2_name_ascii
bsq::rule< Iterator, bsu::blank_type > page_rank
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< uchar_t >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void setRawOffset(const RawOffset_T &iOffset)
Definition: Location.hpp:631
void setAdmin2UtfName(const std::string &iAdminName)
Definition: Location.hpp:694
OPENTREP::int0_5_p_t int0_5_p
void setPopulation(const Population_T &iPopulation)
Definition: Location.hpp:722
bsq::rule< Iterator, bsu::blank_type > lang_code_opt
void setIataType(const IATAType &iIATAType)
Definition: Location.hpp:455
bsq::rule< Iterator, bsu::blank_type > adm2_code
bsq::rule< Iterator, bsu::blank_type > alt_lang_code_ftd
bsq::rule< Iterator, bsu::blank_type > alt_name_short_list
bsq::rule< Iterator, bsu::blank_type > feat_code
void setAdmin2Code(const std::string &iAdminCode)
Definition: Location.hpp:687