]> git.tdb.fi Git - gldbg.git/blob - source/commandinterpreter.h
Add framework necessary to support more modular tools
[gldbg.git] / source / commandinterpreter.h
1 /* $Id$
2
3 This file is part of gldbg
4 Copyright © 2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
6 */
7
8 #ifndef COMMANDINTERPRETER_H_
9 #define COMMANDINTERPRETER_H_
10
11 #include <map>
12 #include <string>
13
14 class GlDbg;
15
16 class CommandInterpreter
17 {
18 public:
19         struct Command
20         {
21         private:
22                 std::string description;
23                 std::string help;
24
25         protected:
26                 Command() { }
27
28         public:
29                 void set_help(const std::string &);
30                 void set_help(const std::string &, const std::string &);
31                 const std::string &get_description() const { return description; }
32                 const std::string &get_help() const { return help; }
33
34                 virtual void execute(const std::string &) = 0;
35         };
36
37 private:
38         template<typename T>
39         class CommandFunction: public Command
40         {
41         private:
42                 typedef void (T::*Func)(const std::string &);
43
44                 T *obj;
45                 Func func;
46         public:
47                 CommandFunction(T *o, Func f): obj(o), func(f) { }
48
49                 virtual void execute(const std::string &a)
50                 { (obj->*func)(a); }
51         };
52
53         class CommandAlias: public Command
54         {
55         private:
56                 Command *target;
57
58         public:
59                 CommandAlias(Command *);
60
61                 const Command *get_target() const { return target; }
62
63                 virtual void execute(const std::string &);
64         };
65
66         typedef std::map<std::string, Command *> CommandMap;
67
68         GlDbg &gldbg;
69         CommandMap commands;
70
71 public:
72         CommandInterpreter(GlDbg &);
73
74         template<typename T>
75         Command &register_command(const std::string &n, T *o, void (T::*f)(const std::string &))
76         { return *(commands[n] = new CommandFunction<T>(o, f)); }
77
78         void execute(const std::string &);
79
80 private:
81         void cmd_help(const std::string &);
82         void cmd_run(const std::string &);
83         void cmd_continue(const std::string &);
84         void cmd_signal(const std::string &);
85         void cmd_kill(const std::string &);
86         void cmd_exit(const std::string &);
87         void cmd_trace(const std::string &);
88         void cmd_profile(const std::string &);
89         void cmd_state(const std::string &);
90         void cmd_texture(const std::string &);
91         void cmd_buffer(const std::string &);
92 };
93
94 #endif