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

stdair/basic/JSonCommand.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/JSonCommand.hpp>
00010 
00011 namespace stdair {
00012   
00013   // //////////////////////////////////////////////////////////////////////
00014   const std::string JSonCommand::_labels[LAST_VALUE] =
00015     { "list", "flight_date", "event_list", "break_point", "run", "reset", "status", "config"};
00016 
00017   // //////////////////////////////////////////////////////////////////////
00018   JSonCommand::JSonCommand()
00019     : _command (LAST_VALUE) {
00020     assert (false);
00021   }
00022 
00023   // //////////////////////////////////////////////////////////////////////
00024   JSonCommand::
00025   JSonCommand (const JSonCommand& iJSonCommand)
00026     : _command (iJSonCommand._command) {
00027   }
00028 
00029   // //////////////////////////////////////////////////////////////////////
00030   JSonCommand::EN_JSonCommand
00031   JSonCommand::getCommand (const std::string& iCommandStr) {
00032  
00033     EN_JSonCommand oJSonCommand;
00034     if (iCommandStr == "list") {
00035       oJSonCommand = LIST;
00036     } else if (iCommandStr == "flight_date") {
00037       oJSonCommand = FLIGHT_DATE; 
00038     } else if (iCommandStr == "event_list") {
00039       oJSonCommand = EVENT_LIST; 
00040     } else if (iCommandStr == "break_point") {
00041       oJSonCommand = BREAK_POINT; 
00042     } else if (iCommandStr == "run") {
00043       oJSonCommand = RUN; 
00044     } else if (iCommandStr == "reset") {
00045       oJSonCommand = RESET;  
00046     } else if (iCommandStr == "status") {
00047       oJSonCommand = STATUS;  
00048     } else if (iCommandStr == "config") {
00049       oJSonCommand = CONFIG; 
00050     } else {
00051       oJSonCommand = LAST_VALUE;
00052     }
00053 
00054     if (oJSonCommand == LAST_VALUE) {
00055       const std::string& lLabels = describeLabels();
00056       std::ostringstream oMessage;
00057       oMessage << "The JSON command '" << iCommandStr
00058                << "' is not known. Known forecasting commands: " << lLabels;
00059       throw CodeConversionException (oMessage.str());
00060     }
00061 
00062     return oJSonCommand;
00063   }
00064 
00065   // //////////////////////////////////////////////////////////////////////
00066   std::string JSonCommand::getLabel(const EN_JSonCommand& iCommand) {
00067     return _labels[iCommand];
00068   }
00069   
00070   // //////////////////////////////////////////////////////////////////////
00071   JSonCommand::JSonCommand (const std::string& iCommandStr) {
00072     // 
00073     _command = getCommand (iCommandStr);
00074   }
00075 
00076   // //////////////////////////////////////////////////////////////////////
00077   std::string JSonCommand::describeLabels() {
00078     std::ostringstream ostr;
00079     for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
00080       if (idx != 0) {
00081         ostr << ", ";
00082       }
00083       ostr << _labels[idx] << " ";//'" << _commandLabels[idx] << "'";
00084     }
00085     return ostr.str();
00086   }
00087 
00088   // //////////////////////////////////////////////////////////////////////
00089   JSonCommand::EN_JSonCommand JSonCommand::getCommand() const {
00090     return _command;
00091   }
00092   
00093   // //////////////////////////////////////////////////////////////////////
00094   const std::string JSonCommand::describe() const {
00095     std::ostringstream ostr;
00096     ostr << _labels[_command];
00097     return ostr.str();
00098   }
00099 
00100   // //////////////////////////////////////////////////////////////////////
00101   bool JSonCommand::
00102   operator== (const EN_JSonCommand& iCommand) const {
00103     return (_command == iCommand);
00104   }
00105   
00106 }