/* 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 { namespace func { std::map registry; void add(const char * functionname, FuncPtr functionptr, unsigned int flags) { std::map::iterator it = registry.find(functionname); Func f; if (it == registry.end()) { // function does not yet exist in the registry f = new Func_t(); registry[std::string(functionname)] = f; } else { f = (*it).second; } f->name = functionname; f->ptr = (void *)functionptr; f->flags = flags; } void add(const char * functionname, GameFuncPtr gamefunctionptr, unsigned int flags) { std::map::iterator it = registry.find(functionname); Func f; if (it == registry.end()) { // function does not yet exist in the registry f = new Func_t(); registry[std::string(functionname)] = f; } else { f = (*it).second; } f->name = functionname; f->ptr = (void *)gamefunctionptr; f->flags = flags & func::Game; } 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() { char typeindicator; std::map::iterator it; for (it = registry.begin(); it != registry.end(); it++) { 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