StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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
21 
22 namespace stdair {
23 
24  // //////////////////////////////////////////////////////////////////////
26  : _eventType (EventType::BKG_REQ), _eventTimeStamp (0) {
27  }
28 
29  // //////////////////////////////////////////////////////////////////////
31  BookingRequestPtr_T ioRequestPtr)
32  : _eventType (iEventType) {
33 
34  //
35  assert (ioRequestPtr != NULL);
36 #if BOOST_VERSION >= 103900
37  _bookingRequest = boost::make_shared<BookingRequestStruct> (*ioRequestPtr);
38 #else // BOOST_VERSION >= 103900
39  _bookingRequest = ioRequestPtr;
40 #endif // BOOST_VERSION >= 103900
41  assert (_bookingRequest != NULL);
42 
48  const Duration_T lDuration =
49  _bookingRequest->getRequestDateTime() - DEFAULT_EVENT_OLDEST_DATETIME;
50  _eventTimeStamp = lDuration.total_milliseconds();
51  }
52 
53  // //////////////////////////////////////////////////////////////////////
55  CancellationPtr_T ioCancellationPtr)
56  : _eventType (iEventType) {
57 
58  //
59  assert (ioCancellationPtr != NULL);
60 #if BOOST_VERSION >= 103900
61  _cancellation = boost::make_shared<CancellationStruct> (*ioCancellationPtr);
62 #else // BOOST_VERSION >= 103900
63  _cancellation = ioCancellationPtr;
64 #endif // BOOST_VERSION >= 103900
65  assert (_cancellation != NULL);
66 
72  const Duration_T lDuration =
73  _cancellation->getCancellationDateTime() - DEFAULT_EVENT_OLDEST_DATETIME;
74  _eventTimeStamp = lDuration.total_milliseconds();
75  }
76 
77  // //////////////////////////////////////////////////////////////////////
80  const DateTime_T& iDCPDate,
81  OptimisationNotificationPtr_T ioOptimisationNotificationPtr)
82  : _eventType (iEventType) {
83 
84  //
85  assert (ioOptimisationNotificationPtr != NULL);
86 #if BOOST_VERSION >= 103900
87  _optimisationNotification =
88  boost::make_shared<OptimisationNotificationStruct> (*ioOptimisationNotificationPtr);
89 #else // BOOST_VERSION >= 103900
90  _optimisationNotification = ioOptimisationNotificationPtr;
91 #endif // BOOST_VERSION >= 103900
92  assert (_optimisationNotification != NULL);
93 
99  const Duration_T lDuration = iDCPDate - DEFAULT_EVENT_OLDEST_DATETIME;
100  _eventTimeStamp = lDuration.total_milliseconds();
101  }
102 
103  // //////////////////////////////////////////////////////////////////////
105  SnapshotPtr_T ioSnapshotPtr)
106  : _eventType (iEventType) {
107 
108  //
109  assert (ioSnapshotPtr != NULL);
110 
111 #if BOOST_VERSION >= 103900
112  _snapshot = boost::make_shared<SnapshotStruct> (*ioSnapshotPtr);
113 #else // BOOST_VERSION >= 103900
114  _snapshot = ioSnapshotPtr;
115 #endif // BOOST_VERSION >= 103900
116  assert (_snapshot != NULL);
117 
123  const Duration_T lDuration =
124  _snapshot->getSnapshotTime() - DEFAULT_EVENT_OLDEST_DATETIME;
125  _eventTimeStamp = lDuration.total_milliseconds();
126  }
127 
128  // //////////////////////////////////////////////////////////////////////
130  RMEventPtr_T ioRMEventPtr)
131  : _eventType (iEventType) {
132 
133  //
134  assert (ioRMEventPtr != NULL);
135 
136 #if BOOST_VERSION >= 103900
137  _rmEvent = boost::make_shared<RMEventStruct> (*ioRMEventPtr);
138 #else // BOOST_VERSION >= 103900
139  _rmEvent = ioRMEventPtr;
140 #endif // BOOST_VERSION >= 103900
141  assert (_rmEvent != NULL);
142 
148  const Duration_T lDuration =
149  _rmEvent->getRMEventTime() - DEFAULT_EVENT_OLDEST_DATETIME;
150  _eventTimeStamp = lDuration.total_milliseconds();
151  }
152 
153  // //////////////////////////////////////////////////////////////////////
154  EventStruct::EventStruct (const EventStruct& iEventStruct)
155  : _eventType (iEventStruct._eventType),
156  _eventTimeStamp (iEventStruct._eventTimeStamp) {
157 
158  //
159  if (iEventStruct._bookingRequest != NULL) {
160 #if BOOST_VERSION >= 103900
161  _bookingRequest =
162  boost::make_shared<BookingRequestStruct>(*iEventStruct._bookingRequest);
163 #else // BOOST_VERSION >= 103900
164  _bookingRequest = iEventStruct._bookingRequest;
165 #endif // BOOST_VERSION >= 103900
166  }
167 
168  //
169  if (iEventStruct._cancellation != NULL) {
170 #if BOOST_VERSION >= 103900
171  _cancellation =
172  boost::make_shared<CancellationStruct>(*iEventStruct._cancellation);
173 #else // BOOST_VERSION >= 103900
174  _cancellation = iEventStruct._cancellation;
175 #endif // BOOST_VERSION >= 103900
176  }
177 
178  //
179  if (iEventStruct._optimisationNotification != NULL) {
180 #if BOOST_VERSION >= 103900
181  _optimisationNotification =
182  boost::make_shared<OptimisationNotificationStruct> (*iEventStruct._optimisationNotification);
183 #else // BOOST_VERSION >= 103900
184  _optimisationNotification = iEventStruct._optimisationNotification;
185 #endif // BOOST_VERSION >= 103900
186  }
187 
188  //
189  if (iEventStruct._snapshot != NULL) {
190 #if BOOST_VERSION >= 103900
191  _snapshot = boost::make_shared<SnapshotStruct> (*iEventStruct._snapshot);
192 #else // BOOST_VERSION >= 103900
193  _snapshot = iEventStruct._snapshot;
194 #endif // BOOST_VERSION >= 103900
195  }
196 
197  //
198  if (iEventStruct._rmEvent != NULL) {
199 #if BOOST_VERSION >= 103900
200  _rmEvent = boost::make_shared<RMEventStruct> (*iEventStruct._rmEvent);
201 #else // BOOST_VERSION >= 103900
202  _rmEvent = iEventStruct._rmEvent;
203 #endif // BOOST_VERSION >= 103900
204  }
205  }
206 
207  // //////////////////////////////////////////////////////////////////////
209  }
210 
211  // //////////////////////////////////////////////////////////////////////
212  void EventStruct::fromStream (std::istream& ioIn) {
213  }
214 
215  // //////////////////////////////////////////////////////////////////////
216  const std::string EventStruct::describe() const {
217  std::ostringstream oStr;
218 
219  //
220  const Duration_T lEventDateTimeDelta =
221  boost::posix_time::milliseconds (_eventTimeStamp);
222  const DateTime_T lEventDateTime (DEFAULT_EVENT_OLDEST_DATETIME
223  + lEventDateTimeDelta);
224  oStr << lEventDateTime;
225 
226  //
227  switch (_eventType) {
228  case EventType::BKG_REQ: {
229  assert (_bookingRequest != NULL);
230  oStr << ", " << _eventType << ", " << _bookingRequest->describe();
231  break;
232  }
233  case EventType::CX: {
234  assert (_cancellation != NULL);
235  oStr << ", " << _eventType << ", " << _cancellation->describe();
236  break;
237  }
239  assert (_optimisationNotification != NULL);
240  oStr << ", " << _eventType
241  << ", " << _optimisationNotification->describe();
242  break;
243  }
244  case EventType::SNAPSHOT: {
245  assert (_snapshot != NULL);
246  oStr << ", " << _eventType
247  << ", " << _snapshot->describe();
248  break;
249  }
250  case EventType::RM: {
251  assert (_rmEvent != NULL);
252  oStr << ", " << _eventType
253  << ", " << _rmEvent->describe();
254  break;
255  }
256  default: {
257  oStr << ", " << _eventType << " (not yet recognised)";
258  break;
259  }
260  }
261 
262  return oStr.str();
263  }
264 
265 }