]> git.tdb.fi Git - gldbg.git/blobdiff - source/commandinterpreter.h
Add some virtual destructors to shut up older gcc versions
[gldbg.git] / source / commandinterpreter.h
index 8ce59d0a85fc02343908bf3001c21050227ea6f6..cc6246e927390465301983e03cd290662a8d37e3 100644 (file)
@@ -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,24 +15,76 @@ class GlDbg;
 
 class CommandInterpreter
 {
+public:
+       struct Command
+       {
+       private:
+               std::string description;
+               std::string help;
+
+       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;
+       };
+
 private:
-       typedef void (CommandInterpreter::*CommandFunc)(const std::string &);
-       typedef std::map<std::string, CommandFunc> CommandMap;
+       template<typename T>
+       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<std::string, Command *> CommandMap;
 
        GlDbg &gldbg;
        CommandMap commands;
 
 public:
        CommandInterpreter(GlDbg &);
+
+       template<typename T>
+       Command &register_command(const std::string &n, T *o, void (T::*f)(const std::string &))
+       { return *(commands[n] = new CommandFunction<T>(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 &);
 };
 
 #endif