aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/LResource.cc29
-rw-r--r--src/FbTk/LResource.hh4
-rw-r--r--src/FbTk/Resource.cc56
-rw-r--r--src/FbTk/Resource.hh32
4 files changed, 41 insertions, 80 deletions
diff --git a/src/FbTk/LResource.cc b/src/FbTk/LResource.cc
index fd8ef2f..5842b65 100644
--- a/src/FbTk/LResource.cc
+++ b/src/FbTk/LResource.cc
@@ -108,8 +108,7 @@ void LResourceManager::addResource(Resource_base &r) {
108 m_l->checkstack(5); 108 m_l->checkstack(5);
109 lua::stack_sentry s(*m_l); 109 lua::stack_sentry s(*m_l);
110 110
111 m_resourcelist.push_back(&r); 111 ResourceManager_base::addResource(r);
112 m_resourcelist.unique();
113 112
114 m_l->getfield(lua::REGISTRYINDEX, register_resource); 113 m_l->getfield(lua::REGISTRYINDEX, register_resource);
115 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str()); 114 m_l->getfield(lua::GLOBALSINDEX, m_root.c_str());
@@ -133,31 +132,7 @@ void LResourceManager::removeResource(Resource_base &r) {
133 *static_cast<Resource_base **>(m_l->touserdata(-1)) = NULL; 132 *static_cast<Resource_base **>(m_l->touserdata(-1)) = NULL;
134 m_l->pop(); 133 m_l->pop();
135 134
136 m_resourcelist.remove(&r); 135 ResourceManager_base::removeResource(r);
137}
138
139Resource_base *LResourceManager::findResource(const std::string &resname) {
140 // find resource name
141 ResourceList::const_iterator i = m_resourcelist.begin();
142 ResourceList::const_iterator i_end = m_resourcelist.end();
143 for (; i != i_end; ++i) {
144 if ((*i)->name() == resname ||
145 (*i)->altName() == resname)
146 return *i;
147 }
148 return 0;
149}
150
151const Resource_base *LResourceManager::findResource(const std::string &resname) const {
152 // find resource name
153 ResourceList::const_iterator i = m_resourcelist.begin();
154 ResourceList::const_iterator i_end = m_resourcelist.end();
155 for (; i != i_end; ++i) {
156 if ((*i)->name() == resname ||
157 (*i)->altName() == resname)
158 return *i;
159 }
160 return 0;
161} 136}
162 137
163} // end namespace FbTk 138} // end namespace FbTk
diff --git a/src/FbTk/LResource.hh b/src/FbTk/LResource.hh
index 897575b..0853687 100644
--- a/src/FbTk/LResource.hh
+++ b/src/FbTk/LResource.hh
@@ -43,13 +43,9 @@ public:
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);
46 Resource_base *findResource(const std::string &resname);
47 const Resource_base *findResource(const std::string &resname) const;
48 46
49private: 47private:
50 typedef std::list<Resource_base *> ResourceList;
51 48
52 ResourceList m_resourcelist;
53 lua::state *m_l; 49 lua::state *m_l;
54 std::string m_root; 50 std::string m_root;
55}; 51};
diff --git a/src/FbTk/Resource.cc b/src/FbTk/Resource.cc
index fad4bf3..fb0f595 100644
--- a/src/FbTk/Resource.cc
+++ b/src/FbTk/Resource.cc
@@ -37,7 +37,34 @@ using std::string;
37 37
38namespace FbTk { 38namespace FbTk {
39 39
40ResourceManager_base::~ResourceManager_base() { 40
41void ResourceManager_base::addResource(Resource_base &r) {
42 m_resourcelist.push_back(&r);
43 m_resourcelist.unique();
44}
45
46Resource_base *ResourceManager_base::findResource(const string &resname) {
47 // find resource name
48 ResourceList::iterator i = m_resourcelist.begin();
49 ResourceList::iterator i_end = m_resourcelist.end();
50 for (; i != i_end; ++i) {
51 if ((*i)->name() == resname ||
52 (*i)->altName() == resname)
53 return *i;
54 }
55 return 0;
56}
57
58const Resource_base *ResourceManager_base::findResource(const string &resname) const {
59 // find resource name
60 ResourceList::const_iterator i = m_resourcelist.begin();
61 ResourceList::const_iterator i_end = m_resourcelist.end();
62 for (; i != i_end; ++i) {
63 if ((*i)->name() == resname ||
64 (*i)->altName() == resname)
65 return *i;
66 }
67 return 0;
41} 68}
42 69
43string ResourceManager_base::resourceValue(const string &resname) const { 70string ResourceManager_base::resourceValue(const string &resname) const {
@@ -180,30 +207,6 @@ bool ResourceManager::save(const char *filename, const char *mergefilename) {
180 return true; 207 return true;
181} 208}
182 209
183Resource_base *ResourceManager::findResource(const string &resname) {
184 // find resource name
185 ResourceList::iterator i = m_resourcelist.begin();
186 ResourceList::iterator i_end = m_resourcelist.end();
187 for (; i != i_end; ++i) {
188 if ((*i)->name() == resname ||
189 (*i)->altName() == resname)
190 return *i;
191 }
192 return 0;
193}
194
195const Resource_base *ResourceManager::findResource(const string &resname) const {
196 // find resource name
197 ResourceList::const_iterator i = m_resourcelist.begin();
198 ResourceList::const_iterator i_end = m_resourcelist.end();
199 for (; i != i_end; ++i) {
200 if ((*i)->name() == resname ||
201 (*i)->altName() == resname)
202 return *i;
203 }
204 return 0;
205}
206
207ResourceManager &ResourceManager::lock() { 210ResourceManager &ResourceManager::lock() {
208 ++m_db_lock; 211 ++m_db_lock;
209 // if the lock was zero, then load the database 212 // if the lock was zero, then load the database
@@ -231,8 +234,7 @@ void ResourceManager::unlock() {
231 234
232// add the resource and load its value 235// add the resource and load its value
233void ResourceManager::addResource(Resource_base &r) { 236void ResourceManager::addResource(Resource_base &r) {
234 m_resourcelist.push_back(&r); 237 ResourceManager_base::addResource(r);
235 m_resourcelist.unique();
236 238
237 // lock ensures that the database is loaded. 239 // lock ensures that the database is loaded.
238 lock(); 240 lock();
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh
index fb05426..33a6bb2 100644
--- a/src/FbTk/Resource.hh
+++ b/src/FbTk/Resource.hh
@@ -87,7 +87,7 @@ class ResourceManager_base
87public: 87public:
88 typedef std::list<Resource_base *> ResourceList; 88 typedef std::list<Resource_base *> ResourceList;
89 89
90 virtual ~ResourceManager_base(); 90 virtual ~ResourceManager_base() {}
91 91
92 /// Save all resouces registered to this class 92 /// Save all resouces registered to this class
93 /// @return true on success 93 /// @return true on success
@@ -96,17 +96,19 @@ 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 virtual void addResource(Resource_base &r) = 0; 99 virtual void addResource(Resource_base &r);
100 100
101 /// Remove a specific resource, only used in Resource<T> 101 /// Remove a specific resource, only used in Resource<T>
102 virtual void removeResource(Resource_base &r) = 0; 102 virtual void removeResource(Resource_base &r) {
103 m_resourcelist.remove(&r);
104 }
103 105
104 /// searches for the resource with the resourcename 106 /// searches for the resource with the resourcename
105 /// @return pointer to resource base on success, else 0. 107 /// @return pointer to resource base on success, else 0.
106 virtual Resource_base *findResource(const std::string &resourcename) = 0; 108 Resource_base *findResource(const std::string &resourcename);
107 /// searches for the resource with the resourcename 109 /// searches for the resource with the resourcename
108 /// @return pointer to resource base on success, else 0. 110 /// @return pointer to resource base on success, else 0.
109 virtual const Resource_base *findResource(const std::string &resourcename) const = 0; 111 const Resource_base *findResource(const std::string &resourcename) const;
110 112
111 std::string resourceValue(const std::string &resourcename) const; 113 std::string resourceValue(const std::string &resourcename) const;
112 void setResourceValue(const std::string &resourcename, const std::string &value); 114 void setResourceValue(const std::string &resourcename, const std::string &value);
@@ -118,13 +120,14 @@ public:
118 */ 120 */
119 template <typename ResourceType, typename Traits> 121 template <typename ResourceType, typename Traits>
120 Resource<ResourceType, Traits> &getResource(const std::string &resource); 122 Resource<ResourceType, Traits> &getResource(const std::string &resource);
123
124protected:
125 ResourceList m_resourcelist;
121}; 126};
122 127
123class ResourceManager: public ResourceManager_base 128class ResourceManager: public ResourceManager_base
124{ 129{
125public: 130public:
126 typedef std::list<Resource_base *> ResourceList;
127
128 // lock specifies if the database should be opened with one level locked 131 // lock specifies if the database should be opened with one level locked
129 // (useful for constructing inside initial set of constructors) 132 // (useful for constructing inside initial set of constructors)
130 ResourceManager(const char *filename, bool lock_db); 133 ResourceManager(const char *filename, bool lock_db);
@@ -139,22 +142,9 @@ public:
139 virtual bool save(const char *filename, const char *mergefilename=0); 142 virtual bool save(const char *filename, const char *mergefilename=0);
140 143
141 144
142
143 /// Add resource to list, only used in Resource<T> 145 /// Add resource to list, only used in Resource<T>
144 virtual void addResource(Resource_base &r); 146 virtual void addResource(Resource_base &r);
145 147
146 /// Remove a specific resource, only used in Resource<T>
147 virtual void removeResource(Resource_base &r) {
148 m_resourcelist.remove(&r);
149 }
150
151 /// searches for the resource with the resourcename
152 /// @return pointer to resource base on success, else 0.
153 virtual Resource_base *findResource(const std::string &resourcename);
154 /// searches for the resource with the resourcename
155 /// @return pointer to resource base on success, else 0.
156 virtual const Resource_base *findResource(const std::string &resourcename) const;
157
158 // this marks the database as "in use" and will avoid reloading 148 // this marks the database as "in use" and will avoid reloading
159 // resources unless it is zero. 149 // resources unless it is zero.
160 // It returns this resource manager. Useful for passing to 150 // It returns this resource manager. Useful for passing to
@@ -176,8 +166,6 @@ protected:
176 166
177private: 167private:
178 168
179 ResourceList m_resourcelist;
180
181 XrmDatabaseHelper *m_database; 169 XrmDatabaseHelper *m_database;
182 170
183 std::string m_filename; 171 std::string m_filename;