aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/LogicCommands.cc
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2008-01-11 07:41:22 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2008-01-11 07:41:22 (GMT)
commit9f2f65a698c4cc71373a7fe9d73a0889e0d3487b (patch)
tree4ad67db771d73ea3c48f80a1244037fc9754edd2 /src/FbTk/LogicCommands.cc
parent1f01d84c080d607a91eb417efcaf5e500b5f1d7e (diff)
downloadfluxbox_pavel-9f2f65a698c4cc71373a7fe9d73a0889e0d3487b.zip
fluxbox_pavel-9f2f65a698c4cc71373a7fe9d73a0889e0d3487b.tar.bz2
make FbTk::Command a template class, split parsing information out of ObjectRegistry
Diffstat (limited to 'src/FbTk/LogicCommands.cc')
-rw-r--r--src/FbTk/LogicCommands.cc56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/FbTk/LogicCommands.cc b/src/FbTk/LogicCommands.cc
index fedffe9..3545b61 100644
--- a/src/FbTk/LogicCommands.cc
+++ b/src/FbTk/LogicCommands.cc
@@ -21,7 +21,7 @@
21 21
22#include "LogicCommands.hh" 22#include "LogicCommands.hh"
23 23
24#include "ObjectRegistry.hh" 24#include "CommandParser.hh"
25#include "StringUtil.hh" 25#include "StringUtil.hh"
26 26
27#include <vector> 27#include <vector>
@@ -39,11 +39,11 @@ M *addCommands(M *macro, const string &args, bool trusted) {
39 std::string blah; 39 std::string blah;
40 std::vector<std::string> cmds; 40 std::vector<std::string> cmds;
41 StringUtil::stringTokensBetween(cmds, args, blah, '{', '}'); 41 StringUtil::stringTokensBetween(cmds, args, blah, '{', '}');
42 RefCount<BoolCommand> cmd(0); 42 RefCount<Command<bool> > cmd(0);
43 43
44 std::vector<std::string>::iterator it = cmds.begin(), it_end = cmds.end(); 44 std::vector<std::string>::iterator it = cmds.begin(), it_end = cmds.end();
45 for (; it != it_end; ++it) { 45 for (; it != it_end; ++it) {
46 cmd = ObjectRegistry<BoolCommand>::instance().parse(*it, trusted); 46 cmd = CommandParser<bool>::instance().parse(*it, trusted);
47 if (*cmd) 47 if (*cmd)
48 macro->add(cmd); 48 macro->add(cmd);
49 } 49 }
@@ -54,14 +54,14 @@ M *addCommands(M *macro, const string &args, bool trusted) {
54 return 0; 54 return 0;
55} 55}
56 56
57BoolCommand *parseLogicCommand(const string &command, const string &args, 57Command<bool> *parseLogicCommand(const string &command, const string &args,
58 bool trusted) { 58 bool trusted) {
59 if (command == "not") { 59 if (command == "not") {
60 BoolCommand *boolcmd = 60 Command<bool> *boolcmd =
61 ObjectRegistry<BoolCommand>::instance().parse(args, trusted); 61 CommandParser<bool>::instance().parse(args, trusted);
62 if (!boolcmd) 62 if (!boolcmd)
63 return 0; 63 return 0;
64 RefCount<BoolCommand> ref(boolcmd); 64 RefCount<Command<bool> > ref(boolcmd);
65 return new NotCommand(ref); 65 return new NotCommand(ref);
66 } else if (command == "and") 66 } else if (command == "and")
67 return addCommands<AndCommand>(new AndCommand(), args, trusted); 67 return addCommands<AndCommand>(new AndCommand(), args, trusted);
@@ -72,41 +72,41 @@ BoolCommand *parseLogicCommand(const string &command, const string &args,
72 return 0; 72 return 0;
73} 73}
74 74
75REGISTER_OBJECT_PARSER(not, parseLogicCommand, BoolCommand); 75REGISTER_COMMAND_PARSER(not, parseLogicCommand, bool);
76REGISTER_OBJECT_PARSER(and, parseLogicCommand, BoolCommand); 76REGISTER_COMMAND_PARSER(and, parseLogicCommand, bool);
77REGISTER_OBJECT_PARSER(or, parseLogicCommand, BoolCommand); 77REGISTER_COMMAND_PARSER(or, parseLogicCommand, bool);
78REGISTER_OBJECT_PARSER(xor, parseLogicCommand, BoolCommand); 78REGISTER_COMMAND_PARSER(xor, parseLogicCommand, bool);
79 79
80}; // end anonymous namespace 80}; // end anonymous namespace
81 81
82Command *IfCommand::parse(const std::string &command, const std::string &args, 82Command<void> *IfCommand::parse(const std::string &command, const std::string &args,
83 bool trusted) { 83 bool trusted) {
84 std::string blah; 84 std::string blah;
85 std::vector<std::string> cmds; 85 std::vector<std::string> cmds;
86 RefCount<BoolCommand> cond(0); 86 RefCount<Command<bool> > cond(0);
87 RefCount<Command> t(0), f(0); 87 RefCount<Command<void> > t(0), f(0);
88 88
89 StringUtil::stringTokensBetween(cmds, args, blah, '{', '}'); 89 StringUtil::stringTokensBetween(cmds, args, blah, '{', '}');
90 if (cmds.size() < 3) 90 if (cmds.size() < 3)
91 return 0; 91 return 0;
92 92
93 cond = ObjectRegistry<BoolCommand>::instance().parse(cmds[0], trusted); 93 cond = CommandParser<bool>::instance().parse(cmds[0], trusted);
94 if (*cond == 0) 94 if (*cond == 0)
95 return 0; 95 return 0;
96 96
97 t = ObjectRegistry<Command>::instance().parse(cmds[1], trusted); 97 t = CommandParser<void>::instance().parse(cmds[1], trusted);
98 if (cmds.size() >= 3) 98 if (cmds.size() >= 3)
99 f = ObjectRegistry<Command>::instance().parse(cmds[2], trusted); 99 f = CommandParser<void>::instance().parse(cmds[2], trusted);
100 if (*t == 0 && *f == 0) 100 if (*t == 0 && *f == 0)
101 return 0; 101 return 0;
102 102
103 return new IfCommand(cond, t, f); 103 return new IfCommand(cond, t, f);
104} 104}
105 105
106REGISTER_OBJECT_PARSER(if, IfCommand::parse, Command); 106REGISTER_COMMAND_PARSER(if, IfCommand::parse, void);
107REGISTER_OBJECT_PARSER(cond, IfCommand::parse, Command); 107REGISTER_COMMAND_PARSER(cond, IfCommand::parse, void);
108 108
109void OrCommand::add(RefCount<BoolCommand> &com) { 109void OrCommand::add(RefCount<Command<bool> > &com) {
110 m_commandlist.push_back(com); 110 m_commandlist.push_back(com);
111} 111}
112 112
@@ -114,15 +114,15 @@ size_t OrCommand::size() const {
114 return m_commandlist.size(); 114 return m_commandlist.size();
115} 115}
116 116
117bool OrCommand::bool_execute() { 117bool OrCommand::execute() {
118 for (size_t i=0; i < m_commandlist.size(); ++i) { 118 for (size_t i=0; i < m_commandlist.size(); ++i) {
119 if (m_commandlist[i]->bool_execute()) 119 if (m_commandlist[i]->execute())
120 return true; 120 return true;
121 } 121 }
122 return false; 122 return false;
123} 123}
124 124
125void AndCommand::add(RefCount<BoolCommand> &com) { 125void AndCommand::add(RefCount<Command<bool> > &com) {
126 m_commandlist.push_back(com); 126 m_commandlist.push_back(com);
127} 127}
128 128
@@ -130,15 +130,15 @@ size_t AndCommand::size() const {
130 return m_commandlist.size(); 130 return m_commandlist.size();
131} 131}
132 132
133bool AndCommand::bool_execute() { 133bool AndCommand::execute() {
134 for (size_t i=0; i < m_commandlist.size(); ++i) { 134 for (size_t i=0; i < m_commandlist.size(); ++i) {
135 if (!m_commandlist[i]->bool_execute()) 135 if (!m_commandlist[i]->execute())
136 return false; 136 return false;
137 } 137 }
138 return true; 138 return true;
139} 139}
140 140
141void XorCommand::add(RefCount<BoolCommand> &com) { 141void XorCommand::add(RefCount<Command<bool> > &com) {
142 m_commandlist.push_back(com); 142 m_commandlist.push_back(com);
143} 143}
144 144
@@ -146,10 +146,10 @@ size_t XorCommand::size() const {
146 return m_commandlist.size(); 146 return m_commandlist.size();
147} 147}
148 148
149bool XorCommand::bool_execute() { 149bool XorCommand::execute() {
150 bool ret = false; 150 bool ret = false;
151 for (size_t i=0; i < m_commandlist.size(); ++i) 151 for (size_t i=0; i < m_commandlist.size(); ++i)
152 ret ^= m_commandlist[i]->bool_execute(); 152 ret ^= m_commandlist[i]->execute();
153 return ret; 153 return ret;
154} 154}
155 155