0.08.01
C++ Open Travel Request Parsing Library
Toggle main menu visibility
Loading...
Searching...
No Matches
ScoreType.cpp
Go to the documentation of this file.
1
// //////////////////////////////////////////////////////////////////////
2
// Import section
3
// //////////////////////////////////////////////////////////////////////
4
// STL
5
#include <cassert>
6
#include <sstream>
7
// OpenTrep
8
#include <
opentrep/OPENTREP_exceptions.hpp
>
9
#include <
opentrep/basic/ScoreType.hpp
>
10
11
namespace
OPENTREP
{
12
13
// //////////////////////////////////////////////////////////////////////
14
const
std::string ScoreType::_labels[
LAST_VALUE
] =
15
{
"Combination"
,
"Xapian Percentage"
,
"Page Rank"
,
"Passenger Number"
,
16
"Heuristic"
,
"Envelope ID"
,
"IATA/ICAO Code Full Match"
};
17
18
const
char
ScoreType::_typeLabels[
LAST_VALUE
] = {
'C'
,
'X'
,
'R'
,
'N'
,
'H'
,
19
'E'
,
'F'
};
20
21
22
// //////////////////////////////////////////////////////////////////////
23
ScoreType::ScoreType
(
const
EN_ScoreType
& iScoreType)
24
: _type (iScoreType) {
25
}
26
27
// //////////////////////////////////////////////////////////////////////
28
ScoreType::ScoreType
(
const
char
iType) {
29
switch
(iType) {
30
case
'C'
: _type =
COMBINATION
;
break
;
31
case
'X'
: _type =
XAPIAN_PCT
;
break
;
32
case
'R'
: _type =
PAGE_RANK
;
break
;
33
case
'N'
: _type =
PAX_NB
;
break
;
34
case
'H'
: _type =
HEURISTIC
;
break
;
35
case
'E'
: _type =
ENV_ID
;
break
;
36
case
'F'
: _type =
CODE_FULL_MATCH
;
break
;
37
default
: _type =
LAST_VALUE
;
break
;
38
}
39
40
if
(_type ==
LAST_VALUE
) {
41
const
std::string& lLabels =
describeLabels
();
42
std::ostringstream oMessage;
43
oMessage <<
"The score type '"
<< iType
44
<<
"' is not known. Known score types: "
<< lLabels;
45
throw
CodeConversionException
(oMessage.str());
46
}
47
}
48
49
// //////////////////////////////////////////////////////////////////////
50
const
std::string&
ScoreType::getLongLabel
()
const
{
51
return
_labels[_type];
52
}
53
54
// //////////////////////////////////////////////////////////////////////
55
const
std::string&
ScoreType::getLabel
(
const
EN_ScoreType
& iType) {
56
return
_labels[iType];
57
}
58
59
// //////////////////////////////////////////////////////////////////////
60
char
ScoreType::getTypeLabel
(
const
EN_ScoreType
& iType) {
61
return
_typeLabels[iType];
62
}
63
64
// //////////////////////////////////////////////////////////////////////
65
std::string
ScoreType::
66
getTypeLabelAsString
(
const
EN_ScoreType
& iType) {
67
std::ostringstream oStr;
68
oStr << _typeLabels[iType];
69
return
oStr.str();
70
}
71
72
// //////////////////////////////////////////////////////////////////////
73
std::string
ScoreType::describeLabels
() {
74
std::ostringstream ostr;
75
for
(
unsigned
short
idx = 0; idx !=
LAST_VALUE
; ++idx) {
76
if
(idx != 0) {
77
ostr <<
", "
;
78
}
79
ostr << _labels[idx];
80
}
81
return
ostr.str();
82
}
83
84
// //////////////////////////////////////////////////////////////////////
85
ScoreType::EN_ScoreType
ScoreType::getType
()
const
{
86
return
_type;
87
}
88
89
// //////////////////////////////////////////////////////////////////////
90
std::string
ScoreType::getTypeAsString
()
const
{
91
std::ostringstream oStr;
92
oStr << _typeLabels[_type];
93
return
oStr.str();
94
}
95
96
// //////////////////////////////////////////////////////////////////////
97
std::string
ScoreType::describe
()
const
{
98
std::ostringstream ostr;
99
ostr << _labels[_type];
100
return
ostr.str();
101
}
102
103
// //////////////////////////////////////////////////////////////////////
104
bool
ScoreType::isIndividualScore
()
const
{
105
bool
oIsIndividual =
true
;
106
if
(_type ==
COMBINATION
|| _type ==
LAST_VALUE
) {
107
oIsIndividual =
false
;
108
}
109
return
oIsIndividual;
110
}
111
112
// //////////////////////////////////////////////////////////////////////
113
bool
ScoreType::isIndividualScore
(
const
EN_ScoreType
& iTypeEnum) {
114
ScoreType
lType (iTypeEnum);
115
return
lType.
isIndividualScore
();
116
}
117
118
// //////////////////////////////////////////////////////////////////////
119
bool
ScoreType::operator==
(
const
EN_ScoreType
& iType)
const
{
120
return
(_type == iType);
121
}
122
123
}
OPENTREP_exceptions.hpp
ScoreType.hpp
OPENTREP::CodeConversionException
Definition
OPENTREP_exceptions.hpp:226
OPENTREP::LOG::LAST_VALUE
@ LAST_VALUE
Definition
OPENTREP_log.hpp:22
OPENTREP
Definition
BasChronometer.cpp:10
OPENTREP::ScoreType::ScoreType
ScoreType(const EN_ScoreType &)
Definition
ScoreType.cpp:23
OPENTREP::ScoreType::getTypeLabelAsString
static std::string getTypeLabelAsString(const EN_ScoreType &)
Definition
ScoreType.cpp:66
OPENTREP::ScoreType::describeLabels
static std::string describeLabels()
Definition
ScoreType.cpp:73
OPENTREP::ScoreType::getLongLabel
const std::string & getLongLabel() const
Definition
ScoreType.cpp:50
OPENTREP::ScoreType::operator==
bool operator==(const EN_ScoreType &) const
Definition
ScoreType.cpp:119
OPENTREP::ScoreType::getLabel
static const std::string & getLabel(const EN_ScoreType &)
Definition
ScoreType.cpp:55
OPENTREP::ScoreType::isIndividualScore
bool isIndividualScore() const
Definition
ScoreType.cpp:104
OPENTREP::ScoreType::describe
std::string describe() const
Definition
ScoreType.cpp:97
OPENTREP::ScoreType::getType
EN_ScoreType getType() const
Definition
ScoreType.cpp:85
OPENTREP::ScoreType::EN_ScoreType
EN_ScoreType
Definition
ScoreType.hpp:27
OPENTREP::ScoreType::ENV_ID
@ ENV_ID
Definition
ScoreType.hpp:33
OPENTREP::ScoreType::LAST_VALUE
@ LAST_VALUE
Definition
ScoreType.hpp:35
OPENTREP::ScoreType::COMBINATION
@ COMBINATION
Definition
ScoreType.hpp:28
OPENTREP::ScoreType::PAGE_RANK
@ PAGE_RANK
Definition
ScoreType.hpp:30
OPENTREP::ScoreType::HEURISTIC
@ HEURISTIC
Definition
ScoreType.hpp:32
OPENTREP::ScoreType::CODE_FULL_MATCH
@ CODE_FULL_MATCH
Definition
ScoreType.hpp:34
OPENTREP::ScoreType::XAPIAN_PCT
@ XAPIAN_PCT
Definition
ScoreType.hpp:29
OPENTREP::ScoreType::PAX_NB
@ PAX_NB
Definition
ScoreType.hpp:31
OPENTREP::ScoreType::getTypeAsString
std::string getTypeAsString() const
Definition
ScoreType.cpp:90
OPENTREP::ScoreType::getTypeLabel
static char getTypeLabel(const EN_ScoreType &)
Definition
ScoreType.cpp:60
Generated on
for OpenTREP by
1.17.0