Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
committerStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
commit982562fa19bb87a3dab352e562f386f61c171b7b (patch)
treeaeade8d5b7d3c68f5c222af1d8ecc6a734e1b43f /src/core/func.h
parentd198b7b8d9ff713d891f35ab173d1f428f610e7d (diff)
major rewrite of Cvar, Func and Entity
Diffstat (limited to 'src/core/func.h')
-rw-r--r--src/core/func.h88
1 files changed, 46 insertions, 42 deletions
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 <sstream>
@@ -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<std::string, Func> registry;
+ /// the function registry
+ static std::map<std::string, Func*> registry;
-} // namespace func
+private:
+ std::string func_name;
+ unsigned int func_flags;
+ void *func_ptr;
+};
-} // namespace core
+}
#endif // __INCLUDED_CORE_FUNC_H__