#ifndef COMMAND_H #define COMMAND_H #pragma once #include #include #include extern "C"{ #include } #include "commandexecutor.h" using std::string; using std::vector; namespace mshconsole{ class Command { const string name; void checkObj(); vector opts; static const struct poptOption POPT_TERMINATOR; size_t optionNum; public: class Data{ public: union Arg{ int i; char* s; long l; float f; double d; }; enum Types{ STRING, INT, LONG, FLOAT, DOUBLE }; private: union Arg d; poptOption* of; Data(poptOption* o) : of(o), d() {} friend class mshconsole::Command; public: const union Arg& getArg() const; enum Types getType() const; int getInt() const; char* getString() const; long getLong() const; float getFloat() const; double getDouble() const; }; class Datas : public vector{ public: Data* getOptData(const string& optionName) const; Data* getOptData(char opt) const; Data* operator[](const string& opt) const; }; class DuplicatedOptionException{}; class CommandNameNotValidException{}; class InvalidOptionException{}; Command(const string& n, int (*funcptr)(CommandExecutor* whoExecuted,const Datas& data, const vector argv)); Command(const Command&); ~Command(); const string& getName(); int execute(const struct Params&, CommandExecutor*); void addOption(const poptOption& option); private: int (*funcCommand)(CommandExecutor* whoExecuted,const Datas& data, const vector argv); }; } #endif // COMMAND_H