From 151a2ac2434f4b4c23c107d9c21e4a18dd1a3c68 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 4 Feb 2008 18:42:05 +0000 Subject: converted client:: singleton classes to namespaces --- src/core/applicationinterface.cc | 10 +++++----- src/core/commandbuffer.cc | 2 +- src/core/func.cc | 26 +++++++++++++++++++------- src/core/func.h | 23 +++++++++++++++-------- 4 files changed, 40 insertions(+), 21 deletions(-) (limited to 'src/core') diff --git a/src/core/applicationinterface.cc b/src/core/applicationinterface.cc index 561bf94..6add2e0 100644 --- a/src/core/applicationinterface.cc +++ b/src/core/applicationinterface.cc @@ -110,12 +110,12 @@ void ApplicationInterface::init() filesystem::init(); // register our functions - func_register("print", func_print); - func_register("help", func_help); - func_register("quit", func_quit); + func::add("print", func_print); + func::add("help", func_help); + func::add("quit", func_quit); - func_register("connect", func_connect); - func_register("disconnect", func_disconnect); + func::add("connect", func_connect); + func::add("disconnect", func_disconnect); if (game()) game()->connected = false; diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 292013b..7ba1e08 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -25,7 +25,7 @@ void exec(const char *text) cmdstream >> cmdname; - Func f = func_find(cmdname); + Func f = func::find(cmdname); if (f) { f(cmdstream); diff --git a/src/core/func.cc b/src/core/func.cc index b89e556..bcc6f50 100644 --- a/src/core/func.cc +++ b/src/core/func.cc @@ -6,25 +6,37 @@ #include "core/func.h" #include +#include namespace core { -std::map functionmap; +namespace func +{ + +std::map registry; -void func_register(const char * functionname, Func functionptr) +void add(const char * functionname, Func functionptr) { - functionmap[std::string(functionname)] = functionptr; + registry[std::string(functionname)] = functionptr; } -void func_unregister(std:: string functionname) +void remove(const char *functionname) { - functionmap.erase(std::string(functionname)); + registry.erase(std::string(functionname)); } -Func func_find(std::string functionname) +void remove(const std::string &functionname) { - return functionmap[functionname]; + registry.erase(functionname); } +Func find(const std::string &functionname) +{ + return registry[functionname]; +} + +} // namespace func + } // namespace core + diff --git a/src/core/func.h b/src/core/func.h index 901490e..b3d446f 100644 --- a/src/core/func.h +++ b/src/core/func.h @@ -1,5 +1,5 @@ /* - core/core.h + core/funct.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ @@ -10,19 +10,26 @@ #include namespace core { - /// function pointer type - typedef void (* Func)(std::stringstream &args); - /// register a function pointer - void func_register(const char *functionname, Func functionptr); +/// function pointer type +typedef void (* Func)(std::stringstream &args); - /// unregister a function pointer - void func_unregister(std:: string functionname); +/// the function registry +namespace func +{ + /// add a function to the registry + void add(const char *functionname, Func functionptr); + + /// remove a function from the registry + void remove(const char *functionname); + void remove(const std::string &functionname); /// find a fuction pointer /** Returns 0 if the function pointer could not be found */ - Func func_find(std::string functionname); + Func find(const std::string &functionname); +} + } #endif // __INCLUDED_CORE_FUNC_H__ -- cgit v1.2.3