OpenTREP Logo  0.07.18
C++ Open Travel Request Parsing Library
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
10
11namespace 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 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
61 return _typeLabels[iType];
62 }
63
64 // //////////////////////////////////////////////////////////////////////
65 std::string ScoreType::
67 std::ostringstream oStr;
68 oStr << _typeLabels[iType];
69 return oStr.str();
70 }
71
72 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
105 bool oIsIndividual = true;
106 if (_type == COMBINATION || _type == LAST_VALUE) {
107 oIsIndividual = false;
108 }
109 return oIsIndividual;
110 }
111
112 // //////////////////////////////////////////////////////////////////////
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}
ScoreType(const EN_ScoreType &)
Definition ScoreType.cpp:23
static std::string getTypeLabelAsString(const EN_ScoreType &)
Definition ScoreType.cpp:66
static std::string describeLabels()
Definition ScoreType.cpp:73
const std::string & getLongLabel() const
Definition ScoreType.cpp:50
bool operator==(const EN_ScoreType &) const
static const std::string & getLabel(const EN_ScoreType &)
Definition ScoreType.cpp:55
bool isIndividualScore() const
std::string describe() const
Definition ScoreType.cpp:97
EN_ScoreType getType() const
Definition ScoreType.cpp:85
std::string getTypeAsString() const
Definition ScoreType.cpp:90
static char getTypeLabel(const EN_ScoreType &)
Definition ScoreType.cpp:60