$treeview $search $mathjax
StdAir Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

stdair/basic/PreOptimisationMethod.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // StdAir
00008 #include <stdair/stdair_exceptions.hpp>
00009 #include <stdair/basic/PreOptimisationMethod.hpp>
00010 
00011 namespace stdair {
00012   
00013   // //////////////////////////////////////////////////////////////////////
00014   const std::string PreOptimisationMethod::_labels[LAST_VALUE] =
00015     {"None", "Fare Adjustment", "Marginal Revenue Transformation"};
00016 
00017   // //////////////////////////////////////////////////////////////////////
00018   const char PreOptimisationMethod::
00019   _methodLabels[LAST_VALUE] = {'N', 'F', 'M'};
00020 
00021   
00022   // //////////////////////////////////////////////////////////////////////
00023   PreOptimisationMethod::PreOptimisationMethod()
00024     : _method (LAST_VALUE) {
00025     assert (false);
00026   }
00027 
00028   // //////////////////////////////////////////////////////////////////////
00029   PreOptimisationMethod::
00030   PreOptimisationMethod (const PreOptimisationMethod& iPreOptimisationMethod)
00031     : _method (iPreOptimisationMethod._method) {
00032   }
00033 
00034   // //////////////////////////////////////////////////////////////////////
00035   PreOptimisationMethod::
00036   PreOptimisationMethod (const EN_PreOptimisationMethod& iPreOptimisationMethod)
00037     : _method (iPreOptimisationMethod) {
00038   }
00039 
00040   // //////////////////////////////////////////////////////////////////////
00041   PreOptimisationMethod::PreOptimisationMethod (const char iMethod) {
00042     switch (iMethod) {
00043     case 'N': _method = NONE; break;
00044     case 'F': _method = FA; break;
00045     case 'M': _method = MRT; break;
00046     default: _method = LAST_VALUE; break;
00047     }
00048 
00049     if (_method == LAST_VALUE) {
00050       const std::string& lLabels = describeLabels();
00051       std::ostringstream oMessage;
00052       oMessage << "The pre-optimisation method '" << iMethod
00053                << "' is not known. Known pre-optimisation methods: " << lLabels;
00054       throw CodeConversionException (oMessage.str());
00055     }
00056   }
00057   
00058   // //////////////////////////////////////////////////////////////////////
00059   const std::string& PreOptimisationMethod::
00060   getLabel (const EN_PreOptimisationMethod& iMethod) {
00061     return _labels[iMethod];
00062   }
00063   
00064   // //////////////////////////////////////////////////////////////////////
00065   char PreOptimisationMethod::getMethodLabel (const EN_PreOptimisationMethod& iMethod) {
00066     return _methodLabels[iMethod];
00067   }
00068 
00069   // //////////////////////////////////////////////////////////////////////
00070   std::string PreOptimisationMethod::
00071   getMethodLabelAsString (const EN_PreOptimisationMethod& iMethod) {
00072     std::ostringstream oStr;
00073     oStr << _methodLabels[iMethod];
00074     return oStr.str();
00075   }
00076 
00077   // //////////////////////////////////////////////////////////////////////
00078   std::string PreOptimisationMethod::describeLabels() {
00079     std::ostringstream ostr;
00080     for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
00081       if (idx != 0) {
00082         ostr << ", ";
00083       }
00084       ostr << _labels[idx] << " (" << _methodLabels[idx] << ")";
00085     }
00086     return ostr.str();
00087   }
00088 
00089   // //////////////////////////////////////////////////////////////////////
00090   PreOptimisationMethod::EN_PreOptimisationMethod PreOptimisationMethod::getMethod() const {
00091     return _method;
00092   }
00093   
00094   // //////////////////////////////////////////////////////////////////////
00095   std::string PreOptimisationMethod::getMethodAsString() const {
00096     std::ostringstream oStr;
00097     oStr << _methodLabels[_method];
00098     return oStr.str();
00099   }
00100   
00101   // //////////////////////////////////////////////////////////////////////
00102   const std::string PreOptimisationMethod::describe() const {
00103     std::ostringstream ostr;
00104     ostr << _labels[_method];
00105     return ostr.str();
00106   }
00107 
00108   // //////////////////////////////////////////////////////////////////////
00109   bool PreOptimisationMethod::
00110   operator== (const EN_PreOptimisationMethod& iMethod) const {
00111     return (_method == iMethod);
00112   }
00113   
00114 }