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

stdair/basic/ServiceInitialisationType.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/ServiceInitialisationType.hpp>
00010 
00011 namespace stdair {
00012   
00013   // //////////////////////////////////////////////////////////////////////
00014   const std::string ServiceInitialisationType::_labels[LAST_VALUE] =
00015     { "Not yet initialised", "File parsing",  "Built-in sample BOM" };
00016 
00017   // //////////////////////////////////////////////////////////////////////
00018   const char ServiceInitialisationType::_typeLabels[LAST_VALUE] =
00019     { 'N', 'F', 'B' };
00020 
00021   
00022   // //////////////////////////////////////////////////////////////////////
00023   ServiceInitialisationType::ServiceInitialisationType()
00024     : _type (LAST_VALUE) {
00025     assert (false);
00026   }
00027 
00028   // //////////////////////////////////////////////////////////////////////
00029   ServiceInitialisationType::
00030   ServiceInitialisationType (const ServiceInitialisationType& iServiceInitialisationType)
00031     : _type (iServiceInitialisationType._type) {
00032   }
00033 
00034   // //////////////////////////////////////////////////////////////////////
00035   ServiceInitialisationType::
00036   ServiceInitialisationType (const EN_ServiceInitialisationType& iServiceInitialisationType)
00037     : _type (iServiceInitialisationType) {
00038   }
00039 
00040   // //////////////////////////////////////////////////////////////////////
00041   ServiceInitialisationType::EN_ServiceInitialisationType
00042   ServiceInitialisationType::getType (const char iTypeChar) {
00043     EN_ServiceInitialisationType oType;
00044     switch (iTypeChar) {
00045     case 'N': oType = NOT_YET_INITIALISED; break;
00046     case 'F': oType = FILE_PARSING; break;
00047     case 'B': oType = BUILTIN_SAMPLE; break;
00048     default: oType = LAST_VALUE; break;
00049     }
00050 
00051     if (oType == LAST_VALUE) {
00052       const std::string& lLabels = describeLabels();
00053       std::ostringstream oMessage;
00054       oMessage << "The service initialisation type '" << iTypeChar
00055                << "' is not known. "
00056                << "Known service initialisation types: " << lLabels;
00057       throw CodeConversionException (oMessage.str());
00058     }
00059 
00060     return oType;
00061   }
00062   
00063   // //////////////////////////////////////////////////////////////////////
00064   ServiceInitialisationType::
00065   ServiceInitialisationType (const char iTypeChar)
00066     : _type (getType (iTypeChar)) {
00067   }
00068   
00069   // //////////////////////////////////////////////////////////////////////
00070   ServiceInitialisationType::
00071   ServiceInitialisationType (const std::string& iTypeStr) {
00072     // 
00073     const size_t lSize = iTypeStr.size();
00074     assert (lSize == 1);
00075     const char lTypeChar = iTypeStr[0];
00076     _type = getType (lTypeChar);
00077   }
00078   
00079   // //////////////////////////////////////////////////////////////////////
00080   const std::string& ServiceInitialisationType::
00081   getLabel (const EN_ServiceInitialisationType& iType) {
00082     return _labels[iType];
00083   }
00084   
00085   // //////////////////////////////////////////////////////////////////////
00086   char ServiceInitialisationType::
00087   getTypeLabel (const EN_ServiceInitialisationType& iType) {
00088     return _typeLabels[iType];
00089   }
00090 
00091   // //////////////////////////////////////////////////////////////////////
00092   std::string ServiceInitialisationType::
00093   getTypeLabelAsString (const EN_ServiceInitialisationType& iType) {
00094     std::ostringstream oStr;
00095     oStr << _typeLabels[iType];
00096     return oStr.str();
00097   }
00098 
00099   // //////////////////////////////////////////////////////////////////////
00100   std::string ServiceInitialisationType::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   ServiceInitialisationType::EN_ServiceInitialisationType
00113   ServiceInitialisationType::getType() const {
00114     return _type;
00115   }
00116   
00117   // //////////////////////////////////////////////////////////////////////
00118   char ServiceInitialisationType::getTypeAsChar() const {
00119     const char oTypeChar = _typeLabels[_type];
00120     return oTypeChar;
00121   }
00122 
00123   // //////////////////////////////////////////////////////////////////////
00124   std::string ServiceInitialisationType::getTypeAsString() const {
00125     std::ostringstream oStr;
00126     oStr << _typeLabels[_type];
00127     return oStr.str();
00128   }
00129   
00130   // //////////////////////////////////////////////////////////////////////
00131   const std::string ServiceInitialisationType::describe() const {
00132     std::ostringstream ostr;
00133     ostr << _labels[_type];
00134     return ostr.str();
00135   }
00136 
00137   // //////////////////////////////////////////////////////////////////////
00138   bool ServiceInitialisationType::
00139   operator== (const EN_ServiceInitialisationType& iType) const {
00140     return (_type == iType);
00141   }
00142   
00143 }