From d03f47e861140e93e7edea61e6276bc22b406559 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 12 Jul 2011 14:16:32 +0200 Subject: 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). --- src/FbTk/ResTraits.hh | 18 ++++++++++++------ src/FbTk/Resource.hh | 12 +++++++----- src/Screen.cc | 5 ++--- src/Screen.hh | 4 +--- src/Window.cc | 9 +++------ 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 { } }; -template +template struct VectorTraits { typedef std::vector Type; - static std::string toString(const Type &x) { + + VectorTraits(const std::string &delim) : m_delim(delim) {} + + std::string toString(const Type &x) const { std::string retval; for(size_t i = 0; i < x.size(); ++i) { - retval.append(Traits::toString(x[i])); - retval.append(" "); + retval += Traits::toString(x[i]); + retval += m_delim[0]; } return retval; @@ -184,9 +187,9 @@ struct VectorTraits { } } - static Type fromString(const std::string &x) { + Type fromString(const std::string &x) const { std::vector val; - StringUtil::stringtok(val, x, delim); + StringUtil::stringtok(val, x, m_delim.c_str()); Type retval; for(size_t i = 0; i < val.size(); i++) { @@ -218,6 +221,9 @@ struct VectorTraits { throw ConversionError( std::string("Cannot convert to vector from lua type ") + l.type_name(l.type(-1)) ); } + +private: + std::string m_delim; }; } // 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: * If there is no traits class for your type, you have to implement one. */ template -class Resource:public Resource_base, public Accessor { +class Resource:public Resource_base, public Accessor, private Traits { public: typedef T Type; - Resource(ResourceManager_base &rm, T val, const std::string &name, const std::string &altname): - Resource_base(name, altname), m_value(val), m_defaultval(val), m_rm(rm) { + Resource(ResourceManager_base &rm, T val, const std::string &name, + const std::string &altname, const Traits &traits = Traits() ): + Resource_base(name, altname), Traits(traits), m_value(val), m_defaultval(val), m_rm(rm) { m_rm.addResource(*this); // add this to resource handler } // LResourceManager does not use altname, so we provide a constructor which initializes // altname to name - Resource(ResourceManager_base &rm, T val, const std::string &name): - Resource_base(name, name), m_value(val), m_defaultval(val), m_rm(rm) { + Resource(ResourceManager_base &rm, T val, const std::string &name, + const Traits &traits = Traits() ): + Resource_base(name, name), Traits(traits), m_value(val), m_defaultval(val), m_rm(rm) { m_rm.addResource(*this); // add this to resource handler } virtual ~Resource() { diff --git a/src/Screen.cc b/src/Screen.cc index cb86c73..e4eca07 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -242,11 +242,10 @@ const EnumTraits::Pair EnumTraits(), scrname + ".workspaceNames"), + workspace_names(rm, std::vector(), scrname + ".workspaceNames", + FbTk::VectorTraits(",") ), opaque_move(rm, true, scrname + ".opaqueMove"), full_max(rm, false, scrname+".fullMaximization"), max_ignore_inc(rm, true, scrname+".maxIgnoreIncrement"), diff --git a/src/Screen.hh b/src/Screen.hh index 6492104..1906d67 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -508,10 +508,8 @@ private: struct ScreenResource { ScreenResource(FbTk::ResourceManager_base &rm, const std::string &scrname); - static const char workspace_names_delim[]; FbTk::Resource< - std::vector, - FbTk::VectorTraits + std::vector, FbTk::VectorTraits > workspace_names; FbTk::BoolResource opaque_move, full_max, diff --git a/src/Window.cc b/src/Window.cc index 47118fa..95bf9b3 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -251,11 +251,8 @@ private: int m_mode; }; -extern const char win_buttons_delim[] = " \t\n"; -typedef FbTk::Resource< - vector, - FbTk::VectorTraits, win_buttons_delim> -> WinButtonsResource; +typedef FbTk::VectorTraits > WinButtonsTraits; +typedef FbTk::Resource, WinButtonsTraits> WinButtonsResource; } @@ -3477,7 +3474,7 @@ void FluxboxWindow::setupWindow() { titlebar_side[i] = new WinButtonsResource(rm, WinButtonsResource::Type(begin, end), - titlebar_name[i]); + titlebar_name[i], WinButtonsTraits(" \t\n")); screen().addManagedResource(titlebar_side[i]); -- cgit v0.11.2