diff options
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/Resource.cc | 29 | ||||
-rw-r--r-- | src/FbTk/Resource.hh | 36 |
2 files changed, 31 insertions, 34 deletions
diff --git a/src/FbTk/Resource.cc b/src/FbTk/Resource.cc index 4be85de..85e78da 100644 --- a/src/FbTk/Resource.cc +++ b/src/FbTk/Resource.cc | |||
@@ -226,4 +226,33 @@ void ResourceManager::unlock() { | |||
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
229 | // add the resource and load its value | ||
230 | void ResourceManager::addResource(Resource_base &r) { | ||
231 | m_resourcelist.push_back(&r); | ||
232 | m_resourcelist.unique(); | ||
233 | |||
234 | // lock ensures that the database is loaded. | ||
235 | lock(); | ||
236 | |||
237 | if (m_database == 0) { | ||
238 | unlock(); | ||
239 | return; | ||
240 | } | ||
241 | |||
242 | XrmValue value; | ||
243 | char *value_type; | ||
244 | |||
245 | // now, load the value for this resource | ||
246 | if (XrmGetResource(**m_database, r.name().c_str(), | ||
247 | r.altName().c_str(), &value_type, &value)) { | ||
248 | r.setFromString(value.addr); | ||
249 | } else { | ||
250 | std::cerr<<"Failed to read: "<<r.name()<<std::endl; | ||
251 | std::cerr<<"Setting default value"<<std::endl; | ||
252 | r.setDefaultValue(); | ||
253 | } | ||
254 | |||
255 | unlock(); | ||
256 | } | ||
257 | |||
229 | } // end namespace FbTk | 258 | } // end namespace FbTk |
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 8c9d645..55afe60 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh | |||
@@ -96,12 +96,10 @@ public: | |||
96 | 96 | ||
97 | 97 | ||
98 | /// Add resource to list, only used in Resource<T> | 98 | /// Add resource to list, only used in Resource<T> |
99 | template <class T> | 99 | void addResource(Resource_base &r); |
100 | void addResource(Resource<T> &r); | ||
101 | 100 | ||
102 | /// Remove a specific resource, only used in Resource<T> | 101 | /// Remove a specific resource, only used in Resource<T> |
103 | template <class T> | 102 | void removeResource(Resource_base &r) { |
104 | void removeResource(Resource<T> &r) { | ||
105 | m_resourcelist.remove(&r); | 103 | m_resourcelist.remove(&r); |
106 | } | 104 | } |
107 | 105 | ||
@@ -194,36 +192,6 @@ private: | |||
194 | }; | 192 | }; |
195 | 193 | ||
196 | 194 | ||
197 | // add the resource and load its value | ||
198 | template <class T> | ||
199 | void ResourceManager::addResource(Resource<T> &r) { | ||
200 | m_resourcelist.push_back(&r); | ||
201 | m_resourcelist.unique(); | ||
202 | |||
203 | // lock ensures that the database is loaded. | ||
204 | lock(); | ||
205 | |||
206 | if (m_database == 0) { | ||
207 | unlock(); | ||
208 | return; | ||
209 | } | ||
210 | |||
211 | XrmValue value; | ||
212 | char *value_type; | ||
213 | |||
214 | // now, load the value for this resource | ||
215 | if (XrmGetResource(**m_database, r.name().c_str(), | ||
216 | r.altName().c_str(), &value_type, &value)) { | ||
217 | r.setFromString(value.addr); | ||
218 | } else { | ||
219 | std::cerr<<"Failed to read: "<<r.name()<<std::endl; | ||
220 | std::cerr<<"Setting default value"<<std::endl; | ||
221 | r.setDefaultValue(); | ||
222 | } | ||
223 | |||
224 | unlock(); | ||
225 | } | ||
226 | |||
227 | 195 | ||
228 | template <typename ResourceType> | 196 | template <typename ResourceType> |
229 | Resource<ResourceType> &ResourceManager::getResource(const std::string &resname) { | 197 | Resource<ResourceType> &ResourceManager::getResource(const std::string &resname) { |