From 982562fa19bb87a3dab352e562f386f61c171b7b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 17 Feb 2008 18:59:52 +0000 Subject: major rewrite of Cvar, Func and Entity --- src/core/func.h | 88 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 42 deletions(-) (limited to 'src/core/func.h') diff --git a/src/core/func.h b/src/core/func.h index 3d91ab1..e34e32d 100644 --- a/src/core/func.h +++ b/src/core/func.h @@ -7,7 +7,6 @@ #ifndef __INCLUDED_CORE_FUNC_H__ #define __INCLUDED_CORE_FUNC_H__ -#include "sys/sys.h" #include "core/player.h" #include @@ -17,65 +16,70 @@ namespace core { -class Func_t +/// function pointer type for local functions +typedef void(* FuncPtr)(std::string const &args); + +/// fuction pointer for game functions +typedef void(* GameFuncPtr)(Player *player, std::string const &args); + +/// a function pointer encapsulation class +class Func { public: - Func_t(unsigned int fflags = 0); - - /// flags - unsigned int flags(); + /// function flags + enum Flags {Game=1}; + /// create a new function + Func(char const * funcname, void *ptr, unsigned int funcflags = 0); - /// pointer to the function - void *ptr; + ~Func(); -private: - unsigned int func_flags; -}; +/*----- inspectors ------------------------------------------------ */ -/// function type -typedef Func_t *Func; + /// returns the fucuntion flags + inline unsigned int flags() const { return func_flags; } -/// function pointer type for local functions -typedef void(* FuncPtr)(std::stringstream &args); + /// returns the name of the function + inline std::string const &name() const { return func_name; } -/// fuction pointer for game functions -typedef void(* GameFuncPtr)(Player &player, std::stringstream &args); +/*----- mutators -------------------------------------------------- */ + + /// execute the function if the Game flag is not set + void exec(std::string const &args); + + /// execute the function if the Game flag is set + void exec(Player *player, std::string const &args); -/// the function registry -namespace func -{ +/* ---- Static functions for the Func registry -------------------- */ -/// function flags -enum Flags {Game=1}; + /// add a function to the registry + static void add(const char *name, FuncPtr functionptr, unsigned int flags=0); -/// add a function to the registry -void add(const char *functionname, FuncPtr functionptr, unsigned int flags=0); + /// add a game function to the registry and set the Game flag + static void add(const char *name, GameFuncPtr functionptr, unsigned int flags=0); -/** - * @brief add a game function to the registry - * the flag core::func::Game will automaticly be set - */ -void add(const char *functionname, GameFuncPtr gamefunctionptr, unsigned int flags=0); + /// remove a function from the registry + static void remove(const char *name); -/// remove a function from the registry -void remove(const char *functionname); -void remove(const std::string &functionname); + /// remove a function from the registry + static void remove(std::string const &name); -/// find a fuction pointer -/** Returns 0 if the function pointer could not be found - */ -Func find(const std::string &functionname); + /// find a fuction pointer, return 0 if it could not be found + static Func *find(std::string const &name); -/// list the function registry -void list(); + /// list the function registry + static void list(); -/// the function registry -extern std::map registry; + /// the function registry + static std::map registry; -} // namespace func +private: + std::string func_name; + unsigned int func_flags; + void *func_ptr; +}; -} // namespace core +} #endif // __INCLUDED_CORE_FUNC_H__ -- cgit v1.2.3