X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcommandinterpreter.h;h=d39b8b13c0559e7b8d424e797630f5f6372cbf5f;hb=ea3d851aa52e999b1c5a5fa52c97ff5019756c0e;hp=bdd3c174b2d993a2a34c694e1d6be279d627e7d3;hpb=0be9f22fa27bfca77f494489fce0e62b66882e5b;p=gldbg.git diff --git a/source/commandinterpreter.h b/source/commandinterpreter.h index bdd3c17..d39b8b1 100644 --- a/source/commandinterpreter.h +++ b/source/commandinterpreter.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of gldbg -Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions Distributed under the GPL */ @@ -15,37 +15,80 @@ class GlDbg; class CommandInterpreter { -private: +public: struct Command { - typedef void (CommandInterpreter::*Func)(const std::string &); - - Func func; + private: std::string description; std::string help; - Command(); - Command(Func, const std::string &); - Command(Func, const std::string &, const std::string &); + protected: + Command() { } + public: + virtual ~Command() { } + + 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; }; - typedef std::map CommandMap; +private: + 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_break(const std::string &); + void cmd_unbreak(const std::string &); + void cmd_next(const std::string &); + void cmd_finish(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 &); }; #endif