/* 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 #include namespace core { Func_t::Func_t(unsigned int funcflags) { func_flags = funcflags; } unsigned int Func_t::flags() { return func_flags; } namespace func { std::map registry; void add(const char * functionname, FuncPtr functionptr, unsigned int flags) { std::map::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::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::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::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::iterator it = registry.find(functionname); if (it == registry.end()) return 0; else return (*it).second; } void list() { std::map::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