StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
BomKeyManager.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // Boost
00008 #include <boost/tokenizer.hpp>
00009 #include <boost/lexical_cast.hpp>
00010 #include <boost/date_time/gregorian/parsers.hpp>
00011 // StdAir
00012 #include <stdair/stdair_exceptions.hpp>
00013 #include <stdair/basic/BasConst_BomDisplay.hpp>
00014 #include <stdair/bom/InventoryKey.hpp>
00015 #include <stdair/bom/FlightDateKey.hpp>
00016 #include <stdair/bom/SegmentDateKey.hpp>
00017 #include <stdair/bom/ParsedKey.hpp>
00018 #include <stdair/bom/BomKeyManager.hpp>
00019 #include <stdair/service/Logger.hpp>
00020 
00021 namespace stdair {
00022 
00023   // ////////////// Tokenising support ///////////////
00027   typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T;
00028 
00029   // ////////////////////////////////////////////////////////////////////
00030   ParsedKey BomKeyManager::extractKeys (const std::string& iFullKeyStr) {
00031     ParsedKey oParsedKey;
00032     oParsedKey._fullKey = iFullKeyStr;
00033 
00034     // Token-ise the full key string
00035     Tokeniser_T lTokens (iFullKeyStr, DEFAULT_KEY_TOKEN_DELIMITER);
00036     Tokeniser_T::iterator itToken = lTokens.begin();
00037 
00038     // Airline code
00039     if (itToken != lTokens.end()) {
00040       oParsedKey._airlineCode = *itToken;
00041       
00042     // Flight number
00043       ++itToken;
00044       if (itToken != lTokens.end()) {
00045         oParsedKey._flightNumber = *itToken;
00046 
00047         // Departure date
00048         ++itToken;
00049         if (itToken != lTokens.end()) {
00050           oParsedKey._departureDate = *itToken;
00051 
00052           // Origin
00053           ++itToken;
00054           if (itToken != lTokens.end()) {
00055             oParsedKey._boardingPoint = *itToken;
00056 
00057             // Destination
00058             ++itToken;
00059             if (itToken != lTokens.end()) {
00060               oParsedKey._offPoint = *itToken;
00061 
00062               // Boarding time
00063               ++itToken;
00064               if (itToken != lTokens.end()) {
00065                 oParsedKey._boardingTime = *itToken;
00066               }
00067             }
00068           }
00069         }
00070       }
00071     }
00072 
00073     return oParsedKey;
00074   }
00075 
00076   // ////////////////////////////////////////////////////////////////////
00077   InventoryKey BomKeyManager::
00078   extractInventoryKey (const std::string& iFullKeyStr) {
00079     ParsedKey lParsedKey = extractKeys (iFullKeyStr);
00080 
00081     return lParsedKey.getInventoryKey();
00082   }
00083 
00084   // ////////////////////////////////////////////////////////////////////
00085   FlightDateKey BomKeyManager::
00086   extractFlightDateKey (const std::string& iFullKeyStr) {
00087     ParsedKey lParsedKey = extractKeys (iFullKeyStr);
00088 
00089     return lParsedKey.getFlightDateKey();
00090   }
00091 
00092   // ////////////////////////////////////////////////////////////////////
00093   SegmentDateKey BomKeyManager::
00094   extractSegmentDateKey (const std::string& iFullKeyStr) {
00095     ParsedKey lParsedKey = extractKeys (iFullKeyStr);
00096 
00097     return lParsedKey.getSegmentKey();
00098   }
00099 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines