comments and other minor stuff
This commit is contained in:
parent
cd7b6d1fd5
commit
a18a6b0994
2 changed files with 42 additions and 28 deletions
|
@ -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: "<<resource->getName()<<endl;
|
||||
cerr<<"Failed to read: "<<resource->name()<<endl;
|
||||
cerr<<"Setting default value"<<endl;
|
||||
resource->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,11 +97,12 @@ 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);
|
||||
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);
|
||||
|
|
|
@ -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,13 +31,18 @@
|
|||
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;
|
||||
inline const std::string& getAltName() const { return m_altname; }
|
||||
inline const std::string& getName() const { return m_name; }
|
||||
/// 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):
|
||||
|
@ -45,9 +50,10 @@ protected:
|
|||
{
|
||||
|
||||
}
|
||||
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; }
|
||||
|
@ -88,9 +94,15 @@ public:
|
|||
typedef std::list<Resource_base *> ResourceList;
|
||||
|
||||
ResourceManager() { }
|
||||
|
||||
bool load(const char *filename);
|
||||
bool save(const char *filename, const char *mergefilename=0);
|
||||
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 @@ public:
|
|||
void removeResource(Resource<T> &r) {
|
||||
m_resourcelist.remove(&r);
|
||||
}
|
||||
private:
|
||||
protected:
|
||||
static inline void ensureXrmIsInitialize();
|
||||
private:
|
||||
static bool m_init;
|
||||
ResourceList m_resourcelist;
|
||||
|
||||
|
|
Loading…
Reference in a new issue