1.00.26
C++ Standard Airline IT Object Library
Toggle main menu visibility
Loading...
Searching...
No Matches
PassengerType.cpp
Go to the documentation of this file.
1
// //////////////////////////////////////////////////////////////////////
2
// Import section
3
// //////////////////////////////////////////////////////////////////////
4
// STL
5
#include <cassert>
6
#include <sstream>
7
// StdAir
8
#include <
stdair/stdair_exceptions.hpp
>
9
#include <
stdair/basic/PassengerType.hpp
>
10
11
namespace
stdair
{
12
13
// //////////////////////////////////////////////////////////////////////
14
const
std::string PassengerType::_labels[
LAST_VALUE
] =
15
{
"Leisure"
,
"Business"
,
"First"
};
16
17
const
char
PassengerType::_typeLabels[
LAST_VALUE
] = {
'L'
,
'B'
,
'F'
};
18
19
20
// //////////////////////////////////////////////////////////////////////
21
PassengerType::PassengerType
(
const
EN_PassengerType
& iPassengerType)
22
: _type (iPassengerType) {
23
}
24
25
// //////////////////////////////////////////////////////////////////////
26
PassengerType::PassengerType
(
const
char
iType) {
27
switch
(iType) {
28
case
'L'
: _type =
LEISURE
;
break
;
29
case
'B'
: _type =
BUSINESS
;
break
;
30
case
'F'
: _type =
FIRST
;
break
;
31
default
: _type =
LAST_VALUE
;
break
;
32
}
33
34
if
(_type ==
LAST_VALUE
) {
35
const
std::string& lLabels =
describeLabels
();
36
std::ostringstream oMessage;
37
oMessage <<
"The passenger type '"
<< iType
38
<<
"' is not known. Known passenger types: "
<< lLabels;
39
throw
CodeConversionException
(oMessage.str());
40
}
41
}
42
43
// //////////////////////////////////////////////////////////////////////
44
const
std::string&
PassengerType::getLabel
(
const
EN_PassengerType
& iType) {
45
return
_labels[iType];
46
}
47
48
// //////////////////////////////////////////////////////////////////////
49
char
PassengerType::getTypeLabel
(
const
EN_PassengerType
& iType) {
50
return
_typeLabels[iType];
51
}
52
53
// //////////////////////////////////////////////////////////////////////
54
std::string
PassengerType::
55
getTypeLabelAsString
(
const
EN_PassengerType
& iType) {
56
std::ostringstream oStr;
57
oStr << _typeLabels[iType];
58
return
oStr.str();
59
}
60
61
// //////////////////////////////////////////////////////////////////////
62
std::string
PassengerType::describeLabels
() {
63
std::ostringstream ostr;
64
for
(
unsigned
short
idx = 0; idx !=
LAST_VALUE
; ++idx) {
65
if
(idx != 0) {
66
ostr <<
", "
;
67
}
68
ostr << _labels[idx];
69
}
70
return
ostr.str();
71
}
72
73
// //////////////////////////////////////////////////////////////////////
74
PassengerType::EN_PassengerType
PassengerType::getType
()
const
{
75
return
_type;
76
}
77
78
// //////////////////////////////////////////////////////////////////////
79
std::string
PassengerType::getTypeAsString
()
const
{
80
std::ostringstream oStr;
81
oStr << _typeLabels[_type];
82
return
oStr.str();
83
}
84
85
// //////////////////////////////////////////////////////////////////////
86
const
std::string
PassengerType::describe
()
const
{
87
std::ostringstream ostr;
88
ostr << _labels[_type];
89
return
ostr.str();
90
}
91
92
// //////////////////////////////////////////////////////////////////////
93
bool
PassengerType::operator==
(
const
EN_PassengerType
& iType)
const
{
94
return
(_type == iType);
95
}
96
97
}
PassengerType.hpp
stdair_exceptions.hpp
stdair
Handle on the StdAir library context.
Definition
BasChronometer.cpp:9
stdair::LOG::LAST_VALUE
@ LAST_VALUE
Definition
stdair_log.hpp:25
stdair::PassengerType::EN_PassengerType
EN_PassengerType
Definition
PassengerType.hpp:17
stdair::PassengerType::LEISURE
@ LEISURE
Definition
PassengerType.hpp:18
stdair::PassengerType::BUSINESS
@ BUSINESS
Definition
PassengerType.hpp:19
stdair::PassengerType::FIRST
@ FIRST
Definition
PassengerType.hpp:20
stdair::PassengerType::LAST_VALUE
@ LAST_VALUE
Definition
PassengerType.hpp:21
stdair::PassengerType::describe
const std::string describe() const
Definition
PassengerType.cpp:86
stdair::PassengerType::operator==
bool operator==(const EN_PassengerType &) const
Definition
PassengerType.cpp:93
stdair::PassengerType::getType
EN_PassengerType getType() const
Definition
PassengerType.cpp:74
stdair::PassengerType::getTypeAsString
std::string getTypeAsString() const
Definition
PassengerType.cpp:79
stdair::PassengerType::getLabel
static const std::string & getLabel(const EN_PassengerType &)
Definition
PassengerType.cpp:44
stdair::PassengerType::describeLabels
static std::string describeLabels()
Definition
PassengerType.cpp:62
stdair::PassengerType::PassengerType
PassengerType(const EN_PassengerType &)
Definition
PassengerType.cpp:21
stdair::PassengerType::getTypeLabelAsString
static std::string getTypeLabelAsString(const EN_PassengerType &)
Definition
PassengerType.cpp:55
stdair::PassengerType::getTypeLabel
static char getTypeLabel(const EN_PassengerType &)
Definition
PassengerType.cpp:49
stdair::CodeConversionException
Definition
stdair_exceptions.hpp:133
Generated for StdAir by
1.17.0