From a18a6b0994292668db09b4c7af0c4e1199b308f8 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sat, 20 Jul 2002 09:51:26 +0000 Subject: comments and other minor stuff --- src/Resource.cc | 21 +++++++++++---------- src/Resource.hh | 49 +++++++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/Resource.cc b/src/Resource.cc index 8bd4e26..cb871f1 100644 --- a/src/Resource.cc +++ b/src/Resource.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Resource.cc,v 1.2 2002/02/04 06:47:34 fluxgen Exp $ +// $Id: Resource.cc,v 1.3 2002/07/20 09:51:26 fluxgen Exp $ #include "Resource.hh" #include "XrmDatabaseHelper.hh" @@ -55,11 +55,11 @@ bool ResourceManager::load(const char *filename) { for (; i != i_end; ++i) { Resource_base *resource = *i; - if (XrmGetResource(*database, resource->getName().c_str(), - resource->getAltName().c_str(), &value_type, &value)) + if (XrmGetResource(*database, resource->name().c_str(), + resource->altName().c_str(), &value_type, &value)) resource->setFromString(value.addr); else { - cerr<<"Faild to read: "<getName()<name()<setDefaultValue(); } @@ -87,7 +87,7 @@ bool ResourceManager::save(const char *filename, const char *mergefilename) { //write all resources to database for (; i != i_end; ++i) { Resource_base *resource = *i; - rc_string = resource->getName() + string(": ") + resource->getString(); + rc_string = resource->name() + string(": ") + resource->getString(); XrmPutLineResource(&*database, rc_string.c_str()); } @@ -97,13 +97,14 @@ bool ResourceManager::save(const char *filename, const char *mergefilename) { //check if we want to merge a database if (mergefilename) { XrmDatabaseHelper olddatabase(mergefilename); - if (olddatabase == 0) + if (olddatabase == 0) // did we load the file? return false; - XrmMergeDatabases(*database, &*olddatabase); - XrmPutFileDatabase(*olddatabase, filename); //save database to file - *database=0; //don't try to destroy the database - } else //save database to file + XrmMergeDatabases(*database, &*olddatabase); // merge databases + XrmPutFileDatabase(*olddatabase, filename); // save database to file + + *database = 0; // don't try to destroy the database + } else // save database to file XrmPutFileDatabase(*database, filename); return true; diff --git a/src/Resource.hh b/src/Resource.hh index 10a77f7..8055701 100644 --- a/src/Resource.hh +++ b/src/Resource.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Resource.hh,v 1.5 2002/05/17 10:59:58 fluxgen Exp $ +// $Id: Resource.hh,v 1.6 2002/07/20 09:51:03 fluxgen Exp $ #ifndef RESOURCE_HH #define RESOURCE_HH @@ -31,23 +31,29 @@ class Resource_base:private NotCopyable { public: - - virtual void setFromString(char const *strval)=0; - virtual void setDefaultValue()=0; - - virtual std::string getString()=0; - inline const std::string& getAltName() const { return m_altname; } - inline const std::string& getName() const { return m_name; } + virtual ~Resource_base() { }; + /// set from string value + virtual void setFromString(char const *strval) = 0; + /// set default value + virtual void setDefaultValue() = 0; + /// get string value + virtual std::string getString() = 0; + /// get alternative name of this resource + inline const std::string& altName() const { return m_altname; } + /// get name of this resource + inline const std::string& name() const { return m_name; } + protected: Resource_base(const std::string &name, const std::string &altname): m_name(name), m_altname(altname) { } - virtual ~Resource_base(){ }; + private: - std::string m_name, m_altname; + std::string m_name; // name of this resource + std::string m_altname; // alternative name }; class ResourceManager; @@ -62,10 +68,10 @@ public: m_value(val), m_defaultval(val), m_rm(rm) { - m_rm.addResource(*this); + m_rm.addResource(*this); // add this to resource handler } - ~Resource() { - m_rm.removeResource(*this); + virtual ~Resource() { + m_rm.removeResource(*this); // remove this from resource handler } inline void setDefaultValue() { m_value = m_defaultval; } @@ -87,10 +93,16 @@ class ResourceManager public: typedef std::list ResourceList; - ResourceManager(){ } - - bool load(const char *filename); - bool save(const char *filename, const char *mergefilename=0); + ResourceManager() { } + virtual ~ResourceManager() {} + /** + load all resouces registered to this class + */ + virtual bool load(const char *filename); + /** + save all resouces registered to this class + */ + virtual bool save(const char *filename, const char *mergefilename=0); template void addResource(Resource &r) { m_resourcelist.push_back(&r); @@ -100,8 +112,9 @@ public: void removeResource(Resource &r) { m_resourcelist.remove(&r); } -private: +protected: static inline void ensureXrmIsInitialize(); +private: static bool m_init; ResourceList m_resourcelist; -- cgit v0.11.2