]> Dogcows Code - chaz/openbox/blobdiff - src/Resource.cc
adding Geometry classes: Point, Size, and Rect
[chaz/openbox] / src / Resource.cc
index 5ff05657c28a7822991e0556ea82106e97e1a63a..1f6f84380528ff2ddbb2bdc6f6b0c1f839504e17 100644 (file)
 
 #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() {
@@ -62,14 +72,12 @@ void obResource::setAutoSave(bool autosave) {
 }
 
 void obResource::save() {
-  assert(m_file.c_str() != NULL);
   assert(m_database != NULL);
   XrmPutFileDatabase(m_database, m_file.c_str());
   m_modified = false;
 }
 
 bool obResource::load() {
-  assert(m_file.c_str() != NULL);
   if (m_database != NULL)
     XrmDestroyDatabase(m_database);
   m_modified = false;
@@ -79,7 +87,6 @@ bool obResource::load() {
 }
 
 void obResource::setValue(const std::string &rname, bool value) {
-  assert(rname.c_str() != NULL);
   assert(m_database != NULL);
 
   const char *val = (value ? "True" : "False");
@@ -91,8 +98,11 @@ 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(rname.c_str() != NULL);
   assert(m_database != NULL);
   
   char val[11];
@@ -106,7 +116,6 @@ void obResource::setValue(const std::string &rname, long value) {
 }
 
 void obResource::setValue(const std::string &rname, const char *value) {
-  assert(rname.c_str() != NULL);
   assert(m_database != NULL);
   
   std::string rc_string = rname + ": " + value;
@@ -118,7 +127,6 @@ void obResource::setValue(const std::string &rname, const char *value) {
 }
 
 void obResource::setValue(const std::string &rname, const std::string &value) {
-  assert(rname.c_str() != NULL);
   assert(m_database != NULL);
   
   std::string rc_string = rname + ": " + value;
@@ -131,7 +139,6 @@ 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);
   
@@ -141,7 +148,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;
@@ -150,8 +157,6 @@ 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);
   
   char *rettype;
@@ -168,8 +173,6 @@ 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);
   
   char *rettype;
This page took 0.022548 seconds and 4 git commands to generate.