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

stdair/basic/PassengerChoiceModel.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/PassengerChoiceModel.hpp>
00010 
00011 namespace stdair {
00012   
00013   // //////////////////////////////////////////////////////////////////////
00014   const std::string PassengerChoiceModel::_labels[LAST_VALUE] =
00015     { "HardRestrictionModel", "PriceOrientedModel", "HybridModel"};
00016 
00017   // //////////////////////////////////////////////////////////////////////
00018   const char PassengerChoiceModel::
00019   _modelLabels[LAST_VALUE] = { 'R', 'P', 'H'};
00020 
00021   
00022   // //////////////////////////////////////////////////////////////////////
00023   PassengerChoiceModel::PassengerChoiceModel()
00024     : _model (LAST_VALUE) {
00025     assert (false);
00026   }
00027 
00028   // //////////////////////////////////////////////////////////////////////
00029   PassengerChoiceModel::
00030   PassengerChoiceModel (const PassengerChoiceModel& iPassengerChoiceModel)
00031     : _model (iPassengerChoiceModel._model) {
00032   }
00033 
00034   // //////////////////////////////////////////////////////////////////////
00035   PassengerChoiceModel::
00036   PassengerChoiceModel (const EN_PassengerChoiceModel& iPassengerChoiceModel)
00037     : _model (iPassengerChoiceModel) {
00038   }
00039 
00040   // //////////////////////////////////////////////////////////////////////
00041   PassengerChoiceModel::PassengerChoiceModel (const char iModel) {
00042     switch (iModel) {
00043     case 'R': _model = HARD_RESTRICTION; break;
00044     case 'P': _model = PRICE_ORIENTED; break;
00045     case 'H': _model = HYBRID; break;
00046     default: _model = LAST_VALUE; break;
00047     }
00048 
00049     if (_model == LAST_VALUE) {
00050       const std::string& lLabels = describeLabels();
00051       std::ostringstream oMessage;
00052       oMessage << "The passenger choice model '"
00053                << "' is not known. Known passenger choice models " << lLabels;
00054       throw stdair::CodeConversionException (oMessage.str());
00055     }
00056   }
00057   
00058   // //////////////////////////////////////////////////////////////////////
00059   const std::string& PassengerChoiceModel::
00060   getLabel (const EN_PassengerChoiceModel& iModel) {
00061     return _labels[iModel];
00062   }
00063   
00064   // //////////////////////////////////////////////////////////////////////
00065   char PassengerChoiceModel::getModelLabel (const EN_PassengerChoiceModel& iModel) {
00066     return _modelLabels[iModel];
00067   }
00068 
00069   // //////////////////////////////////////////////////////////////////////
00070   std::string PassengerChoiceModel::
00071   getModelLabelAsString (const EN_PassengerChoiceModel& iModel) {
00072     std::ostringstream oStr;
00073     oStr << _modelLabels[iModel];
00074     return oStr.str();
00075   }
00076 
00077   // //////////////////////////////////////////////////////////////////////
00078   std::string PassengerChoiceModel::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] << " (" << _modelLabels[idx] << ")";
00085     }
00086     return ostr.str();
00087   }
00088 
00089   // //////////////////////////////////////////////////////////////////////
00090   PassengerChoiceModel::EN_PassengerChoiceModel PassengerChoiceModel::getModel() const {
00091     return _model;
00092   }
00093   
00094   // //////////////////////////////////////////////////////////////////////
00095   std::string PassengerChoiceModel::getModelAsString() const {
00096     std::ostringstream oStr;
00097     oStr << _modelLabels[_model];
00098     return oStr.str();
00099   }
00100   
00101   // //////////////////////////////////////////////////////////////////////
00102   const std::string PassengerChoiceModel::describe() const {
00103     std::ostringstream ostr;
00104     ostr << _labels[_model];
00105     return ostr.str();
00106   }
00107 
00108   // //////////////////////////////////////////////////////////////////////
00109   bool PassengerChoiceModel::
00110   operator== (const EN_PassengerChoiceModel& iModel) const {
00111     return (_model == iModel);
00112   }
00113   
00114 }