aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-07-12 12:16:32 (GMT)
committerPavel Labath <pavelo@centrum.sk>2013-02-17 09:52:01 (GMT)
commitc9f19e88e187836aee4627d67dc7d26a1641d8ad (patch)
treeb8caa1ebd9d6353097f3542712b57dab4641223d
parent33ee29f5d4fcc59fc9991c7127674d9cf51ff4fc (diff)
downloadfluxbox_pavel-c9f19e88e187836aee4627d67dc7d26a1641d8ad.zip
fluxbox_pavel-c9f19e88e187836aee4627d67dc7d26a1641d8ad.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).
-rw-r--r--src/FbTk/ResTraits.hh18
-rw-r--r--src/FbTk/Resource.hh12
-rw-r--r--src/Screen.cc5
-rw-r--r--src/Screen.hh4
-rw-r--r--src/Window.cc9
5 files changed, 25 insertions, 23 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
163template<typename Traits, const char *delim> 163template<typename Traits>
164struct VectorTraits { 164struct 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
225private:
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 */
190template <typename T, typename Traits> 190template <typename T, typename Traits>
191class Resource:public Resource_base, public Accessor<T> { 191class Resource:public Resource_base, public Accessor<T>, private Traits {
192public: 192public:
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() {
diff --git a/src/Screen.cc b/src/Screen.cc
index 44b6771..cf7f438 100644
--- a/src/Screen.cc
+++ b/src/Screen.cc
@@ -260,11 +260,10 @@ const EnumTraits<FbWinFrame::TabPlacement>::Pair EnumTraits<FbWinFrame::TabPlace
260} // end namespace FbTk 260} // end namespace FbTk
261 261
262 262
263const char BScreen::ScreenResource::workspace_names_delim[] = ",";
264
265BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm, 263BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager_base &rm,
266 const string &scrname): 264 const string &scrname):
267 workspace_names(rm, std::vector<std::string>(), scrname + ".workspaceNames"), 265 workspace_names(rm, std::vector<std::string>(), scrname + ".workspaceNames",
266 FbTk::VectorTraits<FbTk::StringTraits>(",") ),
268 opaque_move(rm, true, scrname + ".opaqueMove"), 267 opaque_move(rm, true, scrname + ".opaqueMove"),
269 full_max(rm, false, scrname+".fullMaximization"), 268 full_max(rm, false, scrname+".fullMaximization"),
270 max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"), 269 max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"),
diff --git a/src/Screen.hh b/src/Screen.hh
index 3e062ac..db357d1 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -525,10 +525,8 @@ private:
525 struct ScreenResource { 525 struct ScreenResource {
526 ScreenResource(FbTk::ResourceManager_base &rm, const std::string &scrname); 526 ScreenResource(FbTk::ResourceManager_base &rm, const std::string &scrname);
527 527
528 static const char workspace_names_delim[];
529 FbTk::Resource< 528 FbTk::Resource<
530 std::vector<std::string>, 529 std::vector<std::string>, FbTk::VectorTraits<FbTk::StringTraits>
531 FbTk::VectorTraits<FbTk::StringTraits, workspace_names_delim>
532 > workspace_names; 530 > workspace_names;
533 531
534 FbTk::BoolResource opaque_move, full_max, 532 FbTk::BoolResource opaque_move, full_max,
diff --git a/src/Window.cc b/src/Window.cc
index bf46f0b..5103182 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -263,11 +263,8 @@ struct TestCornerHelper {
263 } 263 }
264}; 264};
265 265
266extern const char win_buttons_delim[] = " \t\n"; 266typedef FbTk::VectorTraits<FbTk::EnumTraits<WinButton::Type> > WinButtonsTraits;
267typedef FbTk::Resource< 267typedef FbTk::Resource<vector<WinButton::Type>, WinButtonsTraits> WinButtonsResource;
268 vector<WinButton::Type>,
269 FbTk::VectorTraits<FbTk::EnumTraits<WinButton::Type>, win_buttons_delim>
270> WinButtonsResource;
271 268
272} 269}
273 270
@@ -3457,7 +3454,7 @@ void FluxboxWindow::setupWindow() {
3457 titlebar_side[i] = 3454 titlebar_side[i] =
3458 new WinButtonsResource(rm, 3455 new WinButtonsResource(rm,
3459 WinButtonsResource::Type(begin, end), 3456 WinButtonsResource::Type(begin, end),
3460 titlebar_name[i]); 3457 titlebar_name[i], WinButtonsTraits(" \t\n"));
3461 3458
3462 3459
3463 screen().addManagedResource(titlebar_side[i]); 3460 screen().addManagedResource(titlebar_side[i]);