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/cvar.h | 162 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 93 insertions(+), 69 deletions(-) (limited to 'src/core/cvar.h') diff --git a/src/core/cvar.h b/src/core/cvar.h index bca3d8a..7350eee 100644 --- a/src/core/cvar.h +++ b/src/core/cvar.h @@ -13,82 +13,106 @@ namespace core { -/// the cvar container class -class Cvar_t +/// a variable encapsulation class +class Cvar { public: - - Cvar_t(unsigned int cvflags = 0); - - Cvar_t &operator=(const char *other); - Cvar_t &operator=(const std::string &other); - Cvar_t &operator=(float other); + /// Cvar flags + /** + * Archive a cvar with this flag will be saved to the configuration file + * ReadOnly the value of cvar with this flag can not be altered from the commandline + * Game a cvar with this flag is only valid when a game is loaded + */ + enum Flags {Archive=1, ReadOnly=2, Game=4}; - unsigned int flags() const; - float value() const; - const std::string &text() const; + /// create a new variable + Cvar(const char *name = 0, unsigned int flags = 0); + +/*----- inspectors ------------------------------------------------ */ + + /// returns the name of the variable + inline std::string const &name() { return cvar_name; } + + /// returns the flags of the variable + inline unsigned int flags() const { return cvar_flags; } + + /// returns the float value of the variable + inline float value() const { return cvar_value; } + + /// returns the string value of the variable + inline const std::string &str() const { return cvar_str; } + +/*----- mutators -------------------------------------------------- */ + + /// char * assignment operator + Cvar &operator=(const char *other); + + /// std::string assignment operator + Cvar &operator=(const std::string &other); + + /// float assignment operator + Cvar &operator=(float other); + +/* ---- Static functions for the Cvar registry -------------------- */ -private: - std::string cvar_text; - float cvar_value; - unsigned int cvar_flags; -}; + /// get a cvar value from the registry + /** If the a cvar with the given name already exists in the registry, + * its value will not be changed. If the cvar does not exist, + * it will be created + */ + static Cvar *get(const char *name, const char *value, unsigned int flags=0); + + /// get a cvar value from the registry + /** If the a cvar with the given name already exists in the registry, + * its value will not be changed. If the cvar does not exist, + * it will be created + */ + static Cvar *get(const char *name, float value, unsigned int flags=0); + + /// set a cvar value + /** If the a cvar with the given name already exists in the registry, + * its value will be replaced + */ + static Cvar *set(const char *name, const char *value, unsigned int flags=0); + + /// set a cvar value + /** If the a cvar with the given name already exists in the registry, + * its value will be replaced + */ + static Cvar *set(const char *name, float value, unsigned int flags=0); + + /// delete a cvar from the registry + static void unset(const char *name); + + /// delete a cvar from the registry + static void unset(std::string const &name); + + /// search for a named cvar, returns 0 if not found + static Cvar *find(std::string const &name); + + /// search for a named cvar, returns 0 if not found + static Cvar *find(const char *name); + + /// list the cvar registry + static void list(); + + /// the Cvar registry + static std::map registry; + + static Cvar *sv_dedicated; // dedicated server + static Cvar *sv_private; // client with private server + static Cvar *net_host; // network server ip (default binds to all interfaces) + static Cvar *net_port; // network port -/// general cvar type -typedef Cvar_t *Cvar; +private: + std::string cvar_name; + std::string cvar_str; + unsigned int cvar_flags; + float cvar_value; -/// the cvar registry -namespace cvar -{ +}; -/// cvar flags -enum Flags {Archive=1, ReadOnly=2, Game=4}; - -/// get a cvar value from the registry -/** If the a cvar with the given name already exists in the registry, - * its value will not be changed. If the cvar does not exist, - * it will be created - */ -Cvar get(const char *name, const char *value, int flags=0); -/// get a cvar value from the registry -/** If the a cvar with the given name already exists in the registry, - * its value will not be changed. If the cvar does not exist, - * it will be created - */ -Cvar get(const char *name, float value, int flags=0); - -/// set a cvar value -/** If the a cvar with the given name already exists in the registry, - * its value will be replaced - */ -Cvar set(const char *name, const char *value, int flags=0); -/// set a cvar value -/** If the a cvar with the given name already exists in the registry, - * its value will be replaced - */ -Cvar set(const char *name, float value, int flags=0); - -/// delete a cvar from the registry -void unset(const char *name); - -/// delete a cvar from the registry -void unset(const std::string &name); - -/// search for a named cvar, returns 0 if not found -Cvar find(const std::string &name); - -/// search for a named cvar, returns 0 if not found -Cvar find(const char *name); - -/// list the cvar registry -void list(); - -/// the Cvar registry -extern std::map registry; - -} // namespace cvar - -} // namespace core +} #endif // __INCLUDED_CORE_CVAR_H__ -- cgit v1.2.3