]> git.tdb.fi Git - gldbg.git/blob - source/tool.h
Add framework necessary to support more modular tools
[gldbg.git] / source / tool.h
1 /* $Id$
2
3 This file is part of gldbg
4 Copyright © 2010  Mikko Rasa, Mikkosoft Productions
5 Distributed under the GPL
6 */
7
8 #ifndef TOOL_H_
9 #define TOOL_H_
10
11 #include <list>
12
13 class GlDbg;
14
15 class Tool
16 {
17 public:
18         class Factory
19         {
20         protected:
21                 Factory();
22
23         public:
24                 virtual Tool *create(GlDbg &) const = 0;
25         };
26
27 protected:
28         Tool() { }
29 public:
30         virtual ~Tool() { }
31
32         virtual void decode(const char *, unsigned) = 0;
33
34         static std::list<Factory *> &get_factories();
35 };
36
37
38 template<typename T>
39 class RegisteredTool: public Tool
40 {
41 protected:
42         class Factory: public Tool::Factory
43         {
44                 virtual Tool *create(GlDbg &g) const { return new T(g); }
45         };
46
47         static Factory factory;
48
49 protected:
50         // The no-op expression is necessary to instantiate the static member
51         RegisteredTool() { (void)factory; }
52 };
53
54 template<typename T>
55 typename RegisteredTool<T>::Factory RegisteredTool<T>::factory;
56
57 #endif