/** \defgroup Parsing Parsing classes */

/** @addtogroup Parsing
    @{
*/

/** @file CCommandParser.h
    \brief This file contains the declaration of the CCommandParser class

    It parses the command and give tokens to the CCommandExecutor class.  
    It implements the singleton pattern.
*/

#ifndef CCOMMANDPARSER_H
#define CCOMMANDPARSER_H

/**
   \brief This function gets a line from a stream
*/
inline void GetLine(std::istream& i, std::string& s)
{
#ifdef WIN32
  char c;
  s = "";
  std::cin.get(c);
  while(isprint(c))
    {
      s += c;
      std::cin.get(c);
    }
#elif defined LINUX
  std::getline(i, s);
#else
#error OS not supported
#endif
}


/**
   \brief This class parses the command and give tokens to the 
   CCommandExecutor class.

   It takes care of error checking and implements the singleton pattern.
*/

class CCommandParser
{
 public:
  /**
     \brief This function returns a pointer to the unique instance
     of the CCommandParser and creates it if it doesn't exist yet.
  */
  static CCommandParser* getInstance()
    {
      if (s_pInstance == NULL)
        {
          s_pInstance = new CCommandParser;
        }
      return s_pInstance;
    }

  /**
     \brief This function frees the unique instance of the
     CCommandParsor.
  */
  static void freeInstance()
    {
      if (s_pInstance)
        {
          delete s_pInstance;
          s_pInstance = NULL;
        }
    }


  /**
     \brief This function parses a command and fills a CCommand 
     structure to be executed.
  */
  CCommand Parse(std::string StrCommand) const;


 private:
  /**
     \brief The CCommandParser empty private constructor.
  */
  CCommandParser() {}


  /**
     \brief This function converts a string into a floating point value.
  */
  static bool StringToFloat(const std::string& StringNumber, float* pFloat);

  /**
     \brief This function converts a string into a integer value.
  */
  static bool StringToInt(const std::string& StringNumber, int* pInt);


  static CCommandParser* s_pInstance; /** Static pointer to the unique
                                          instance of the CCommandParser. */
};


#endif  // CCOMMANDPARSER_H

/** @} */
