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

stdair/basic/EventType.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/EventType.hpp>
00010 
00011 namespace stdair {
00012   
00013   // //////////////////////////////////////////////////////////////////////
00014   const std::string EventType::_labels[LAST_VALUE] =
00015     { "BookingRequest", "Cancellation","OptimisationNotificationForFlightDate",
00016       "OptimisationNotificationForNetwork", "ScheduleChange", "Snapshot",
00017       "RevenueManagement", "BreakPoint" };
00018 
00019   // //////////////////////////////////////////////////////////////////////
00020   const char EventType::
00021   _typeLabels[LAST_VALUE] = { 'B', 'X', 'F', 'N', 'C', 'S', 'R', 'P' };
00022 
00023   
00024   // //////////////////////////////////////////////////////////////////////
00025   EventType::EventType()
00026     : _type (LAST_VALUE) {
00027     assert (false);
00028   }
00029 
00030   // //////////////////////////////////////////////////////////////////////
00031   EventType::EventType (const EventType& iEventType)
00032     : _type (iEventType._type) {
00033   }
00034 
00035   // //////////////////////////////////////////////////////////////////////
00036   EventType::EventType (const EN_EventType& iEventType)
00037     : _type (iEventType) {
00038   }
00039 
00040   // //////////////////////////////////////////////////////////////////////
00041   EventType::EventType (const char iType) {
00042     switch (iType) {
00043     case 'B': _type = BKG_REQ; break;
00044     case 'X': _type = CX; break;
00045     case 'F': _type = OPT_NOT_4_FD; break;
00046     case 'N': _type = OPT_NOT_4_NET; break;
00047     case 'C': _type = SKD_CHG; break;
00048     case 'S': _type = SNAPSHOT; break;
00049     case 'R': _type = RM; break;
00050     case 'P': _type = BRK_PT; break;
00051     default: _type = LAST_VALUE; break;
00052     }
00053 
00054     if (_type == LAST_VALUE) {
00055       const std::string& lLabels = describeLabels();
00056       std::ostringstream oMessage;
00057       oMessage << "The event type '" << iType
00058                << "' is not known. Known event types: " << lLabels;
00059       throw CodeConversionException (oMessage.str());
00060     }
00061   }   
00062 
00063   // //////////////////////////////////////////////////////////////////////
00064   EventType::EventType (const std::string& iTypeStr) {  
00065     for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
00066       if (iTypeStr.compare(_labels[idx]) == 0) { 
00067         _type = static_cast<EN_EventType> (idx);
00068         break; 
00069       } else {
00070         _type = LAST_VALUE;
00071       } 
00072     }
00073     if (_type == LAST_VALUE) {
00074       const std::string& lLabels = describeLabels();
00075       std::ostringstream oMessage;
00076       oMessage << "The event type '" << iTypeStr
00077                << "' is not known. Known event types: " << lLabels;
00078       throw CodeConversionException (oMessage.str());
00079     }
00080   }
00081 
00082   // //////////////////////////////////////////////////////////////////////
00083   const std::string& EventType::getLabel (const EN_EventType& iType) {
00084     return _labels[iType];
00085   }
00086   
00087   // //////////////////////////////////////////////////////////////////////
00088   char EventType::getTypeLabel (const EN_EventType& iType) {
00089     return _typeLabels[iType];
00090   }
00091 
00092   // //////////////////////////////////////////////////////////////////////
00093   std::string EventType::getTypeLabelAsString (const EN_EventType& iType) {
00094     std::ostringstream oStr;
00095     oStr << _typeLabels[iType];
00096     return oStr.str();
00097   }
00098 
00099   // //////////////////////////////////////////////////////////////////////
00100   std::string EventType::describeLabels() {
00101     std::ostringstream ostr;
00102     for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
00103       if (idx != 0) {
00104         ostr << ", ";
00105       }
00106       ostr << _labels[idx];
00107     }
00108     return ostr.str();
00109   }
00110 
00111   // //////////////////////////////////////////////////////////////////////
00112   EventType::EN_EventType EventType::getType() const {
00113     return _type;
00114   }
00115   
00116   // //////////////////////////////////////////////////////////////////////
00117   std::string EventType::getTypeAsString() const {
00118     std::ostringstream oStr;
00119     oStr << _typeLabels[_type];
00120     return oStr.str();
00121   }
00122   
00123   // //////////////////////////////////////////////////////////////////////
00124   const std::string EventType::describe() const {
00125     std::ostringstream ostr;
00126     ostr << _labels[_type];
00127     return ostr.str();
00128   }
00129 
00130   // //////////////////////////////////////////////////////////////////////
00131   bool EventType::operator== (const EN_EventType& iType) const {
00132     return (_type == iType);
00133   }
00134   
00135 }