StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
FlightDateKey.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // Boost Date-Time
8 #include <boost/date_time/gregorian/formatters.hpp>
9 // Boost.Serialization
10 #include <boost/archive/text_iarchive.hpp>
11 #include <boost/archive/text_oarchive.hpp>
12 #include <boost/serialization/access.hpp>
13 // StdAir
17 
18 namespace stdair {
19 
20  // ////////////////////////////////////////////////////////////////////
21  FlightDateKey::FlightDateKey()
22  : _flightNumber (DEFAULT_FLIGHT_NUMBER),
23  _departureDate (DEFAULT_DEPARTURE_DATE) {
24  assert (false);
25  }
26 
27  // ////////////////////////////////////////////////////////////////////
28  FlightDateKey::FlightDateKey (const FlightNumber_T& iFlightNumber,
29  const Date_T& iFlightDate)
30  : _flightNumber (iFlightNumber), _departureDate (iFlightDate) {
31  }
32 
33  // ////////////////////////////////////////////////////////////////////
34  FlightDateKey::FlightDateKey (const FlightDateKey& iKey)
35  : _flightNumber (iKey._flightNumber), _departureDate (iKey._departureDate) {
36  }
37 
38  // ////////////////////////////////////////////////////////////////////
40  }
41 
42  // ////////////////////////////////////////////////////////////////////
43  void FlightDateKey::toStream (std::ostream& ioOut) const {
44  ioOut << "FlightDateKey: " << toString();
45  }
46 
47  // ////////////////////////////////////////////////////////////////////
48  void FlightDateKey::fromStream (std::istream& ioIn) {
49  }
50 
51  // ////////////////////////////////////////////////////////////////////
52  const std::string FlightDateKey::toString() const {
53  std::ostringstream oStr;
54  const std::string& lDepartureDateStr =
55  boost::gregorian::to_iso_extended_string (_departureDate);
56  oStr << _flightNumber
57  << DEFAULT_KEY_SUB_FLD_DELIMITER << " " << lDepartureDateStr;
58  return oStr.str();
59  }
60 
61  // ////////////////////////////////////////////////////////////////////
62  void FlightDateKey::serialisationImplementationExport() const {
63  std::ostringstream oStr;
64  boost::archive::text_oarchive oa (oStr);
65  oa << *this;
66  }
67 
68  // ////////////////////////////////////////////////////////////////////
69  void FlightDateKey::serialisationImplementationImport() {
70  std::istringstream iStr;
71  boost::archive::text_iarchive ia (iStr);
72  ia >> *this;
73  }
74 
75  // ////////////////////////////////////////////////////////////////////
76  template<class Archive>
77  void FlightDateKey::serialize (Archive& ioArchive,
78  const unsigned int iFileVersion) {
83  std::string lDepartureDateStr =
84  boost::gregorian::to_simple_string (_departureDate);
85  ioArchive & _flightNumber & lDepartureDateStr;
86  }
87 
88  // ////////////////////////////////////////////////////////////////////
89  // Explicit template instantiation
90  namespace ba = boost::archive;
91  template void FlightDateKey::serialize<ba::text_oarchive> (ba::text_oarchive&,
92  unsigned int);
93  template void FlightDateKey::serialize<ba::text_iarchive> (ba::text_iarchive&,
94  unsigned int);
95  // ////////////////////////////////////////////////////////////////////
96 
97 }
const std::string DEFAULT_KEY_SUB_FLD_DELIMITER
const Date_T DEFAULT_DEPARTURE_DATE
unsigned short FlightNumber_T
Handle on the StdAir library context.
void toStream(std::ostream &ioOut) const
Key of a given flight-date, made of a flight number and a departure date.
void fromStream(std::istream &ioIn)
void serialize(Archive &ar, const unsigned int iFileVersion)
boost::gregorian::date Date_T
const FlightNumber_T DEFAULT_FLIGHT_NUMBER
const std::string toString() const