diff options
Diffstat (limited to 'src/core/cvar.cc')
-rw-r--r-- | src/core/cvar.cc | 40 |
1 files changed, 26 insertions, 14 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() |