Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 06aa5b6907e784524205923b04118231fa143419 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
   core/func.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include "core/func.h"
#include <map>
#include <string>

namespace core
{

Func_t::Func_t(unsigned int funcflags)
{
	func_flags = funcflags;
}

unsigned int Func_t::flags()
{
	return func_flags;
}

namespace func
{

std::map<std::string, Func> registry;

void add(const char * functionname, FuncPtr functionptr, unsigned int flags)
{
	std::map<std::string, Func>::iterator it = registry.find(functionname);
	if (it == registry.end()) {
		// function does not yet exist in the registry
		Func f = new Func_t(flags);
		//f->name = functionname;
		f->ptr = (void *)functionptr;
		registry[std::string(functionname)] = f;
	} else {
		con_warn << "Function '" << functionname << "' already registered!" << std::endl;
	}
}

void add(const char * functionname, GameFuncPtr gamefunctionptr, unsigned int flags)
{
	std::map<std::string, Func>::iterator it = registry.find(functionname);
	if (it == registry.end()) {
		// function does not yet exist in the registry
		Func f = new Func_t(flags & func::Game);
		//f->name = functionname;
		f->ptr = (void *)gamefunctionptr;
		registry[std::string(functionname)] = f;
	} else {
		con_warn << "Function '" << functionname << "' already registered!" << std::endl;
	}
}

void remove(const char *functionname)
{
	std::map<std::string, Func>::iterator it = registry.find(functionname);
        if (it != registry.end()) {
		delete (*it).second;
		registry.erase(std::string(functionname));
	}
}

void remove(const std::string &functionname)
{
	std::map<std::string, Func>::iterator it = registry.find(functionname);
        if (it != registry.end()) {
                delete (*it).second;
                registry.erase(std::string(functionname));
        }

}

Func find(const std::string &functionname)
{
	std::map<std::string, Func>::iterator it = registry.find(functionname);
	if (it == registry.end())
		return 0;
	else
		return (*it).second;
}

void list()
{
	std::map<std::string, Func>::iterator it;
	for (it = registry.begin(); it != registry.end(); it++) {
		std::string typeindicator;
		if ((*it).second->flags() & func::Game)
			typeindicator += 'G';
		else
			typeindicator += ' ';
		con_print << " " << typeindicator << " " << (*it).first << std::endl;
	}

	con_print << registry.size() << " registered functions" << std::endl;
}

} // namespace func

} // namespace core