StdAir Logo  1.00.16
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
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
11namespace 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 // //////////////////////////////////////////////////////////////////////
26 : _type (LAST_VALUE) {
27 assert (false);
28 }
29
30 // //////////////////////////////////////////////////////////////////////
31 EventType::EventType (const EventType& iEventType)
32 : _type (iEventType._type) {
33 }
34
35 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
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}
Handle on the StdAir library context.
static char getTypeLabel(const EN_EventType &)
Definition EventType.cpp:88
static std::string getTypeLabelAsString(const EN_EventType &)
Definition EventType.cpp:93
static std::string describeLabels()
std::string getTypeAsString() const
EventType(const EN_EventType &)
Definition EventType.cpp:36
bool operator==(const EN_EventType &) const
const std::string describe() const
static const std::string & getLabel(const EN_EventType &)
Definition EventType.cpp:83
EN_EventType getType() const