diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-07-12 12:16:32 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-11-01 09:57:22 (GMT) |
commit | 592d306e702cac55245b8485db9a769f47584137 (patch) | |
tree | 866a2e17bbebfc0be17b4b829da124cd26e24776 /src/FbTk | |
parent | 24cdaecc1f32b29b29602c7b03d7a6202e3d87c2 (diff) | |
download | fluxbox_paul-592d306e702cac55245b8485db9a769f47584137.zip fluxbox_paul-592d306e702cac55245b8485db9a769f47584137.tar.bz2 |
Enable the resource traits classes to hold non-static members
ps: the Resource class inherits from the Traits class instead of holding it as a member because
it's more size-efficient (base classes can have zero size, members cannot).
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/ResTraits.hh | 18 | ||||
-rw-r--r-- | src/FbTk/Resource.hh | 12 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/FbTk/ResTraits.hh b/src/FbTk/ResTraits.hh index 3284801..19decb5 100644 --- a/src/FbTk/ResTraits.hh +++ b/src/FbTk/ResTraits.hh | |||
@@ -160,14 +160,17 @@ struct EnumTraits { | |||
160 | } | 160 | } |
161 | }; | 161 | }; |
162 | 162 | ||
163 | template<typename Traits, const char *delim> | 163 | template<typename Traits> |
164 | struct VectorTraits { | 164 | struct VectorTraits { |
165 | typedef std::vector<typename Traits::Type> Type; | 165 | typedef std::vector<typename Traits::Type> Type; |
166 | static std::string toString(const Type &x) { | 166 | |
167 | VectorTraits(const std::string &delim) : m_delim(delim) {} | ||
168 | |||
169 | std::string toString(const Type &x) const { | ||
167 | std::string retval; | 170 | std::string retval; |
168 | for(size_t i = 0; i < x.size(); ++i) { | 171 | for(size_t i = 0; i < x.size(); ++i) { |
169 | retval.append(Traits::toString(x[i])); | 172 | retval += Traits::toString(x[i]); |
170 | retval.append(" "); | 173 | retval += m_delim[0]; |
171 | } | 174 | } |
172 | 175 | ||
173 | return retval; | 176 | return retval; |
@@ -184,9 +187,9 @@ struct VectorTraits { | |||
184 | } | 187 | } |
185 | } | 188 | } |
186 | 189 | ||
187 | static Type fromString(const std::string &x) { | 190 | Type fromString(const std::string &x) const { |
188 | std::vector<std::string> val; | 191 | std::vector<std::string> val; |
189 | StringUtil::stringtok(val, x, delim); | 192 | StringUtil::stringtok(val, x, m_delim.c_str()); |
190 | Type retval; | 193 | Type retval; |
191 | 194 | ||
192 | for(size_t i = 0; i < val.size(); i++) { | 195 | for(size_t i = 0; i < val.size(); i++) { |
@@ -218,6 +221,9 @@ struct VectorTraits { | |||
218 | throw ConversionError( std::string("Cannot convert to vector from lua type ") | 221 | throw ConversionError( std::string("Cannot convert to vector from lua type ") |
219 | + l.type_name(l.type(-1)) ); | 222 | + l.type_name(l.type(-1)) ); |
220 | } | 223 | } |
224 | |||
225 | private: | ||
226 | std::string m_delim; | ||
221 | }; | 227 | }; |
222 | 228 | ||
223 | } // end namespace FbTk | 229 | } // end namespace FbTk |
diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 32d24b6..c6f12d6 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh | |||
@@ -188,19 +188,21 @@ private: | |||
188 | * If there is no traits class for your type, you have to implement one. | 188 | * If there is no traits class for your type, you have to implement one. |
189 | */ | 189 | */ |
190 | template <typename T, typename Traits> | 190 | template <typename T, typename Traits> |
191 | class Resource:public Resource_base, public Accessor<T> { | 191 | class Resource:public Resource_base, public Accessor<T>, private Traits { |
192 | public: | 192 | public: |
193 | typedef T Type; | 193 | typedef T Type; |
194 | 194 | ||
195 | Resource(ResourceManager_base &rm, T val, const std::string &name, const std::string &altname): | 195 | Resource(ResourceManager_base &rm, T val, const std::string &name, |
196 | Resource_base(name, altname), m_value(val), m_defaultval(val), m_rm(rm) { | 196 | const std::string &altname, const Traits &traits = Traits() ): |
197 | Resource_base(name, altname), Traits(traits), m_value(val), m_defaultval(val), m_rm(rm) { | ||
197 | m_rm.addResource(*this); // add this to resource handler | 198 | m_rm.addResource(*this); // add this to resource handler |
198 | } | 199 | } |
199 | 200 | ||
200 | // LResourceManager does not use altname, so we provide a constructor which initializes | 201 | // LResourceManager does not use altname, so we provide a constructor which initializes |
201 | // altname to name | 202 | // altname to name |
202 | Resource(ResourceManager_base &rm, T val, const std::string &name): | 203 | Resource(ResourceManager_base &rm, T val, const std::string &name, |
203 | Resource_base(name, name), m_value(val), m_defaultval(val), m_rm(rm) { | 204 | const Traits &traits = Traits() ): |
205 | Resource_base(name, name), Traits(traits), m_value(val), m_defaultval(val), m_rm(rm) { | ||
204 | m_rm.addResource(*this); // add this to resource handler | 206 | m_rm.addResource(*this); // add this to resource handler |
205 | } | 207 | } |
206 | virtual ~Resource() { | 208 | virtual ~Resource() { |