$treeview $search $mathjax
StdAir Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

stdair/bom/EventStruct.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // Boost
00007 #if BOOST_VERSION >= 103900
00008 #include <boost/make_shared.hpp>
00009 #else  // BOOST_VERSION >= 103900
00010 #include <boost/shared_ptr.hpp>
00011 #endif // BOOST_VERSION >= 103900
00012 // StdAir
00013 #include <stdair/basic/BasConst_General.hpp>
00014 #include <stdair/basic/BasConst_Event.hpp>
00015 #include <stdair/bom/BookingRequestStruct.hpp>
00016 #include <stdair/bom/OptimisationNotificationStruct.hpp>
00017 #include <stdair/bom/SnapshotStruct.hpp>
00018 #include <stdair/bom/CancellationStruct.hpp>
00019 #include <stdair/bom/RMEventStruct.hpp>
00020 #include <stdair/bom/BreakPointStruct.hpp>
00021 #include <stdair/bom/EventStruct.hpp>
00022 
00023 namespace stdair {
00024 
00025   // //////////////////////////////////////////////////////////////////////
00026   EventStruct::EventStruct()
00027     : _eventType (EventType::BKG_REQ), _eventTimeStamp (0) {
00028   }
00029   
00030   // //////////////////////////////////////////////////////////////////////
00031   EventStruct::EventStruct (const EventType::EN_EventType& iEventType,
00032                             BookingRequestPtr_T ioRequestPtr)
00033     : _eventType (iEventType) {
00034 
00035     //
00036     assert (ioRequestPtr != NULL);
00037 #if BOOST_VERSION >= 103900
00038     _bookingRequest = boost::make_shared<BookingRequestStruct> (*ioRequestPtr);
00039 #else  // BOOST_VERSION >= 103900
00040     _bookingRequest = ioRequestPtr;
00041 #endif // BOOST_VERSION >= 103900
00042     assert (_bookingRequest != NULL);
00043     
00049     const Duration_T lDuration =
00050       _bookingRequest->getRequestDateTime() - DEFAULT_EVENT_OLDEST_DATETIME;
00051     _eventTimeStamp = lDuration.total_milliseconds();
00052   }
00053   
00054   // //////////////////////////////////////////////////////////////////////
00055   EventStruct::EventStruct (const EventType::EN_EventType& iEventType,
00056                             CancellationPtr_T ioCancellationPtr)
00057     : _eventType (iEventType) {
00058 
00059     //
00060     assert (ioCancellationPtr != NULL);
00061 #if BOOST_VERSION >= 103900
00062     _cancellation = boost::make_shared<CancellationStruct> (*ioCancellationPtr);
00063 #else  // BOOST_VERSION >= 103900
00064     _cancellation = ioCancellationPtr;
00065 #endif // BOOST_VERSION >= 103900
00066     assert (_cancellation != NULL);
00067     
00073     const Duration_T lDuration =
00074       _cancellation->getCancellationDateTime() - DEFAULT_EVENT_OLDEST_DATETIME;
00075     _eventTimeStamp = lDuration.total_milliseconds();
00076   }
00077 
00078   // //////////////////////////////////////////////////////////////////////
00079   EventStruct::
00080   EventStruct (const EventType::EN_EventType& iEventType,
00081                const DateTime_T& iDCPDate,
00082                OptimisationNotificationPtr_T ioOptimisationNotificationPtr)
00083     : _eventType (iEventType) {
00084 
00085     //
00086     assert (ioOptimisationNotificationPtr != NULL);
00087 #if BOOST_VERSION >= 103900
00088     _optimisationNotification =
00089       boost::make_shared<OptimisationNotificationStruct> (*ioOptimisationNotificationPtr);
00090 #else  // BOOST_VERSION >= 103900
00091     _optimisationNotification = ioOptimisationNotificationPtr;
00092 #endif // BOOST_VERSION >= 103900
00093     assert (_optimisationNotification != NULL);
00094     
00100     const Duration_T lDuration = iDCPDate - DEFAULT_EVENT_OLDEST_DATETIME;
00101     _eventTimeStamp = lDuration.total_milliseconds();
00102   }
00103   
00104   // //////////////////////////////////////////////////////////////////////
00105   EventStruct::EventStruct (const EventType::EN_EventType& iEventType,
00106                             SnapshotPtr_T ioSnapshotPtr)
00107     : _eventType (iEventType) {
00108 
00109     //
00110     assert (ioSnapshotPtr != NULL);
00111 
00112 #if BOOST_VERSION >= 103900
00113     _snapshot = boost::make_shared<SnapshotStruct> (*ioSnapshotPtr);
00114 #else  // BOOST_VERSION >= 103900
00115     _snapshot = ioSnapshotPtr;
00116 #endif // BOOST_VERSION >= 103900
00117     assert (_snapshot != NULL);
00118     
00124     const Duration_T lDuration =
00125       _snapshot->getSnapshotTime() - DEFAULT_EVENT_OLDEST_DATETIME;
00126     _eventTimeStamp = lDuration.total_milliseconds();
00127   }
00128   
00129   // //////////////////////////////////////////////////////////////////////
00130   EventStruct::EventStruct (const EventType::EN_EventType& iEventType,
00131                             RMEventPtr_T ioRMEventPtr)
00132     : _eventType (iEventType) {
00133 
00134     //
00135     assert (ioRMEventPtr != NULL);
00136 
00137 #if BOOST_VERSION >= 103900
00138     _rmEvent = boost::make_shared<RMEventStruct> (*ioRMEventPtr);
00139 #else  // BOOST_VERSION >= 103900
00140     _rmEvent = ioRMEventPtr;
00141 #endif // BOOST_VERSION >= 103900
00142     assert (_rmEvent != NULL);
00143     
00149     const Duration_T lDuration =
00150       _rmEvent->getRMEventTime() - DEFAULT_EVENT_OLDEST_DATETIME;
00151     _eventTimeStamp = lDuration.total_milliseconds();
00152   }  
00153 
00154   // //////////////////////////////////////////////////////////////////////
00155   EventStruct::EventStruct (const EventType::EN_EventType& iEventType,
00156                             BreakPointPtr_T ioBreakPointPtr)
00157     : _eventType (iEventType) {
00158 
00159     //
00160     assert (ioBreakPointPtr != NULL);
00161 
00162 #if BOOST_VERSION >= 103900
00163     _breakPoint = boost::make_shared<BreakPointStruct> (*ioBreakPointPtr);
00164 #else  // BOOST_VERSION >= 103900
00165     _breakPoint = ioBreakPointPtr;
00166 #endif // BOOST_VERSION >= 103900
00167     assert (_breakPoint != NULL);
00168     
00174     const Duration_T lDuration =
00175       _breakPoint->getBreakPointTime() - DEFAULT_EVENT_OLDEST_DATETIME;
00176     _eventTimeStamp = lDuration.total_milliseconds();
00177   }
00178 
00179   // //////////////////////////////////////////////////////////////////////
00180   EventStruct::EventStruct (const EventStruct& iEventStruct)
00181     : _eventType (iEventStruct._eventType),
00182       _eventTimeStamp (iEventStruct._eventTimeStamp) {
00183 
00184     //
00185     if (iEventStruct._bookingRequest != NULL) {
00186 #if BOOST_VERSION >= 103900
00187       _bookingRequest =
00188         boost::make_shared<BookingRequestStruct>(*iEventStruct._bookingRequest);
00189 #else  // BOOST_VERSION >= 103900
00190       _bookingRequest = iEventStruct._bookingRequest;
00191 #endif // BOOST_VERSION >= 103900
00192     }
00193 
00194     //
00195     if (iEventStruct._cancellation != NULL) {
00196 #if BOOST_VERSION >= 103900
00197       _cancellation =
00198         boost::make_shared<CancellationStruct>(*iEventStruct._cancellation);
00199 #else  // BOOST_VERSION >= 103900
00200       _cancellation = iEventStruct._cancellation;
00201 #endif // BOOST_VERSION >= 103900
00202     }
00203 
00204     //
00205     if (iEventStruct._optimisationNotification != NULL) {
00206 #if BOOST_VERSION >= 103900
00207       _optimisationNotification =
00208         boost::make_shared<OptimisationNotificationStruct> (*iEventStruct._optimisationNotification);
00209 #else  // BOOST_VERSION >= 103900
00210       _optimisationNotification = iEventStruct._optimisationNotification;
00211 #endif // BOOST_VERSION >= 103900
00212     }
00213 
00214     //
00215     if (iEventStruct._snapshot != NULL) {
00216 #if BOOST_VERSION >= 103900
00217       _snapshot = boost::make_shared<SnapshotStruct> (*iEventStruct._snapshot);
00218 #else  // BOOST_VERSION >= 103900
00219       _snapshot = iEventStruct._snapshot;
00220 #endif // BOOST_VERSION >= 103900
00221     }
00222 
00223     //
00224     if (iEventStruct._rmEvent != NULL) {
00225 #if BOOST_VERSION >= 103900
00226       _rmEvent = boost::make_shared<RMEventStruct> (*iEventStruct._rmEvent);
00227 #else  // BOOST_VERSION >= 103900
00228       _rmEvent = iEventStruct._rmEvent;
00229 #endif // BOOST_VERSION >= 103900
00230     } 
00231 
00232     //
00233     if (iEventStruct._breakPoint != NULL) {
00234 #if BOOST_VERSION >= 103900
00235       _breakPoint = boost::make_shared<BreakPointStruct> (*iEventStruct._breakPoint);
00236 #else  // BOOST_VERSION >= 103900
00237       _breakPoint = iEventStruct._breakPoint;
00238 #endif // BOOST_VERSION >= 103900
00239     }
00240   }
00241   
00242   // //////////////////////////////////////////////////////////////////////
00243   EventStruct::~EventStruct() {
00244   }
00245 
00246   // //////////////////////////////////////////////////////////////////////
00247   void EventStruct::fromStream (std::istream& ioIn) {
00248   }
00249 
00250   // //////////////////////////////////////////////////////////////////////
00251   const std::string EventStruct::describe() const {
00252     std::ostringstream oStr;
00253 
00254     //
00255     const Duration_T lEventDateTimeDelta =
00256       boost::posix_time::milliseconds (_eventTimeStamp);
00257     const DateTime_T lEventDateTime (DEFAULT_EVENT_OLDEST_DATETIME
00258                                    + lEventDateTimeDelta);
00259 
00260     oStr << lEventDateTime;
00261 
00262     //
00263     switch (_eventType) {
00264     case EventType::BKG_REQ: {
00265       assert (_bookingRequest != NULL);
00266       oStr << ", " << EventType::getLabel(_eventType)
00267            << ", " << _bookingRequest->describe();
00268       break;
00269     }
00270     case EventType::CX: {
00271       assert (_cancellation != NULL);
00272       oStr << ", " << EventType::getLabel(_eventType)
00273            << ", " << _cancellation->describe();
00274       break;
00275     }
00276     case EventType::OPT_NOT_4_FD: {
00277       assert (_optimisationNotification != NULL);
00278       oStr << ", " << EventType::getLabel(_eventType)
00279            << ", " << _optimisationNotification->describe();
00280       break;
00281     }
00282     case EventType::SNAPSHOT: {
00283       assert (_snapshot != NULL);
00284       oStr << ", " << EventType::getLabel(_eventType)
00285          << ", " << _snapshot->describe();
00286       break;
00287     }
00288     case EventType::RM: {
00289       assert (_rmEvent != NULL);
00290       oStr << ", " << EventType::getLabel(_eventType)
00291          << ", " << _rmEvent->describe();
00292       break;
00293     } 
00294     case EventType::BRK_PT: {
00295       assert (_breakPoint != NULL);
00296       oStr << ", " << EventType::getLabel(_eventType)
00297            << ", " << _breakPoint->describe(); 
00298       break;
00299     }
00300     default: {
00301       oStr << ", " << _eventType << " (not yet recognised)";
00302       break;
00303     }
00304     }
00305     
00306     oStr << "\n";
00307     return oStr.str();
00308   }   
00309 
00310   // //////////////////////////////////////////////////////////////////////
00311   const DateTime_T& EventStruct::getEventTime() const {
00312     const DateTime_T& lDateTime (DEFAULT_EVENT_OLDEST_DATETIME);
00313 
00314     //
00315     switch (_eventType) {
00316     case EventType::BKG_REQ: {
00317       assert (_bookingRequest != NULL);
00318       return _bookingRequest->getRequestDateTime();
00319       break;
00320     }
00321     case EventType::CX: {
00322       assert (_cancellation != NULL);
00323       return _cancellation->getCancellationDateTime() ;
00324       break;
00325     }
00326     case EventType::OPT_NOT_4_FD: {
00327       assert (_optimisationNotification != NULL);
00328       return _optimisationNotification->getNotificationDateTime();
00329       break;
00330     }
00331     case EventType::SNAPSHOT: {
00332       assert (_snapshot != NULL);
00333       return _snapshot->getSnapshotTime();
00334       break;
00335     }
00336     case EventType::RM: {
00337       assert (_rmEvent != NULL);
00338       return _rmEvent->getRMEventTime();
00339       break;
00340     } 
00341     case EventType::BRK_PT: {
00342       assert (_breakPoint != NULL);
00343       return _breakPoint->getBreakPointTime();
00344       break;
00345     }
00346     default: {
00347       assert(false); 
00348       return lDateTime;
00349       break;
00350     }
00351     }
00352 
00353     return lDateTime;
00354   } 
00355 
00356   // //////////////////////////////////////////////////////////////////////
00357   void EventStruct::incrementEventTimeStamp() {
00358     // The date-time is counted in milliseconds (1e-3 second). Hence,
00359     // one thousand (1e3) of attempts correspond to 1 second.
00360     // Increment the time stamp of one millisecond.
00361     ++_eventTimeStamp;
00362   }
00363 
00364 }