StdAir Logo  1.00.0
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventStruct.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // Boost
7 #if BOOST_VERSION >= 103900
8 #include <boost/make_shared.hpp>
9 #else // BOOST_VERSION >= 103900
10 #include <boost/shared_ptr.hpp>
11 #endif // BOOST_VERSION >= 103900
12 // StdAir
22 
23 namespace stdair {
24 
25  // //////////////////////////////////////////////////////////////////////
27  : _eventType (EventType::BKG_REQ), _eventTimeStamp (0) {
28  }
29 
30  // //////////////////////////////////////////////////////////////////////
32  BookingRequestPtr_T ioRequestPtr)
33  : _eventType (iEventType) {
34 
35  //
36  assert (ioRequestPtr != NULL);
37 #if BOOST_VERSION >= 103900
38  _bookingRequest = boost::make_shared<BookingRequestStruct> (*ioRequestPtr);
39 #else // BOOST_VERSION >= 103900
40  _bookingRequest = ioRequestPtr;
41 #endif // BOOST_VERSION >= 103900
42  assert (_bookingRequest != NULL);
43 
49  const Duration_T lDuration =
50  _bookingRequest->getRequestDateTime() - DEFAULT_EVENT_OLDEST_DATETIME;
51  _eventTimeStamp = lDuration.total_milliseconds();
52  }
53 
54  // //////////////////////////////////////////////////////////////////////
56  CancellationPtr_T ioCancellationPtr)
57  : _eventType (iEventType) {
58 
59  //
60  assert (ioCancellationPtr != NULL);
61 #if BOOST_VERSION >= 103900
62  _cancellation = boost::make_shared<CancellationStruct> (*ioCancellationPtr);
63 #else // BOOST_VERSION >= 103900
64  _cancellation = ioCancellationPtr;
65 #endif // BOOST_VERSION >= 103900
66  assert (_cancellation != NULL);
67 
73  const Duration_T lDuration =
74  _cancellation->getCancellationDateTime() - DEFAULT_EVENT_OLDEST_DATETIME;
75  _eventTimeStamp = lDuration.total_milliseconds();
76  }
77 
78  // //////////////////////////////////////////////////////////////////////
81  const DateTime_T& iDCPDate,
82  OptimisationNotificationPtr_T ioOptimisationNotificationPtr)
83  : _eventType (iEventType) {
84 
85  //
86  assert (ioOptimisationNotificationPtr != NULL);
87 #if BOOST_VERSION >= 103900
88  _optimisationNotification =
89  boost::make_shared<OptimisationNotificationStruct> (*ioOptimisationNotificationPtr);
90 #else // BOOST_VERSION >= 103900
91  _optimisationNotification = ioOptimisationNotificationPtr;
92 #endif // BOOST_VERSION >= 103900
93  assert (_optimisationNotification != NULL);
94 
100  const Duration_T lDuration = iDCPDate - DEFAULT_EVENT_OLDEST_DATETIME;
101  _eventTimeStamp = lDuration.total_milliseconds();
102  }
103 
104  // //////////////////////////////////////////////////////////////////////
106  SnapshotPtr_T ioSnapshotPtr)
107  : _eventType (iEventType) {
108 
109  //
110  assert (ioSnapshotPtr != NULL);
111 
112 #if BOOST_VERSION >= 103900
113  _snapshot = boost::make_shared<SnapshotStruct> (*ioSnapshotPtr);
114 #else // BOOST_VERSION >= 103900
115  _snapshot = ioSnapshotPtr;
116 #endif // BOOST_VERSION >= 103900
117  assert (_snapshot != NULL);
118 
124  const Duration_T lDuration =
125  _snapshot->getSnapshotTime() - DEFAULT_EVENT_OLDEST_DATETIME;
126  _eventTimeStamp = lDuration.total_milliseconds();
127  }
128 
129  // //////////////////////////////////////////////////////////////////////
131  RMEventPtr_T ioRMEventPtr)
132  : _eventType (iEventType) {
133 
134  //
135  assert (ioRMEventPtr != NULL);
136 
137 #if BOOST_VERSION >= 103900
138  _rmEvent = boost::make_shared<RMEventStruct> (*ioRMEventPtr);
139 #else // BOOST_VERSION >= 103900
140  _rmEvent = ioRMEventPtr;
141 #endif // BOOST_VERSION >= 103900
142  assert (_rmEvent != NULL);
143 
149  const Duration_T lDuration =
150  _rmEvent->getRMEventTime() - DEFAULT_EVENT_OLDEST_DATETIME;
151  _eventTimeStamp = lDuration.total_milliseconds();
152  }
153 
154  // //////////////////////////////////////////////////////////////////////
156  BreakPointPtr_T ioBreakPointPtr)
157  : _eventType (iEventType) {
158 
159  //
160  assert (ioBreakPointPtr != NULL);
161 
162 #if BOOST_VERSION >= 103900
163  _breakPoint = boost::make_shared<BreakPointStruct> (*ioBreakPointPtr);
164 #else // BOOST_VERSION >= 103900
165  _breakPoint = ioBreakPointPtr;
166 #endif // BOOST_VERSION >= 103900
167  assert (_breakPoint != NULL);
168 
174  const Duration_T lDuration =
175  _breakPoint->getBreakPointTime() - DEFAULT_EVENT_OLDEST_DATETIME;
176  _eventTimeStamp = lDuration.total_milliseconds();
177  }
178 
179  // //////////////////////////////////////////////////////////////////////
180  EventStruct::EventStruct (const EventStruct& iEventStruct)
181  : _eventType (iEventStruct._eventType),
182  _eventTimeStamp (iEventStruct._eventTimeStamp) {
183 
184  //
185  if (iEventStruct._bookingRequest != NULL) {
186 #if BOOST_VERSION >= 103900
187  _bookingRequest =
188  boost::make_shared<BookingRequestStruct>(*iEventStruct._bookingRequest);
189 #else // BOOST_VERSION >= 103900
190  _bookingRequest = iEventStruct._bookingRequest;
191 #endif // BOOST_VERSION >= 103900
192  }
193 
194  //
195  if (iEventStruct._cancellation != NULL) {
196 #if BOOST_VERSION >= 103900
197  _cancellation =
198  boost::make_shared<CancellationStruct>(*iEventStruct._cancellation);
199 #else // BOOST_VERSION >= 103900
200  _cancellation = iEventStruct._cancellation;
201 #endif // BOOST_VERSION >= 103900
202  }
203 
204  //
205  if (iEventStruct._optimisationNotification != NULL) {
206 #if BOOST_VERSION >= 103900
207  _optimisationNotification =
208  boost::make_shared<OptimisationNotificationStruct> (*iEventStruct._optimisationNotification);
209 #else // BOOST_VERSION >= 103900
210  _optimisationNotification = iEventStruct._optimisationNotification;
211 #endif // BOOST_VERSION >= 103900
212  }
213 
214  //
215  if (iEventStruct._snapshot != NULL) {
216 #if BOOST_VERSION >= 103900
217  _snapshot = boost::make_shared<SnapshotStruct> (*iEventStruct._snapshot);
218 #else // BOOST_VERSION >= 103900
219  _snapshot = iEventStruct._snapshot;
220 #endif // BOOST_VERSION >= 103900
221  }
222 
223  //
224  if (iEventStruct._rmEvent != NULL) {
225 #if BOOST_VERSION >= 103900
226  _rmEvent = boost::make_shared<RMEventStruct> (*iEventStruct._rmEvent);
227 #else // BOOST_VERSION >= 103900
228  _rmEvent = iEventStruct._rmEvent;
229 #endif // BOOST_VERSION >= 103900
230  }
231 
232  //
233  if (iEventStruct._breakPoint != NULL) {
234 #if BOOST_VERSION >= 103900
235  _breakPoint = boost::make_shared<BreakPointStruct> (*iEventStruct._breakPoint);
236 #else // BOOST_VERSION >= 103900
237  _breakPoint = iEventStruct._breakPoint;
238 #endif // BOOST_VERSION >= 103900
239  }
240  }
241 
242  // //////////////////////////////////////////////////////////////////////
244  }
245 
246  // //////////////////////////////////////////////////////////////////////
247  void EventStruct::fromStream (std::istream& ioIn) {
248  }
249 
250  // //////////////////////////////////////////////////////////////////////
251  const std::string EventStruct::describe() const {
252  std::ostringstream oStr;
253 
254  //
255  const Duration_T lEventDateTimeDelta =
256  boost::posix_time::milliseconds (_eventTimeStamp);
257  const DateTime_T lEventDateTime (DEFAULT_EVENT_OLDEST_DATETIME
258  + lEventDateTimeDelta);
259 
260  oStr << lEventDateTime;
261 
262  //
263  switch (_eventType) {
264  case EventType::BKG_REQ: {
265  assert (_bookingRequest != NULL);
266  oStr << ", " << EventType::getLabel(_eventType)
267  << ", " << _bookingRequest->describe();
268  break;
269  }
270  case EventType::CX: {
271  assert (_cancellation != NULL);
272  oStr << ", " << EventType::getLabel(_eventType)
273  << ", " << _cancellation->describe();
274  break;
275  }
277  assert (_optimisationNotification != NULL);
278  oStr << ", " << EventType::getLabel(_eventType)
279  << ", " << _optimisationNotification->describe();
280  break;
281  }
282  case EventType::SNAPSHOT: {
283  assert (_snapshot != NULL);
284  oStr << ", " << EventType::getLabel(_eventType)
285  << ", " << _snapshot->describe();
286  break;
287  }
288  case EventType::RM: {
289  assert (_rmEvent != NULL);
290  oStr << ", " << EventType::getLabel(_eventType)
291  << ", " << _rmEvent->describe();
292  break;
293  }
294  case EventType::BRK_PT: {
295  assert (_breakPoint != NULL);
296  oStr << ", " << EventType::getLabel(_eventType)
297  << ", " << _breakPoint->describe();
298  break;
299  }
300  default: {
301  oStr << ", " << _eventType << " (not yet recognised)";
302  break;
303  }
304  }
305 
306  oStr << "\n";
307  return oStr.str();
308  }
309 
310  // //////////////////////////////////////////////////////////////////////
312  const DateTime_T& lDateTime (DEFAULT_EVENT_OLDEST_DATETIME);
313 
314  //
315  switch (_eventType) {
316  case EventType::BKG_REQ: {
317  assert (_bookingRequest != NULL);
318  return _bookingRequest->getRequestDateTime();
319  break;
320  }
321  case EventType::CX: {
322  assert (_cancellation != NULL);
323  return _cancellation->getCancellationDateTime() ;
324  break;
325  }
327  assert (_optimisationNotification != NULL);
328  return _optimisationNotification->getNotificationDateTime();
329  break;
330  }
331  case EventType::SNAPSHOT: {
332  assert (_snapshot != NULL);
333  return _snapshot->getSnapshotTime();
334  break;
335  }
336  case EventType::RM: {
337  assert (_rmEvent != NULL);
338  return _rmEvent->getRMEventTime();
339  break;
340  }
341  case EventType::BRK_PT: {
342  assert (_breakPoint != NULL);
343  return _breakPoint->getBreakPointTime();
344  break;
345  }
346  default: {
347  assert(false);
348  return lDateTime;
349  break;
350  }
351  }
352 
353  return lDateTime;
354  }
355 
356  // //////////////////////////////////////////////////////////////////////
358  // The date-time is counted in milliseconds (1e-3 second). Hence,
359  // one thousand (1e3) of attempts correspond to 1 second.
360  // Increment the time stamp of one millisecond.
361  ++_eventTimeStamp;
362  }
363 
364 }