From 583ec3285c41e9d253c4aaabd2af4dadac75f3a7 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 23 Nov 2008 12:34:07 +0000 Subject: clean module consturction/destruction --- src/core/loader.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/core/loader.h (limited to 'src/core/loader.h') 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 + +#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 Registry; + + static Registry loader_registry; + static std::string loader_label; +}; + +} + +#endif // __INCLUDED_CORE_LOADER_H__ + -- cgit v1.2.3