StdAir Logo  1.00.8
C++ Standard Airline IT Object Library
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  "RevenueManagement", "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  EventType::EventType (const std::string& iTypeStr) {
65  for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
66  if (iTypeStr.compare(_labels[idx]) == 0) {
67  _type = static_cast<EN_EventType> (idx);
68  break;
69  } else {
70  _type = LAST_VALUE;
71  }
72  }
73  if (_type == LAST_VALUE) {
74  const std::string& lLabels = describeLabels();
75  std::ostringstream oMessage;
76  oMessage << "The event type '" << iTypeStr
77  << "' is not known. Known event types: " << lLabels;
78  throw CodeConversionException (oMessage.str());
79  }
80  }
81 
82  // //////////////////////////////////////////////////////////////////////
83  const std::string& EventType::getLabel (const EN_EventType& iType) {
84  return _labels[iType];
85  }
86 
87  // //////////////////////////////////////////////////////////////////////
88  char EventType::getTypeLabel (const EN_EventType& iType) {
89  return _typeLabels[iType];
90  }
91 
92  // //////////////////////////////////////////////////////////////////////
93  std::string EventType::getTypeLabelAsString (const EN_EventType& iType) {
94  std::ostringstream oStr;
95  oStr << _typeLabels[iType];
96  return oStr.str();
97  }
98 
99  // //////////////////////////////////////////////////////////////////////
101  std::ostringstream ostr;
102  for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
103  if (idx != 0) {
104  ostr << ", ";
105  }
106  ostr << _labels[idx];
107  }
108  return ostr.str();
109  }
110 
111  // //////////////////////////////////////////////////////////////////////
113  return _type;
114  }
115 
116  // //////////////////////////////////////////////////////////////////////
117  std::string EventType::getTypeAsString() const {
118  std::ostringstream oStr;
119  oStr << _typeLabels[_type];
120  return oStr.str();
121  }
122 
123  // //////////////////////////////////////////////////////////////////////
124  const std::string EventType::describe() const {
125  std::ostringstream ostr;
126  ostr << _labels[_type];
127  return ostr.str();
128  }
129 
130  // //////////////////////////////////////////////////////////////////////
131  bool EventType::operator== (const EN_EventType& iType) const {
132  return (_type == iType);
133  }
134 
135 }
stdair::EventType::SKD_CHG
@ SKD_CHG
Definition: EventType.hpp:22
stdair::EventType::describeLabels
static std::string describeLabels()
Definition: EventType.cpp:100
stdair_exceptions.hpp
stdair::EventType::operator==
bool operator==(const EN_EventType &) const
Definition: EventType.cpp:131
stdair::CodeConversionException
Definition: stdair_exceptions.hpp:133
stdair::EventType::OPT_NOT_4_NET
@ OPT_NOT_4_NET
Definition: EventType.hpp:21
stdair::EventType::getTypeAsString
std::string getTypeAsString() const
Definition: EventType.cpp:117
stdair::EventType::getTypeLabelAsString
static std::string getTypeLabelAsString(const EN_EventType &)
Definition: EventType.cpp:93
stdair::EventType::CX
@ CX
Definition: EventType.hpp:19
stdair::EventType::BKG_REQ
@ BKG_REQ
Definition: EventType.hpp:18
stdair::EventType::describe
const std::string describe() const
Definition: EventType.cpp:124
stdair
Handle on the StdAir library context.
Definition: BasChronometer.cpp:9
stdair::EventType::LAST_VALUE
@ LAST_VALUE
Definition: EventType.hpp:26
stdair::EventType::getLabel
static const std::string & getLabel(const EN_EventType &)
Definition: EventType.cpp:83
stdair::EventType::SNAPSHOT
@ SNAPSHOT
Definition: EventType.hpp:23
stdair::EventType::getTypeLabel
static char getTypeLabel(const EN_EventType &)
Definition: EventType.cpp:88
EventType.hpp
stdair::EventType::BRK_PT
@ BRK_PT
Definition: EventType.hpp:25
stdair::EventType::getType
EN_EventType getType() const
Definition: EventType.cpp:112
stdair::EventType
Definition: EventType.hpp:15
stdair::LOG::LAST_VALUE
@ LAST_VALUE
Definition: stdair_log.hpp:25
stdair::EventType::OPT_NOT_4_FD
@ OPT_NOT_4_FD
Definition: EventType.hpp:20
stdair::EventType::EN_EventType
EN_EventType
Definition: EventType.hpp:17
stdair::EventType::RM
@ RM
Definition: EventType.hpp:24