X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcommandinterpreter.h;h=487abb232fcdfcd6e4cb79cc56214db0720b19cb;hb=de6ac03ffc36843bbbb0d496007b3046a4422ee1;hp=8ce59d0a85fc02343908bf3001c21050227ea6f6;hpb=c6b2f7585d51164dc32f4dd2a05855913e464c58;p=gldbg.git diff --git a/source/commandinterpreter.h b/source/commandinterpreter.h index 8ce59d0..487abb2 100644 --- a/source/commandinterpreter.h +++ b/source/commandinterpreter.h @@ -15,24 +15,80 @@ class GlDbg; class CommandInterpreter { +public: + struct Command + { + private: + std::string description; + std::string help; + + protected: + Command() { } + + public: + void set_help(const std::string &); + void set_help(const std::string &, const std::string &); + const std::string &get_description() const { return description; } + const std::string &get_help() const { return help; } + + virtual void execute(const std::string &) = 0; + }; + private: - typedef void (CommandInterpreter::*CommandFunc)(const std::string &); - typedef std::map CommandMap; + template + class CommandFunction: public Command + { + private: + typedef void (T::*Func)(const std::string &); + + T *obj; + Func func; + public: + CommandFunction(T *o, Func f): obj(o), func(f) { } + + virtual void execute(const std::string &a) + { (obj->*func)(a); } + }; + + class CommandAlias: public Command + { + private: + Command *target; + + public: + CommandAlias(Command *); + + const Command *get_target() const { return target; } + + virtual void execute(const std::string &); + }; + + typedef std::map CommandMap; GlDbg &gldbg; CommandMap commands; public: CommandInterpreter(GlDbg &); + + template + Command ®ister_command(const std::string &n, T *o, void (T::*f)(const std::string &)) + { return *(commands[n] = new CommandFunction(o, f)); } + void execute(const std::string &); private: + void cmd_help(const std::string &); void cmd_run(const std::string &); void cmd_continue(const std::string &); void cmd_signal(const std::string &); void cmd_kill(const std::string &); void cmd_exit(const std::string &); void cmd_trace(const std::string &); + void cmd_profile(const std::string &); + void cmd_state(const std::string &); + void cmd_texture(const std::string &); + void cmd_buffer(const std::string &); }; #endif