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
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// 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 "Resource.hh"
|
||||||
#include "XrmDatabaseHelper.hh"
|
#include "XrmDatabaseHelper.hh"
|
||||||
|
@ -55,11 +55,11 @@ bool ResourceManager::load(const char *filename) {
|
||||||
for (; i != i_end; ++i) {
|
for (; i != i_end; ++i) {
|
||||||
|
|
||||||
Resource_base *resource = *i;
|
Resource_base *resource = *i;
|
||||||
if (XrmGetResource(*database, resource->getName().c_str(),
|
if (XrmGetResource(*database, resource->name().c_str(),
|
||||||
resource->getAltName().c_str(), &value_type, &value))
|
resource->altName().c_str(), &value_type, &value))
|
||||||
resource->setFromString(value.addr);
|
resource->setFromString(value.addr);
|
||||||
else {
|
else {
|
||||||
cerr<<"Faild to read: "<<resource->getName()<<endl;
|
cerr<<"Failed to read: "<<resource->name()<<endl;
|
||||||
cerr<<"Setting default value"<<endl;
|
cerr<<"Setting default value"<<endl;
|
||||||
resource->setDefaultValue();
|
resource->setDefaultValue();
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ bool ResourceManager::save(const char *filename, const char *mergefilename) {
|
||||||
//write all resources to database
|
//write all resources to database
|
||||||
for (; i != i_end; ++i) {
|
for (; i != i_end; ++i) {
|
||||||
Resource_base *resource = *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());
|
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
|
//check if we want to merge a database
|
||||||
if (mergefilename) {
|
if (mergefilename) {
|
||||||
XrmDatabaseHelper olddatabase(mergefilename);
|
XrmDatabaseHelper olddatabase(mergefilename);
|
||||||
if (olddatabase == 0)
|
if (olddatabase == 0) // did we load the file?
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
XrmMergeDatabases(*database, &*olddatabase);
|
XrmMergeDatabases(*database, &*olddatabase); // merge databases
|
||||||
XrmPutFileDatabase(*olddatabase, filename); //save database to file
|
XrmPutFileDatabase(*olddatabase, filename); // save database to file
|
||||||
*database=0; //don't try to destroy the database
|
|
||||||
} else //save database to file
|
*database = 0; // don't try to destroy the database
|
||||||
|
} else // save database to file
|
||||||
XrmPutFileDatabase(*database, filename);
|
XrmPutFileDatabase(*database, filename);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// 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
|
#ifndef RESOURCE_HH
|
||||||
#define RESOURCE_HH
|
#define RESOURCE_HH
|
||||||
|
@ -31,13 +31,18 @@
|
||||||
class Resource_base:private NotCopyable
|
class Resource_base:private NotCopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~Resource_base() { };
|
||||||
|
|
||||||
virtual void setFromString(char const *strval)=0;
|
/// set from string value
|
||||||
virtual void setDefaultValue()=0;
|
virtual void setFromString(char const *strval) = 0;
|
||||||
|
/// set default value
|
||||||
virtual std::string getString()=0;
|
virtual void setDefaultValue() = 0;
|
||||||
inline const std::string& getAltName() const { return m_altname; }
|
/// get string value
|
||||||
inline const std::string& getName() const { return m_name; }
|
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:
|
protected:
|
||||||
Resource_base(const std::string &name, const std::string &altname):
|
Resource_base(const std::string &name, const std::string &altname):
|
||||||
|
@ -45,9 +50,10 @@ protected:
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
virtual ~Resource_base(){ };
|
|
||||||
private:
|
private:
|
||||||
std::string m_name, m_altname;
|
std::string m_name; // name of this resource
|
||||||
|
std::string m_altname; // alternative name
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResourceManager;
|
class ResourceManager;
|
||||||
|
@ -62,10 +68,10 @@ public:
|
||||||
m_value(val), m_defaultval(val),
|
m_value(val), m_defaultval(val),
|
||||||
m_rm(rm)
|
m_rm(rm)
|
||||||
{
|
{
|
||||||
m_rm.addResource(*this);
|
m_rm.addResource(*this); // add this to resource handler
|
||||||
}
|
}
|
||||||
~Resource() {
|
virtual ~Resource() {
|
||||||
m_rm.removeResource(*this);
|
m_rm.removeResource(*this); // remove this from resource handler
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setDefaultValue() { m_value = m_defaultval; }
|
inline void setDefaultValue() { m_value = m_defaultval; }
|
||||||
|
@ -87,10 +93,16 @@ class ResourceManager
|
||||||
public:
|
public:
|
||||||
typedef std::list<Resource_base *> ResourceList;
|
typedef std::list<Resource_base *> ResourceList;
|
||||||
|
|
||||||
ResourceManager(){ }
|
ResourceManager() { }
|
||||||
|
virtual ~ResourceManager() {}
|
||||||
bool load(const char *filename);
|
/**
|
||||||
bool save(const char *filename, const char *mergefilename=0);
|
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>
|
template <class T>
|
||||||
void addResource(Resource<T> &r) {
|
void addResource(Resource<T> &r) {
|
||||||
m_resourcelist.push_back(&r);
|
m_resourcelist.push_back(&r);
|
||||||
|
@ -100,8 +112,9 @@ public:
|
||||||
void removeResource(Resource<T> &r) {
|
void removeResource(Resource<T> &r) {
|
||||||
m_resourcelist.remove(&r);
|
m_resourcelist.remove(&r);
|
||||||
}
|
}
|
||||||
private:
|
protected:
|
||||||
static inline void ensureXrmIsInitialize();
|
static inline void ensureXrmIsInitialize();
|
||||||
|
private:
|
||||||
static bool m_init;
|
static bool m_init;
|
||||||
ResourceList m_resourcelist;
|
ResourceList m_resourcelist;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue