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/cvar.h
parentd198b7b8d9ff713d891f35ab173d1f428f610e7d (diff)
major rewrite of Cvar, Func and Entity
Diffstat (limited to 'src/core/cvar.h')
-rw-r--r--src/core/cvar.h162
1 files changed, 93 insertions, 69 deletions
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<std::string, Cvar*> 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<std::string, Cvar> registry;
-
-} // namespace cvar
-
-} // namespace core
+}
#endif // __INCLUDED_CORE_CVAR_H__