all repos — fluxbox @ a18a6b0994292668db09b4c7af0c4e1199b308f8

custom fork of the fluxbox windowmanager

comments and other minor stuff
fluxgen fluxgen
commit

a18a6b0994292668db09b4c7af0c4e1199b308f8

parent

cd7b6d1fd5b1ac1614b1431126f266d8651c890c

2 files changed, 42 insertions(+), 28 deletions(-)

jump to
M src/Resource.ccsrc/Resource.cc

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// 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 @@ ResourceList::iterator i_end = m_resourcelist.end();

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: "<<resource->getName()<<endl; + cerr<<"Failed to read: "<<resource->name()<<endl; cerr<<"Setting default value"<<endl; resource->setDefaultValue(); }

@@ -87,7 +87,7 @@ ResourceList::iterator i_end = m_resourcelist.end();

//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 @@

//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;
M src/Resource.hhsrc/Resource.hh

@@ -19,7 +19,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// 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 ~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; } - 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; } - 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 @@ Resource_base(name, altname),

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 @@ {

public: typedef std::list<Resource_base *> 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 <class T> void addResource(Resource<T> &r) { m_resourcelist.push_back(&r);

@@ -100,8 +112,9 @@ template <class T>

void removeResource(Resource<T> &r) { m_resourcelist.remove(&r); } +protected: + static inline void ensureXrmIsInitialize(); private: - static inline void ensureXrmIsInitialize(); static bool m_init; ResourceList m_resourcelist;