Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-11-23 12:34:07 +0000
committerStijn Buys <ingar@osirion.org>2008-11-23 12:34:07 +0000
commit583ec3285c41e9d253c4aaabd2af4dadac75f3a7 (patch)
tree5ec345e44af9d3699a95f493d8358ee766e23330 /src/core/loader.h
parent44158ccfbe943b832c0e0bf9ce547212aa6c2b8b (diff)
clean module consturction/destruction
Diffstat (limited to 'src/core/loader.h')
-rw-r--r--src/core/loader.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/core/loader.h b/src/core/loader.h
new file mode 100644
index 0000000..1fde764
--- /dev/null
+++ b/src/core/loader.h
@@ -0,0 +1,62 @@
+/*
+ core/loader.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CORE_LOADER_H__
+#define __INCLUDED_CORE_LOADER_H__
+
+#include <string>
+
+#include "core/module.h"
+
+namespace core {
+
+/// module factory registry
+/** The Loader contains a list of module factories and can load
+ * the desired module on request
+ */
+class Loader
+{
+public:
+ /// function pointer type for a module factory
+ typedef Module * (* FactoryFuncPtr)();
+
+ /// find a registered mmodule factory
+ static FactoryFuncPtr find(const char *label);
+
+ /// find a registered module factory
+ static FactoryFuncPtr find(const std::string &label);
+
+ /// add a factory to the loader registry
+ static void add(const std::string & label, FactoryFuncPtr factory);
+
+ /// assign the next module to init
+ static bool load(const char *label);
+
+ /// assign the next module to init
+ static bool load(const std::string &label);
+
+ static inline const std::string &label() { return loader_label; }
+
+ /// initialize a game module
+ static Module *init();
+
+ /// list registered modules
+ static void list();
+
+ /// clear the loader registry
+ static void clear();
+
+private:
+ typedef std::map<std::string, FactoryFuncPtr> Registry;
+
+ static Registry loader_registry;
+ static std::string loader_label;
+};
+
+}
+
+#endif // __INCLUDED_CORE_LOADER_H__
+