X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FResource.cc;h=2a678f89dafde320e75491ca3741599e424a84ba;hb=0a3cfdfcb956024639a05549a50586e3d826b42e;hp=42dd230175c985c2d7588fa3833a38395f5d6f1f;hpb=3dcebcf56c6dd3a3707291e757af485bb55df7a6;p=chaz%2Fopenbox diff --git a/src/Resource.cc b/src/Resource.cc index 42dd2301..2a678f89 100644 --- a/src/Resource.cc +++ b/src/Resource.cc @@ -34,9 +34,9 @@ # include #endif // HAVE_STDIO_H -bool obResource::m_initialized = false; +bool Resource::m_initialized = false; -obResource::obResource(const std::string &file) { +Resource::Resource(const std::string &file) { setFile(file); m_modified = false; m_database = NULL; @@ -47,7 +47,7 @@ obResource::obResource(const std::string &file) { } } -obResource::obResource() { +Resource::Resource() { m_modified = false; m_database = NULL; m_autosave = true; @@ -57,26 +57,26 @@ obResource::obResource() { } } -obResource::~obResource() { +Resource::~Resource() { if (m_database != NULL) XrmDestroyDatabase(m_database); } -void obResource::setFile(const std::string &file) { +void Resource::setFile(const std::string &file) { m_file = file; } -void obResource::setAutoSave(bool autosave) { +void Resource::setAutoSave(bool autosave) { m_autosave = autosave; } -void obResource::save() { +void Resource::save() { ASSERT(m_database != NULL); XrmPutFileDatabase(m_database, m_file.c_str()); m_modified = false; } -bool obResource::load() { +bool Resource::load() { if (m_database != NULL) XrmDestroyDatabase(m_database); m_modified = false; @@ -85,7 +85,14 @@ bool obResource::load() { return true; } -void obResource::setValue(const std::string &rname, bool value) { +void Resource::create() { + if (m_database != NULL) + XrmDestroyDatabase(m_database); + m_modified = false; + ASSERT(NULL != (m_database = XrmGetStringDatabase(""))); +} + +void Resource::setValue(const std::string &rname, bool value) { ASSERT(m_database != NULL); const char *val = (value ? "True" : "False"); @@ -97,11 +104,11 @@ void obResource::setValue(const std::string &rname, bool value) { save(); } -void obResource::setValue(const std::string &rname, int value) { +void Resource::setValue(const std::string &rname, int value) { setValue(rname, (long)value); } -void obResource::setValue(const std::string &rname, long value) { +void Resource::setValue(const std::string &rname, long value) { ASSERT(m_database != NULL); char val[11]; @@ -114,8 +121,9 @@ void obResource::setValue(const std::string &rname, long value) { save(); } -void obResource::setValue(const std::string &rname, const char *value) { +void Resource::setValue(const std::string &rname, const char *value) { ASSERT(m_database != NULL); + ASSERT(value != NULL); std::string rc_string = rname + ": " + value; XrmPutLineResource(&m_database, rc_string.c_str()); @@ -125,7 +133,7 @@ void obResource::setValue(const std::string &rname, const char *value) { save(); } -void obResource::setValue(const std::string &rname, const std::string &value) { +void Resource::setValue(const std::string &rname, const std::string &value) { ASSERT(m_database != NULL); std::string rc_string = rname + ": " + value; @@ -136,7 +144,7 @@ void obResource::setValue(const std::string &rname, const std::string &value) { save(); } -bool obResource::getValue(const std::string &rname, const std::string &rclass, +bool Resource::getValue(const std::string &rname, const std::string &rclass, bool &value) const { ASSERT(rclass.c_str() != NULL); ASSERT(m_database != NULL); @@ -154,7 +162,7 @@ bool obResource::getValue(const std::string &rname, const std::string &rclass, return true; } -bool obResource::getValue(const std::string &rname, const std::string &rclass, +bool Resource::getValue(const std::string &rname, const std::string &rclass, long &value) const { ASSERT(m_database != NULL); @@ -170,7 +178,7 @@ bool obResource::getValue(const std::string &rname, const std::string &rclass, return true; } -bool obResource::getValue(const std::string &rname, const std::string &rclass, +bool Resource::getValue(const std::string &rname, const std::string &rclass, std::string &value) const { ASSERT(m_database != NULL);