]> git.tdb.fi Git - gldbg.git/blobdiff - source/commandinterpreter.h
Replace per-file license notices with License.txt
[gldbg.git] / source / commandinterpreter.h
index 852ba65781241a3e12847ec4dc70b37ec067da2d..fa881c6883be885b6e2cc03974448e68783766fd 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of gldbg
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the GPL
-*/
-
 #ifndef COMMANDINTERPRETER_H_
 #define COMMANDINTERPRETER_H_
 
@@ -15,41 +8,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<std::string, Command> CommandMap;
+private:
+       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_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 &);
-       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