StdAir Logo  1.00.21
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
ServiceInitialisationType.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 ServiceInitialisationType::_labels[LAST_VALUE] =
15 { "Not yet initialised", "File parsing", "Built-in sample BOM" };
16
17 // //////////////////////////////////////////////////////////////////////
18 const char ServiceInitialisationType::_typeLabels[LAST_VALUE] =
19 { 'N', 'F', 'B' };
20
21
22 // //////////////////////////////////////////////////////////////////////
24 : _type (LAST_VALUE) {
25 assert (false);
26 }
27
28 // //////////////////////////////////////////////////////////////////////
29 ServiceInitialisationType::
30 ServiceInitialisationType (const ServiceInitialisationType& iServiceInitialisationType)
31 : _type (iServiceInitialisationType._type) {
32 }
33
34 // //////////////////////////////////////////////////////////////////////
35 ServiceInitialisationType::
36 ServiceInitialisationType (const EN_ServiceInitialisationType& iServiceInitialisationType)
37 : _type (iServiceInitialisationType) {
38 }
39
40 // //////////////////////////////////////////////////////////////////////
42 ServiceInitialisationType::getType (const char iTypeChar) {
44 switch (iTypeChar) {
45 case 'N': oType = NOT_YET_INITIALISED; break;
46 case 'F': oType = FILE_PARSING; break;
47 case 'B': oType = BUILTIN_SAMPLE; break;
48 default: oType = LAST_VALUE; break;
49 }
50
51 if (oType == LAST_VALUE) {
52 const std::string& lLabels = describeLabels();
53 std::ostringstream oMessage;
54 oMessage << "The service initialisation type '" << iTypeChar
55 << "' is not known. "
56 << "Known service initialisation types: " << lLabels;
57 throw CodeConversionException (oMessage.str());
58 }
59
60 return oType;
61 }
62
63 // //////////////////////////////////////////////////////////////////////
64 ServiceInitialisationType::
65 ServiceInitialisationType (const char iTypeChar)
66 : _type (getType (iTypeChar)) {
67 }
68
69 // //////////////////////////////////////////////////////////////////////
70 ServiceInitialisationType::
71 ServiceInitialisationType (const std::string& iTypeStr) {
72 //
73 const size_t lSize = iTypeStr.size();
74 assert (lSize == 1);
75 const char lTypeChar = iTypeStr[0];
76 _type = getType (lTypeChar);
77 }
78
79 // //////////////////////////////////////////////////////////////////////
80 const std::string& ServiceInitialisationType::
82 return _labels[iType];
83 }
84
85 // //////////////////////////////////////////////////////////////////////
88 return _typeLabels[iType];
89 }
90
91 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
114 return _type;
115 }
116
117 // //////////////////////////////////////////////////////////////////////
119 const char oTypeChar = _typeLabels[_type];
120 return oTypeChar;
121 }
122
123 // //////////////////////////////////////////////////////////////////////
125 std::ostringstream oStr;
126 oStr << _typeLabels[_type];
127 return oStr.str();
128 }
129
130 // //////////////////////////////////////////////////////////////////////
131 const std::string ServiceInitialisationType::describe() const {
132 std::ostringstream ostr;
133 ostr << _labels[_type];
134 return ostr.str();
135 }
136
137 // //////////////////////////////////////////////////////////////////////
139 operator== (const EN_ServiceInitialisationType& iType) const {
140 return (_type == iType);
141 }
142
143}
Handle on the StdAir library context.
static EN_ServiceInitialisationType getType(const char)
bool operator==(const EN_ServiceInitialisationType &) const
static std::string getTypeLabelAsString(const EN_ServiceInitialisationType &)
static char getTypeLabel(const EN_ServiceInitialisationType &)
EN_ServiceInitialisationType getType() const
static const std::string & getLabel(const EN_ServiceInitialisationType &)
ServiceInitialisationType(const EN_ServiceInitialisationType &)