diff options
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/LResource.cc | 4 | ||||
-rw-r--r-- | src/FbTk/LResource.hh | 3 | ||||
-rw-r--r-- | src/FbTk/Resource.cc | 18 | ||||
-rw-r--r-- | src/FbTk/Resource.hh | 7 |
4 files changed, 19 insertions, 13 deletions
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc index 5842b65..78511eb 100644 --- a/src/FbTk/LResource.cc +++ b/src/FbTk/LResource.cc | |||
@@ -82,8 +82,8 @@ void LResourceManager::initState(lua::state &l) { | |||
82 | l.setfield(lua::REGISTRYINDEX, make_root); | 82 | l.setfield(lua::REGISTRYINDEX, make_root); |
83 | } | 83 | } |
84 | 84 | ||
85 | LResourceManager::LResourceManager(lua::state &l, const std::string &root) | 85 | LResourceManager::LResourceManager(const std::string &root, lua::state &l) |
86 | : m_l(&l), m_root(root) { | 86 | : ResourceManager_base(root), m_l(&l) { |
87 | l.checkstack(2); | 87 | l.checkstack(2); |
88 | lua::stack_sentry s(l); | 88 | lua::stack_sentry s(l); |
89 | 89 | ||
diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh index 0853687..185a029 100644 --- a/src/FbTk/LResource.hh +++ b/src/FbTk/LResource.hh | |||
@@ -39,7 +39,7 @@ class LResourceManager: public ResourceManager_base { | |||
39 | public: | 39 | public: |
40 | static void initState(lua::state &l); | 40 | static void initState(lua::state &l); |
41 | 41 | ||
42 | LResourceManager(lua::state &l, const std::string &root); | 42 | LResourceManager(const std::string &root, lua::state &l); |
43 | virtual bool save(const char *filename, const char *); | 43 | virtual bool save(const char *filename, const char *); |
44 | virtual void addResource(Resource_base &r); | 44 | virtual void addResource(Resource_base &r); |
45 | virtual void removeResource(Resource_base &r); | 45 | virtual void removeResource(Resource_base &r); |
@@ -47,7 +47,6 @@ public: | |||
47 | private: | 47 | private: |
48 | 48 | ||
49 | lua::state *m_l; | 49 | lua::state *m_l; |
50 | std::string m_root; | ||
51 | }; | 50 | }; |
52 | 51 | ||
53 | } // end namespace FbTk | 52 | } // end namespace FbTk |
diff --git a/src/FbTk/Resource.cc b/src/FbTk/Resource.cc index fb0f595..37555b3 100644 --- a/src/FbTk/Resource.cc +++ b/src/FbTk/Resource.cc | |||
@@ -82,10 +82,13 @@ void ResourceManager_base::setResourceValue(const string &resname, const string | |||
82 | 82 | ||
83 | } | 83 | } |
84 | 84 | ||
85 | ResourceManager::ResourceManager(const char *filename, bool lock_db) : | 85 | ResourceManager::ResourceManager(const std::string &root, const std::string &alt_root, |
86 | const char *filename, bool lock_db) : | ||
87 | ResourceManager_base(root), | ||
86 | m_db_lock(0), | 88 | m_db_lock(0), |
87 | m_database(0), | 89 | m_database(0), |
88 | m_filename(filename ? filename : "") | 90 | m_filename(filename ? filename : ""), |
91 | m_alt_root(alt_root) | ||
89 | { | 92 | { |
90 | static bool xrm_initialized = false; | 93 | static bool xrm_initialized = false; |
91 | if (!xrm_initialized) { | 94 | if (!xrm_initialized) { |
@@ -131,8 +134,8 @@ bool ResourceManager::load(const char *filename) { | |||
131 | for (; i != i_end; ++i) { | 134 | for (; i != i_end; ++i) { |
132 | 135 | ||
133 | Resource_base *resource = *i; | 136 | Resource_base *resource = *i; |
134 | if (XrmGetResource(**m_database, resource->name().c_str(), | 137 | if (XrmGetResource(**m_database, (m_root + '.' + resource->name()).c_str(), |
135 | resource->altName().c_str(), &value_type, &value)) | 138 | (m_alt_root + '.' + resource->altName()).c_str(), &value_type, &value)) |
136 | resource->setFromString(value.addr); | 139 | resource->setFromString(value.addr); |
137 | else { | 140 | else { |
138 | _FB_USES_NLS; | 141 | _FB_USES_NLS; |
@@ -166,13 +169,12 @@ bool ResourceManager::save(const char *filename, const char *mergefilename) { | |||
166 | // empty database | 169 | // empty database |
167 | XrmDatabaseHelper database; | 170 | XrmDatabaseHelper database; |
168 | 171 | ||
169 | string rc_string; | ||
170 | ResourceList::iterator i = m_resourcelist.begin(); | 172 | ResourceList::iterator i = m_resourcelist.begin(); |
171 | ResourceList::iterator i_end = m_resourcelist.end(); | 173 | ResourceList::iterator i_end = m_resourcelist.end(); |
172 | //write all resources to database | 174 | //write all resources to database |
173 | for (; i != i_end; ++i) { | 175 | for (; i != i_end; ++i) { |
174 | Resource_base *resource = *i; | 176 | Resource_base *resource = *i; |
175 | rc_string = resource->name() + string(": ") + resource->getString(); | 177 | const string &rc_string = m_root + '.' + resource->name() + ": " + resource->getString(); |
176 | XrmPutLineResource(&*database, rc_string.c_str()); | 178 | XrmPutLineResource(&*database, rc_string.c_str()); |
177 | } | 179 | } |
178 | 180 | ||
@@ -248,8 +250,8 @@ void ResourceManager::addResource(Resource_base &r) { | |||
248 | char *value_type; | 250 | char *value_type; |
249 | 251 | ||
250 | // now, load the value for this resource | 252 | // now, load the value for this resource |
251 | if (XrmGetResource(**m_database, r.name().c_str(), | 253 | if (XrmGetResource(**m_database, (m_root + '.' + r.name()).c_str(), |
252 | r.altName().c_str(), &value_type, &value)) { | 254 | (m_alt_root + '.' + r.altName()).c_str(), &value_type, &value)) { |
253 | r.setFromString(value.addr); | 255 | r.setFromString(value.addr); |
254 | } else { | 256 | } else { |
255 | std::cerr<<"Failed to read: "<<r.name()<<std::endl; | 257 | std::cerr<<"Failed to read: "<<r.name()<<std::endl; |
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 33a6bb2..744178b 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh | |||
@@ -87,6 +87,8 @@ class ResourceManager_base | |||
87 | public: | 87 | public: |
88 | typedef std::list<Resource_base *> ResourceList; | 88 | typedef std::list<Resource_base *> ResourceList; |
89 | 89 | ||
90 | ResourceManager_base(const std::string &root) : m_root(root) {} | ||
91 | |||
90 | virtual ~ResourceManager_base() {} | 92 | virtual ~ResourceManager_base() {} |
91 | 93 | ||
92 | /// Save all resouces registered to this class | 94 | /// Save all resouces registered to this class |
@@ -123,6 +125,7 @@ public: | |||
123 | 125 | ||
124 | protected: | 126 | protected: |
125 | ResourceList m_resourcelist; | 127 | ResourceList m_resourcelist; |
128 | const std::string m_root; | ||
126 | }; | 129 | }; |
127 | 130 | ||
128 | class ResourceManager: public ResourceManager_base | 131 | class ResourceManager: public ResourceManager_base |
@@ -130,7 +133,8 @@ class ResourceManager: public ResourceManager_base | |||
130 | public: | 133 | public: |
131 | // lock specifies if the database should be opened with one level locked | 134 | // lock specifies if the database should be opened with one level locked |
132 | // (useful for constructing inside initial set of constructors) | 135 | // (useful for constructing inside initial set of constructors) |
133 | ResourceManager(const char *filename, bool lock_db); | 136 | ResourceManager(const std::string &root, const std::string &alt_root, |
137 | const char *filename, bool lock_db); | ||
134 | virtual ~ResourceManager(); | 138 | virtual ~ResourceManager(); |
135 | 139 | ||
136 | /// Load all resources registered to this class | 140 | /// Load all resources registered to this class |
@@ -169,6 +173,7 @@ private: | |||
169 | XrmDatabaseHelper *m_database; | 173 | XrmDatabaseHelper *m_database; |
170 | 174 | ||
171 | std::string m_filename; | 175 | std::string m_filename; |
176 | std::string m_alt_root; | ||
172 | }; | 177 | }; |
173 | 178 | ||
174 | 179 | ||