StdAir Logo  1.00.20
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
OptimisationMethod.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 OptimisationMethod::_labels[LAST_VALUE] =
15 { "Leg based Monte Carlo", "Leg based EMSRb"};
16
17 // //////////////////////////////////////////////////////////////////////
18 const char OptimisationMethod::
19 _methodLabels[LAST_VALUE] = { 'M', 'E'};
20
21
22 // //////////////////////////////////////////////////////////////////////
24 : _method (LAST_VALUE) {
25 assert (false);
26 }
27
28 // //////////////////////////////////////////////////////////////////////
29 OptimisationMethod::
30 OptimisationMethod (const OptimisationMethod& iOptimisationMethod)
31 : _method (iOptimisationMethod._method) {
32 }
33
34 // //////////////////////////////////////////////////////////////////////
35 OptimisationMethod::
36 OptimisationMethod (const EN_OptimisationMethod& iOptimisationMethod)
37 : _method (iOptimisationMethod) {
38 }
39
40 // //////////////////////////////////////////////////////////////////////
42 switch (iMethod) {
43 case 'M': _method = LEG_BASED_MC; break;
44 case 'E': _method = LEG_BASED_EMSR_B; break;
45 default: _method = LAST_VALUE; break;
46 }
47
48 if (_method == LAST_VALUE) {
49 const std::string& lLabels = describeLabels();
50 std::ostringstream oMessage;
51 oMessage << "The optimisation method '" << iMethod
52 << "' is not known. Known optimisation methods: " << lLabels;
53 throw CodeConversionException (oMessage.str());
54 }
55 }
56
57 // //////////////////////////////////////////////////////////////////////
58 const std::string& OptimisationMethod::
59 getLabel (const EN_OptimisationMethod& iMethod) {
60 return _labels[iMethod];
61 }
62
63 // //////////////////////////////////////////////////////////////////////
65 return _methodLabels[iMethod];
66 }
67
68 // //////////////////////////////////////////////////////////////////////
71 std::ostringstream oStr;
72 oStr << _methodLabels[iMethod];
73 return oStr.str();
74 }
75
76 // //////////////////////////////////////////////////////////////////////
78 std::ostringstream ostr;
79 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
80 if (idx != 0) {
81 ostr << ", ";
82 }
83 ostr << _labels[idx] << " (" << _methodLabels[idx] << ")";
84 }
85 return ostr.str();
86 }
87
88 // //////////////////////////////////////////////////////////////////////
92
93 // //////////////////////////////////////////////////////////////////////
95 std::ostringstream oStr;
96 oStr << _methodLabels[_method];
97 return oStr.str();
98 }
99
100 // //////////////////////////////////////////////////////////////////////
101 const std::string OptimisationMethod::describe() const {
102 std::ostringstream ostr;
103 ostr << _labels[_method];
104 return ostr.str();
105 }
106
107 // //////////////////////////////////////////////////////////////////////
109 operator== (const EN_OptimisationMethod& iMethod) const {
110 return (_method == iMethod);
111 }
112
113}
Handle on the StdAir library context.
EN_OptimisationMethod getMethod() const
std::string getMethodAsString() const
bool operator==(const EN_OptimisationMethod &) const
static char getMethodLabel(const EN_OptimisationMethod &)
static std::string getMethodLabelAsString(const EN_OptimisationMethod &)
const std::string describe() const
static const std::string & getLabel(const EN_OptimisationMethod &)
static std::string describeLabels()
OptimisationMethod(const EN_OptimisationMethod &)