Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-05 00:09:22 +0000
committerStijn Buys <ingar@osirion.org>2008-02-05 00:09:22 +0000
commitcf61370df80de6dc659dbd9b803c973b300c1b4c (patch)
tree7eba1f644a96a3269a63f447d3ce9676b854819b /src
parentad340b52a0a4e86edd5b54b01d74aac731a6a812 (diff)
don't use cvar
Diffstat (limited to 'src')
-rw-r--r--src/core/cvar.cc58
-rw-r--r--src/core/cvar.h22
-rw-r--r--src/core/func.h32
3 files changed, 69 insertions, 43 deletions
diff --git a/src/core/cvar.cc b/src/core/cvar.cc
index ef3f06c..21105b4 100644
--- a/src/core/cvar.cc
+++ b/src/core/cvar.cc
@@ -4,20 +4,20 @@
the terms of the GNU General Public License version 2
*/
-#include "cvar.h"
+#include "core/cvar.h"
+#include "sys/sys.h"
+
#include <map>
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <iomanip>
-namespace core {
-Cvar_t::Cvar_t(const char *cvarname, unsigned int cvarflags)
-{
- cvar_name.assign(cvarname);
- cvar_flags = cvarflags;
-}
+namespace core {
-Cvar_t::Cvar_t(const std::string &cvarname, unsigned int cvarflags)
+Cvar_t::Cvar_t(unsigned int cvarflags)
{
- cvar_name = cvarname;
cvar_flags = cvarflags;
}
@@ -46,14 +46,30 @@ namespace cvar
std::map<std::string, Cvar> registry;
-Cvar set(const char *cvarname, const char *value)
+Cvar set(const char *cvarname, const char *cvarvalue, int cvarflags)
+{
+ Cvar c = registry[std::string(cvarname)];
+ if (c) {
+ con_debug << "cvar::set " << cvarname << " already exist with value " << cvarvalue << std::endl;
+ } else {
+ con_debug << "cvar::set " << cvarname << " with value " << cvarvalue << std::endl;
+ c = new Cvar_t(cvarflags);
+ registry[std::string(cvarname)] = c;
+ (*c) = cvarvalue;
+ }
+ return c;
+}
+
+Cvar set(const char *cvarname, int cvarvalue, int cvarflags)
{
Cvar c = registry[std::string(cvarname)];
- if (!c) {
- // not found, create a new variable and assign value
- c = new Cvar_t(cvarname);
+ if (c) {
+ con_debug << "cvar::set " << cvarname << " already exist with value " << cvarvalue << std::endl;
+ } else {
+ con_debug << "cvar::set " << cvarname << " with value " << cvarvalue << std::endl;
+ c = new Cvar_t(cvarflags);
registry[std::string(cvarname)] = c;
- (*c) = value;
+ (*c) = cvarvalue;
}
return c;
}
@@ -62,6 +78,7 @@ void unset(const char *cvarname)
{
Cvar c = registry[std::string(cvarname)];
if (c) {
+ con_debug << "cvar::unset " << cvarname << std::endl;
registry.erase(std::string(cvarname));
delete c;
}
@@ -71,6 +88,7 @@ void unset(const std::string &cvarname)
{
Cvar c = registry[cvarname];
if (c) {
+ con_debug << "cvar::unset " << cvarname << std::endl;
registry.erase(cvarname);
delete c;
}
@@ -85,7 +103,17 @@ Cvar find(const char *cvarname)
{
return registry[std::string(cvarname)];
}
-
+
+void list()
+{
+ std::map<std::string, Cvar>::iterator registryiterator;
+ for (registryiterator = registry.begin(); registryiterator != registry.end(); registryiterator++) {
+ con_print << std::setw(4) << (*registryiterator).second->flags()
+ << " " << (*registryiterator).first
+ << " " << (*registryiterator).second->value() << std::endl;
+ }
+}
+
} // namespace cvar
} // namespace core
diff --git a/src/core/cvar.h b/src/core/cvar.h
index f407395..8ad0fa1 100644
--- a/src/core/cvar.h
+++ b/src/core/cvar.h
@@ -7,51 +7,49 @@
#ifndef __INCLUDED_CORE_CVAR_H__
#define __INCLUDED_CORE_CVAR_H__
-#include <sstream>
+#include <string>
namespace core {
-/** new cvars have to be added through the cvar::set functions
- * and not created directly.
- */
+/// Don't use - need a decent cvar
class Cvar_t {
public:
- Cvar_t(const char *cvarname, unsigned int cvarflags = 0);
- Cvar_t(const std::string &cvarname, unsigned int cvarflags = 0);
+ Cvar_t(unsigned int cvarflags = 0);
- inline const std::string &name() const { return cvar_name; }
inline const std::string &value() const {return cvar_value; }
+ inline unsigned int flags() const { return cvar_flags; }
Cvar_t &operator=(const char *cvarvalue);
Cvar_t &operator=(const std::string &cvarvalue);
Cvar_t &operator=(int cvarvalue);
private:
- std::string cvar_name;
std::string cvar_value;
unsigned int cvar_flags;
};
+/// general cvar type
typedef Cvar_t *Cvar;
-/// the cvar registry
+/// Don't use - need a decent cvar
namespace cvar
{
/// create a new cvar containing a string value
-Cvar set(const char *cvarname, const char *value);
+Cvar set(const char *cvarname, const char *cvarvalue, int cvarflags=0);
/// create a new cvar containing an integer value
-Cvar set(const char *cvarname, int value);
+Cvar set(const char *cvarname, int cvarvalue, int cvarflags=0);
/// delete a cvar
void unset(const char *cvarname);
-// delete a cvar
+/// delete a cvar
void unset(const std::string &cvarname);
/// search for a named cvar, returns 0 if not found
Cvar find(const std::string &cvarname);
+
/// search for a named cvar, returns 0 if not found
Cvar find(const char *cvarname);
diff --git a/src/core/func.h b/src/core/func.h
index b3d446f..1af69c0 100644
--- a/src/core/func.h
+++ b/src/core/func.h
@@ -1,7 +1,7 @@
/*
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
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CORE_FUNC_H__
@@ -9,25 +9,25 @@
#include <sstream>
-namespace core {
+namespace core
+{
/// function pointer type
typedef void (* Func)(std::stringstream &args);
/// 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 find(const std::string &functionname);
+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 find(const std::string &functionname);
}
}