Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: e9f7e0bd7369cb39415bcb3c759e35ffb317604c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
   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__