aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Resource.hh
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-08-15 12:07:53 (GMT)
committerPavel Labath <pavelo@centrum.sk>2013-02-18 21:04:26 (GMT)
commita897844ea1cfa6303112fd3f0d472d3e135bdc6d (patch)
treec65582488fa42930d7e44c0f585e6eba4f1f3650 /src/FbTk/Resource.hh
parenta5792b747d5c0318f66360092dafbd4852e2c68c (diff)
downloadfluxbox_pavel-a897844ea1cfa6303112fd3f0d472d3e135bdc6d.zip
fluxbox_pavel-a897844ea1cfa6303112fd3f0d472d3e135bdc6d.tar.bz2
More preparation for automatic updating of config files
Diffstat (limited to 'src/FbTk/Resource.hh')
-rw-r--r--src/FbTk/Resource.hh41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh
index 700fe70..b729ad4 100644
--- a/src/FbTk/Resource.hh
+++ b/src/FbTk/Resource.hh
@@ -47,12 +47,19 @@ private:
47 std::string m_str; 47 std::string m_str;
48}; 48};
49 49
50// forward declarations
51template <typename T, typename Traits>
52class Resource;
53class ResourceManager_base;
54
50/// Base class for resources, this is only used in ResourceManager 55/// Base class for resources, this is only used in ResourceManager
51class Resource_base:private FbTk::NotCopyable 56class Resource_base:private FbTk::NotCopyable
52{ 57{
53public: 58public:
54 virtual ~Resource_base() { }; 59 virtual ~Resource_base() { };
55 60
61 virtual void setResourceManager(ResourceManager_base &rm) = 0;
62
56 /// set from string value 63 /// set from string value
57 virtual void setFromString(char const *strval) = 0; 64 virtual void setFromString(char const *strval) = 0;
58 /// set default value 65 /// set default value
@@ -80,9 +87,6 @@ private:
80 std::string m_altname; ///< alternative name 87 std::string m_altname; ///< alternative name
81}; 88};
82 89
83template <typename T, typename Traits>
84class Resource;
85
86class ResourceManager_base 90class ResourceManager_base
87{ 91{
88public: 92public:
@@ -134,10 +138,10 @@ public:
134 ResourceList::const_iterator begin() { return m_resourcelist.begin(); } 138 ResourceList::const_iterator begin() { return m_resourcelist.begin(); }
135 ResourceList::const_iterator end() { return m_resourcelist.end(); } 139 ResourceList::const_iterator end() { return m_resourcelist.end(); }
136 140
137protected:
138 /// does the actual loading 141 /// does the actual loading
139 virtual void doLoad(const std::string &filename) = 0; 142 virtual void doLoad(const std::string &filename) = 0;
140 143
144protected:
141 ResourceList m_resourcelist; 145 ResourceList m_resourcelist;
142 const std::string m_root; 146 const std::string m_root;
143 std::string m_filename; 147 std::string m_filename;
@@ -177,9 +181,10 @@ public:
177 std::cerr<<(*it)->name()<<std::endl; 181 std::cerr<<(*it)->name()<<std::endl;
178 } 182 }
179 } 183 }
180protected: 184
181 virtual void doLoad(const std::string &filename); 185 virtual void doLoad(const std::string &filename);
182 186
187protected:
183 int m_db_lock; 188 int m_db_lock;
184 189
185private: 190private:
@@ -202,31 +207,37 @@ public:
202 207
203 Resource(ResourceManager_base &rm, T val, const std::string &name, 208 Resource(ResourceManager_base &rm, T val, const std::string &name,
204 const std::string &altname, const Traits &traits = Traits() ): 209 const std::string &altname, const Traits &traits = Traits() ):
205 Resource_base(name, altname), Traits(traits), m_value(val), m_defaultval(val), m_rm(rm) { 210 Resource_base(name, altname), Traits(traits), m_value(val), m_defaultval(val), m_rm(&rm) {
206 m_rm.addResource(*this); // add this to resource handler 211 m_rm->addResource(*this); // add this to resource handler
207 } 212 }
208 213
209 // LResourceManager does not use altname, so we provide a constructor which initializes 214 // LResourceManager does not use altname, so we provide a constructor which initializes
210 // altname to name 215 // altname to name
211 Resource(ResourceManager_base &rm, T val, const std::string &name, 216 Resource(ResourceManager_base &rm, T val, const std::string &name,
212 const Traits &traits = Traits() ): 217 const Traits &traits = Traits() ):
213 Resource_base(name, name), Traits(traits), m_value(val), m_defaultval(val), m_rm(rm) { 218 Resource_base(name, name), Traits(traits), m_value(val), m_defaultval(val), m_rm(&rm) {
214 m_rm.addResource(*this); // add this to resource handler 219 m_rm->addResource(*this); // add this to resource handler
215 } 220 }
216 virtual ~Resource() { 221 virtual ~Resource() {
217 m_rm.removeResource(*this); // remove this from resource handler 222 m_rm->removeResource(*this); // remove this from resource handler
223 }
224
225 virtual void setResourceManager(ResourceManager_base &rm) {
226 m_rm->removeResource(*this);
227 m_rm = &rm;
228 m_rm->addResource(*this);
218 } 229 }
219 230
220 void setDefaultValue() { 231 void setDefaultValue() {
221 m_value = m_defaultval; 232 m_value = m_defaultval;
222 m_rm.resourceChanged(*this); 233 m_rm->resourceChanged(*this);
223 m_modified_sig.emit(m_value); 234 m_modified_sig.emit(m_value);
224 } 235 }
225 /// sets resource from string, specialized, must be implemented 236 /// sets resource from string, specialized, must be implemented
226 void setFromString(const char *strval) { 237 void setFromString(const char *strval) {
227 try { 238 try {
228 m_value = Traits::fromString(strval); 239 m_value = Traits::fromString(strval);
229 m_rm.resourceChanged(*this); 240 m_rm->resourceChanged(*this);
230 m_modified_sig.emit(m_value); 241 m_modified_sig.emit(m_value);
231 } 242 }
232 catch(ConversionError &e) { 243 catch(ConversionError &e) {
@@ -236,7 +247,7 @@ public:
236 } 247 }
237 Accessor<T> &operator =(const T& newvalue) { 248 Accessor<T> &operator =(const T& newvalue) {
238 m_value = newvalue; 249 m_value = newvalue;
239 m_rm.resourceChanged(*this); 250 m_rm->resourceChanged(*this);
240 m_modified_sig.emit(m_value); 251 m_modified_sig.emit(m_value);
241 return *this; 252 return *this;
242 } 253 }
@@ -247,7 +258,7 @@ public:
247 virtual void setFromLua(lua::state &l) { 258 virtual void setFromLua(lua::state &l) {
248 try { 259 try {
249 m_value = Traits::fromLua(l); 260 m_value = Traits::fromLua(l);
250 m_rm.resourceChanged(*this); 261 m_rm->resourceChanged(*this);
251 m_modified_sig.emit(m_value); 262 m_modified_sig.emit(m_value);
252 } 263 }
253 catch(ConversionError &e) { 264 catch(ConversionError &e) {
@@ -268,7 +279,7 @@ public:
268 279
269private: 280private:
270 T m_value, m_defaultval; 281 T m_value, m_defaultval;
271 ResourceManager_base &m_rm; 282 ResourceManager_base *m_rm;
272 Signal<const T &> m_modified_sig; 283 Signal<const T &> m_modified_sig;
273}; 284};
274 285