StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EventType.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
10 
11 namespace stdair {
12 
13  // //////////////////////////////////////////////////////////////////////
14  const std::string EventType::_labels[LAST_VALUE] =
15  { "BookingRequest", "Cancellation","OptimisationNotificationForFlightDate",
16  "OptimisationNotificationForNetwork", "ScheduleChange", "Snapshot",
17  "RevenueMangement", "BreakPoint" };
18 
19  // //////////////////////////////////////////////////////////////////////
20  const char EventType::
21  _typeLabels[LAST_VALUE] = { 'B', 'X', 'F', 'N', 'C', 'S', 'R', 'P' };
22 
23 
24  // //////////////////////////////////////////////////////////////////////
25  EventType::EventType()
26  : _type (LAST_VALUE) {
27  assert (false);
28  }
29 
30  // //////////////////////////////////////////////////////////////////////
31  EventType::EventType (const EventType& iEventType)
32  : _type (iEventType._type) {
33  }
34 
35  // //////////////////////////////////////////////////////////////////////
36  EventType::EventType (const EN_EventType& iEventType)
37  : _type (iEventType) {
38  }
39 
40  // //////////////////////////////////////////////////////////////////////
41  EventType::EventType (const char iType) {
42  switch (iType) {
43  case 'B': _type = BKG_REQ; break;
44  case 'X': _type = CX; break;
45  case 'F': _type = OPT_NOT_4_FD; break;
46  case 'N': _type = OPT_NOT_4_NET; break;
47  case 'C': _type = SKD_CHG; break;
48  case 'S': _type = SNAPSHOT; break;
49  case 'R': _type = RM; break;
50  case 'P': _type = BRK_PT; break;
51  default: _type = LAST_VALUE; break;
52  }
53 
54  if (_type == LAST_VALUE) {
55  const std::string& lLabels = describeLabels();
56  std::ostringstream oMessage;
57  oMessage << "The event type '" << iType
58  << "' is not known. Known event types: " << lLabels;
59  throw CodeConversionException (oMessage.str());
60  }
61  }
62 
63  // //////////////////////////////////////////////////////////////////////
64  const std::string& EventType::getLabel (const EN_EventType& iType) {
65  return _labels[iType];
66  }
67 
68  // //////////////////////////////////////////////////////////////////////
69  char EventType::getTypeLabel (const EN_EventType& iType) {
70  return _typeLabels[iType];
71  }
72 
73  // //////////////////////////////////////////////////////////////////////
74  std::string EventType::getTypeLabelAsString (const EN_EventType& iType) {
75  std::ostringstream oStr;
76  oStr << _typeLabels[iType];
77  return oStr.str();
78  }
79 
80  // //////////////////////////////////////////////////////////////////////
81  std::string EventType::describeLabels() {
82  std::ostringstream ostr;
83  for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
84  if (idx != 0) {
85  ostr << ", ";
86  }
87  ostr << _labels[idx];
88  }
89  return ostr.str();
90  }
91 
92  // //////////////////////////////////////////////////////////////////////
94  return _type;
95  }
96 
97  // //////////////////////////////////////////////////////////////////////
98  std::string EventType::getTypeAsString() const {
99  std::ostringstream oStr;
100  oStr << _typeLabels[_type];
101  return oStr.str();
102  }
103 
104  // //////////////////////////////////////////////////////////////////////
105  const std::string EventType::describe() const {
106  std::ostringstream ostr;
107  ostr << _labels[_type];
108  return ostr.str();
109  }
110 
111  // //////////////////////////////////////////////////////////////////////
112  bool EventType::operator== (const EN_EventType& iType) const {
113  return (_type == iType);
114  }
115 
116 }