diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-11 11:00:45 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-16 23:49:23 (GMT) |
commit | eb0eef14134ee667c60f75f53de4e24950f3c117 (patch) | |
tree | 58b35842e1f84666373478bca3386be037a7a019 /src/IconbarTool.cc | |
parent | 3b7c1a3c220b7ccec0dee7804d36dabfe81449c4 (diff) | |
download | fluxbox_pavel-eb0eef14134ee667c60f75f53de4e24950f3c117.zip fluxbox_pavel-eb0eef14134ee667c60f75f53de4e24950f3c117.tar.bz2 |
Simplify FbTk::Resource template class
by outsourcing the conversion from string/lua to the specific type (and back) to a separate
class. This change touches a lot of files because the interface of FbTk::Resource changed
slightly. However, the changes are minor.
Diffstat (limited to 'src/IconbarTool.cc')
-rw-r--r-- | src/IconbarTool.cc | 45 |
1 files changed, 6 insertions, 39 deletions
diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 0f3aeb7..1452080 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc | |||
@@ -68,45 +68,12 @@ using std::endl; | |||
68 | namespace FbTk { | 68 | namespace FbTk { |
69 | 69 | ||
70 | template<> | 70 | template<> |
71 | void FbTk::Resource<FbTk::Container::Alignment>::setDefaultValue() { | 71 | const EnumTraits<Container::Alignment>::Pair EnumTraits<Container::Alignment>::s_map[] = { |
72 | m_value = FbTk::Container::RELATIVE; | 72 | { "Left", Container::LEFT }, |
73 | } | 73 | { "Right", Container::RIGHT }, |
74 | 74 | { "Relative", Container::RELATIVE }, | |
75 | template<> | 75 | { NULL, Container::RELATIVE } |
76 | string FbTk::Resource<FbTk::Container::Alignment>::getString() const { | 76 | }; |
77 | if (m_value == FbTk::Container::LEFT) | ||
78 | return string("Left"); | ||
79 | if (m_value == FbTk::Container::RIGHT) | ||
80 | return string("Right"); | ||
81 | return string("Relative"); | ||
82 | } | ||
83 | |||
84 | template<> | ||
85 | void FbTk::Resource<FbTk::Container::Alignment>::setFromString(const char *str) { | ||
86 | if (strcasecmp(str, "Left") == 0) | ||
87 | m_value = FbTk::Container::LEFT; | ||
88 | else if (strcasecmp(str, "Right") == 0) | ||
89 | m_value = FbTk::Container::RIGHT; | ||
90 | else if (strcasecmp(str, "Relative") == 0) | ||
91 | m_value = FbTk::Container::RELATIVE; | ||
92 | else | ||
93 | setDefaultValue(); | ||
94 | } | ||
95 | |||
96 | template<> | ||
97 | void FbTk::Resource<FbTk::Container::Alignment>::setFromLua(lua::state &l) { | ||
98 | lua::stack_sentry s(l, -1); | ||
99 | if(l.isstring(-1)) | ||
100 | setFromString(l.tostring(-1).c_str()); | ||
101 | else | ||
102 | setDefaultValue(); | ||
103 | l.pop(); | ||
104 | } | ||
105 | |||
106 | template<> | ||
107 | void FbTk::Resource<FbTk::Container::Alignment>::pushToLua(lua::state &l) const { | ||
108 | l.pushstring(getString()); | ||
109 | } | ||
110 | 77 | ||
111 | } // end namespace FbTk | 78 | } // end namespace FbTk |
112 | 79 | ||