]> git.tdb.fi Git - gldbg.git/blobdiff - source/tool.h
Add framework necessary to support more modular tools
[gldbg.git] / source / tool.h
diff --git a/source/tool.h b/source/tool.h
new file mode 100644 (file)
index 0000000..b299e2a
--- /dev/null
@@ -0,0 +1,57 @@
+/* $Id$
+
+This file is part of gldbg
+Copyright © 2010  Mikko Rasa, Mikkosoft Productions
+Distributed under the GPL
+*/
+
+#ifndef TOOL_H_
+#define TOOL_H_
+
+#include <list>
+
+class GlDbg;
+
+class Tool
+{
+public:
+       class Factory
+       {
+       protected:
+               Factory();
+
+       public:
+               virtual Tool *create(GlDbg &) const = 0;
+       };
+
+protected:
+       Tool() { }
+public:
+       virtual ~Tool() { }
+
+       virtual void decode(const char *, unsigned) = 0;
+
+       static std::list<Factory *> &get_factories();
+};
+
+
+template<typename T>
+class RegisteredTool: public Tool
+{
+protected:
+       class Factory: public Tool::Factory
+       {
+               virtual Tool *create(GlDbg &g) const { return new T(g); }
+       };
+
+       static Factory factory;
+
+protected:
+       // The no-op expression is necessary to instantiate the static member
+       RegisteredTool() { (void)factory; }
+};
+
+template<typename T>
+typename RegisteredTool<T>::Factory RegisteredTool<T>::factory;
+
+#endif