X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2FResource.cc;h=42dd230175c985c2d7588fa3833a38395f5d6f1f;hb=3dcebcf56c6dd3a3707291e757af485bb55df7a6;hp=a6254bcb3ee334b9dbca2c469e7a65bbefd4175b;hpb=455b288c3e4b027060481f7c10e5931599d1ae96;p=chaz%2Fopenbox diff --git a/src/Resource.cc b/src/Resource.cc index a6254bcb..42dd2301 100644 --- a/src/Resource.cc +++ b/src/Resource.cc @@ -20,6 +20,7 @@ // DEALINGS IN THE SOFTWARE. #include "Resource.h" +#include "Util.h" #ifdef HAVE_CONFIG_H # include "../config.h" @@ -33,13 +34,27 @@ # include #endif // HAVE_STDIO_H -#include +bool obResource::m_initialized = false; obResource::obResource(const std::string &file) { setFile(file); m_modified = false; m_database = NULL; m_autosave = true; + if (!m_initialized) { + XrmInitialize(); + m_initialized = true; + } +} + +obResource::obResource() { + m_modified = false; + m_database = NULL; + m_autosave = true; + if (!m_initialized) { + XrmInitialize(); + m_initialized = true; + } } obResource::~obResource() { @@ -49,7 +64,6 @@ obResource::~obResource() { void obResource::setFile(const std::string &file) { m_file = file; - assert(m_file.c_str() != NULL); } void obResource::setAutoSave(bool autosave) { @@ -57,7 +71,7 @@ void obResource::setAutoSave(bool autosave) { } void obResource::save() { - assert(m_database != NULL); + ASSERT(m_database != NULL); XrmPutFileDatabase(m_database, m_file.c_str()); m_modified = false; } @@ -72,7 +86,7 @@ bool obResource::load() { } void obResource::setValue(const std::string &rname, bool value) { - assert(m_database != NULL); + ASSERT(m_database != NULL); const char *val = (value ? "True" : "False"); std::string rc_string = rname + ": " + val; @@ -83,8 +97,12 @@ void obResource::setValue(const std::string &rname, bool value) { save(); } +void obResource::setValue(const std::string &rname, int value) { + setValue(rname, (long)value); +} + void obResource::setValue(const std::string &rname, long value) { - assert(m_database != NULL); + ASSERT(m_database != NULL); char val[11]; sprintf(val, "%ld", value); @@ -97,7 +115,7 @@ void obResource::setValue(const std::string &rname, long value) { } void obResource::setValue(const std::string &rname, const char *value) { - assert(m_database != NULL); + ASSERT(m_database != NULL); std::string rc_string = rname + ": " + value; XrmPutLineResource(&m_database, rc_string.c_str()); @@ -108,7 +126,7 @@ void obResource::setValue(const std::string &rname, const char *value) { } void obResource::setValue(const std::string &rname, const std::string &value) { - assert(m_database != NULL); + ASSERT(m_database != NULL); std::string rc_string = rname + ": " + value; XrmPutLineResource(&m_database, rc_string.c_str()); @@ -120,9 +138,8 @@ void obResource::setValue(const std::string &rname, const std::string &value) { bool obResource::getValue(const std::string &rname, const std::string &rclass, bool &value) const { - assert(rname.c_str() != NULL); - assert(rclass.c_str() != NULL); - assert(m_database != NULL); + ASSERT(rclass.c_str() != NULL); + ASSERT(m_database != NULL); char *rettype; XrmValue retvalue; @@ -130,7 +147,7 @@ bool obResource::getValue(const std::string &rname, const std::string &rclass, &rettype, &retvalue) || retvalue.addr == NULL) return false; std::string val = retvalue.addr; - if (val == "True") + if (0 == strncasecmp(val.c_str(), "true", val.length())) value = true; else value = false; @@ -139,9 +156,7 @@ bool obResource::getValue(const std::string &rname, const std::string &rclass, bool obResource::getValue(const std::string &rname, const std::string &rclass, long &value) const { - assert(rname.c_str() != NULL); - assert(rclass.c_str() != NULL); - assert(m_database != NULL); + ASSERT(m_database != NULL); char *rettype; XrmValue retvalue; @@ -157,9 +172,7 @@ bool obResource::getValue(const std::string &rname, const std::string &rclass, bool obResource::getValue(const std::string &rname, const std::string &rclass, std::string &value) const { - assert(rname.c_str() != NULL); - assert(rclass.c_str() != NULL); - assert(m_database != NULL); + ASSERT(m_database != NULL); char *rettype; XrmValue retvalue;