Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/cvar.cc40
-rw-r--r--src/core/cvar.h30
-rw-r--r--src/core/func.cc20
3 files changed, 67 insertions, 23 deletions
diff --git a/src/core/cvar.cc b/src/core/cvar.cc
index 6b4302d..f043028 100644
--- a/src/core/cvar.cc
+++ b/src/core/cvar.cc
@@ -47,28 +47,33 @@ void Cvar::set_info(const char* info)
cvar_info.assign(info);
}
-Cvar & Cvar::operator=(const std::string& other)
+void Cvar::assign(const std::string& other)
{
cvar_str = other;
std::stringstream s(cvar_str);
if (!(s >> cvar_value))
cvar_value = cvar_str.size();
- return (*this);
}
-Cvar & Cvar::operator=(const char* other)
+void Cvar::assign(const char* other)
{
- std::string value(other);
- return (this->operator=(value));
+ if (other) {
+ cvar_str.assign(other);
+ std::stringstream s(cvar_str);
+ if (!(s >> cvar_value))
+ cvar_value = cvar_str.size();
+ } else {
+ cvar_str.clear();
+ cvar_value = 0;
+ }
}
-Cvar & Cvar::operator=(const float other)
+void Cvar::assign(const float other)
{
std::stringstream s;
s << other;
s >> cvar_str;
cvar_value = other;
- return (*this);
}
Cvar* Cvar::get(const char* name, const char* value, const unsigned int flags)
@@ -76,8 +81,8 @@ Cvar* Cvar::get(const char* name, const char* value, const unsigned int flags)
Cvar *c = find(name);
if (!c) {
c = new Cvar(name, flags);
+ c->assign(value);
cvar_registry[c->name()] = c;
- (*c) = value;
}
c->cvar_flags |= flags;
return c;
@@ -88,8 +93,8 @@ Cvar* Cvar::get(const char* name, const float value, const unsigned int flags)
Cvar *c = find(name);
if (!c) {
c = new Cvar(name, flags);
+ c->assign(value);
cvar_registry[c->name()] = c;
- (*c) = value;
}
c->cvar_flags |= flags;
return c;
@@ -102,7 +107,7 @@ Cvar* Cvar::set(const char* name, const char* value, const unsigned int flags)
c = new Cvar(name, flags);
cvar_registry[c->name()] = c;
}
- (*c) = value;
+ c->assign(value);
c->cvar_flags = flags;
//con_debug << "set " << name << " " << cvar->str() << std::endl;
@@ -116,7 +121,7 @@ Cvar* Cvar::set(const char* name, const float value, const unsigned int flags)
c = new Cvar(name, flags);
cvar_registry[c->name()] = c;
}
- (*c) = value;
+ c->assign(value);
c->cvar_flags = flags;
//con_debug << "set " << name << " " << cvar->str() << std::endl;
@@ -135,7 +140,11 @@ void Cvar::unset(const std::string& name)
void Cvar::unset(const char* name)
{
- unset(std::string(name));
+ if (!name)
+ return;
+
+ std::string namestr(name);
+ unset(namestr);
}
Cvar *Cvar::find(const std::string& name)
@@ -149,8 +158,11 @@ Cvar *Cvar::find(const std::string& name)
Cvar *Cvar::find(const char* name)
{
- std::string s(name);
- return(find(s));
+ if (!name)
+ return 0;
+
+ std::string namestr(name);
+ return(find(namestr));
}
void Cvar::list()
diff --git a/src/core/cvar.h b/src/core/cvar.h
index 3d7b246..21491fd 100644
--- a/src/core/cvar.h
+++ b/src/core/cvar.h
@@ -65,14 +65,34 @@ public:
/// set the info string
void set_info(const char* info);
- /// char * assignment operator
- Cvar &operator=(const char* other);
+ /// std::string assignment
+ void assign(const std::string& other);
+
+ /// char * assignment
+ void assign(const char* other);
+
+ /// float assignment
+ void assign(const float other);
/// std::string assignment operator
- Cvar &operator=(const std::string& other);
+ inline Cvar & operator=(const std::string& other)
+ {
+ assign(other);
+ return (*this);
+ }
+ /// char * assignment operator
+ inline Cvar & operator=(const char* other)
+ {
+ assign(other);
+ return (*this);
+ }
/// float assignment operator
- Cvar &operator=(const float other);
+ inline Cvar & operator=(const float other)
+ {
+ assign(other);
+ return (*this);
+ }
/* ---- Static functions for the Cvar registry -------------------- */
@@ -107,7 +127,7 @@ public:
* 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, const unsigned int flags = 0);
+ static Cvar* set(const char* name, const float value, const unsigned int flags = 0);
/// search for a named cvar, returns 0 if not found
static Cvar* find(const std::string& name);
diff --git a/src/core/func.cc b/src/core/func.cc
index be5aca3..4072f39 100644
--- a/src/core/func.cc
+++ b/src/core/func.cc
@@ -20,11 +20,15 @@ Func::Registry Func::func_registry;
Func * Func::add(const char *name, FuncPtr functionptr, bool shared)
{
+ if (!name || !functionptr)
+ return 0;
+
Func *func = 0;
Registry::iterator it = func_registry.find(name);
if (it == func_registry.end()) {
- func = new Func(name, (void *)functionptr, shared ? Shared : 0);
- func_registry[std::string(name)] = func;
+ std::string funcname(name);
+ func = new Func(funcname.c_str(), (void *)functionptr, shared ? Shared : 0);
+ func_registry[func->name()] = func;
//con_debug << "Function '" << name << "' registered." << std::endl;
} else {
con_warn << "Function '" << name << "' already registered!" << std::endl;
@@ -35,10 +39,14 @@ Func * Func::add(const char *name, FuncPtr functionptr, bool shared)
Func *Func::add(const char *name, GameFuncPtr gamefunctionptr)
{
+ if (!name || !gamefunctionptr)
+ return 0;
+
Func *func = 0;
Registry::iterator it = func_registry.find(name);
if (it == func_registry.end()) {
- func = new Func(name, (void *)gamefunctionptr, Game);
+ std::string funcname(name);
+ func = new Func(funcname.c_str(), (void *)gamefunctionptr, Game);
func_registry[func->name()] = func;
//con_debug << "Function '" << name << "' registered." << std::endl;
} else {
@@ -50,10 +58,14 @@ Func *Func::add(const char *name, GameFuncPtr gamefunctionptr)
Func *Func::add(const char *name, TargetFuncPtr targetfunctionptr)
{
+ if (!name || !targetfunctionptr)
+ return 0;
+
Func *func = 0;
Registry::iterator it = func_registry.find(name);
if (it == func_registry.end()) {
- func = new Func(name, (void *)targetfunctionptr, Game | Target);
+ std::string funcname(name);
+ func = new Func(funcname.c_str(), (void *)targetfunctionptr, Game | Target);
func_registry[func->name()] = func;
//con_debug << "Function '" << name << "' registered." << std::endl;
} else {