StdAir Logo  0.43.0
C++ Standard Airline IT Library
FlightDateKey.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // Boost Date-Time
00008 #include <boost/date_time/gregorian/formatters.hpp>
00009 // Boost.Serialization
00010 #include <boost/archive/text_iarchive.hpp>
00011 #include <boost/archive/text_oarchive.hpp>
00012 #include <boost/serialization/access.hpp>
00013 // StdAir
00014 #include <stdair/basic/BasConst_Inventory.hpp>
00015 #include <stdair/basic/BasConst_BomDisplay.hpp>
00016 #include <stdair/bom/FlightDateKey.hpp>
00017 
00018 namespace stdair {
00019 
00020   // ////////////////////////////////////////////////////////////////////
00021   FlightDateKey::FlightDateKey()
00022     : _flightNumber (DEFAULT_FLIGHT_NUMBER),
00023       _departureDate (DEFAULT_DEPARTURE_DATE) {
00024     assert (false);
00025   }
00026 
00027   // ////////////////////////////////////////////////////////////////////
00028   FlightDateKey::FlightDateKey (const FlightNumber_T& iFlightNumber,
00029                                 const Date_T& iFlightDate)
00030     : _flightNumber (iFlightNumber), _departureDate (iFlightDate) {
00031   }
00032 
00033   // ////////////////////////////////////////////////////////////////////
00034   FlightDateKey::FlightDateKey (const FlightDateKey& iKey)
00035     : _flightNumber (iKey._flightNumber), _departureDate (iKey._departureDate) {
00036   }
00037 
00038   // ////////////////////////////////////////////////////////////////////
00039   FlightDateKey::~FlightDateKey() {
00040   }
00041 
00042   // ////////////////////////////////////////////////////////////////////
00043   void FlightDateKey::toStream (std::ostream& ioOut) const {
00044     ioOut << "FlightDateKey: " << toString();
00045   }
00046 
00047   // ////////////////////////////////////////////////////////////////////
00048   void FlightDateKey::fromStream (std::istream& ioIn) {
00049   }
00050 
00051   // ////////////////////////////////////////////////////////////////////
00052   const std::string FlightDateKey::toString() const {
00053     std::ostringstream oStr;
00054     const std::string& lDepartureDateStr =
00055       boost::gregorian::to_simple_string (_departureDate);
00056     oStr << _flightNumber
00057          << DEFAULT_KEY_SUB_FLD_DELIMITER << " " << lDepartureDateStr;
00058     return oStr.str();
00059   }
00060 
00061   // ////////////////////////////////////////////////////////////////////
00062   void FlightDateKey::serialisationImplementation() {
00063     std::ostringstream oStr;
00064     boost::archive::text_oarchive oa (oStr);
00065     oa << *this;
00066 
00067     std::istringstream iStr;
00068     boost::archive::text_iarchive ia (iStr);
00069     ia >> *this;
00070   }
00071 
00072   // ////////////////////////////////////////////////////////////////////
00073   template<class Archive>
00074   void FlightDateKey::serialize (Archive& ioArchive,
00075                                  const unsigned int iFileVersion) {
00080     std::string lDepartureDateStr =
00081       boost::gregorian::to_simple_string (_departureDate);
00082     ioArchive & _flightNumber & lDepartureDateStr;
00083   }
00084 
00085   // ////////////////////////////////////////////////////////////////////
00086   // Explicit template instantiation
00087   namespace ba = boost::archive;
00088   template void FlightDateKey::serialize<ba::text_oarchive> (ba::text_oarchive&,
00089                                                              unsigned int);
00090   template void FlightDateKey::serialize<ba::text_iarchive> (ba::text_iarchive&,
00091                                                              unsigned int);
00092   // ////////////////////////////////////////////////////////////////////
00093   
00094 }