// DEALINGS IN THE SOFTWARE.
#include "Resource.h"
+#include "Util.h"
#ifdef HAVE_CONFIG_H
# include "../config.h"
# include <stdio.h>
#endif // HAVE_STDIO_H
-#include <assert.h>
+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() {
void obResource::setFile(const std::string &file) {
m_file = file;
- assert(m_file.c_str() != NULL);
}
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;
}
}
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;
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);
}
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());
}
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());
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;
&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;
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;
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;