diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-04 18:42:05 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-04 18:42:05 +0000 |
commit | 151a2ac2434f4b4c23c107d9c21e4a18dd1a3c68 (patch) | |
tree | 18154b52b44327de28d82ff187f25c8369ddc5d9 /src/core | |
parent | 09fb43f3d36847977ac202c10c5a11f34af03a43 (diff) |
converted client:: singleton classes to namespaces
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/applicationinterface.cc | 10 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 2 | ||||
-rw-r--r-- | src/core/func.cc | 26 | ||||
-rw-r--r-- | src/core/func.h | 23 |
4 files changed, 40 insertions, 21 deletions
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 <map> +#include <string> namespace core { -std::map<std::string, Func> functionmap; +namespace func +{ + +std::map<std::string, Func> 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 <sstream> 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__ |