fp@1142: /***************************************************************************** fp@1142: * fp@1142: * $Id$ fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #ifndef __COMMAND_H__ fp@1142: #define __COMMAND_H__ fp@1142: fp@1142: #include fp@1142: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "MasterDevice.h" fp@1142: fp@1142: /*****************************************************************************/ fp@1142: fp@1142: extern unsigned int masterIndex; fp@1142: extern int slavePosition; fp@1142: extern int domainIndex; fp@1142: extern string dataTypeStr; fp@1142: extern bool force; fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: class InvalidUsageException: fp@1142: public runtime_error fp@1142: { fp@1142: friend class Command; fp@1142: fp@1142: protected: fp@1142: /** Constructor with stringstream parameter. */ fp@1142: InvalidUsageException( fp@1142: const stringstream &s /**< Message. */ fp@1142: ): runtime_error(s.str()) {} fp@1142: }; fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: class CommandException: fp@1142: public runtime_error fp@1142: { fp@1142: friend class Command; fp@1142: fp@1142: protected: fp@1142: /** Constructor with stringstream parameter. */ fp@1142: CommandException( fp@1142: const stringstream &s /**< Message. */ fp@1142: ): runtime_error(s.str()) {} fp@1142: }; fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: class Command fp@1142: { fp@1142: public: fp@1142: Command(const string &, const string &); fp@1142: virtual ~Command(); fp@1142: fp@1142: enum Verbosity { fp@1142: Quiet, fp@1142: Normal, fp@1142: Verbose fp@1142: }; fp@1142: void setVerbosity(Verbosity); fp@1142: fp@1142: const string &getName() const; fp@1142: const string &getBriefDescription() const; fp@1142: Verbosity getVerbosity() const; fp@1142: fp@1142: bool matchesSubstr(const string &) const; fp@1142: bool matchesAbbrev(const string &) const; fp@1142: fp@1142: virtual string helpString() const = 0; fp@1142: fp@1142: typedef vector StringVector; fp@1142: virtual void execute(MasterDevice &, const StringVector &) = 0; fp@1142: fp@1142: protected: fp@1142: void throwInvalidUsageException(const stringstream &); fp@1142: void throwCommandException(const stringstream &); fp@1142: fp@1142: enum {BreakAfterBytes = 16}; fp@1142: static string numericInfo(); fp@1142: fp@1142: private: fp@1142: string name; fp@1142: string briefDesc; fp@1142: Verbosity verbosity; fp@1142: fp@1142: Command(); fp@1142: }; fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: inline const string &Command::getName() const fp@1142: { fp@1142: return name; fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: inline const string &Command::getBriefDescription() const fp@1142: { fp@1142: return briefDesc; fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: inline Command::Verbosity Command::getVerbosity() const fp@1142: { fp@1142: return verbosity; fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: #endif