aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authormarkt <markt>2007-11-22 04:07:57 (GMT)
committermarkt <markt>2007-11-22 04:07:57 (GMT)
commit675bc5d66aa08311e99cb00cf836d16a910a73df (patch)
tree9118f77bcc38631f944cdf4a07d2173011a29a9b /src/FbTk
parent08ebff4b319f51b4263cded0bb9c04103bcd9c3a (diff)
downloadfluxbox_pavel-675bc5d66aa08311e99cb00cf836d16a910a73df.zip
fluxbox_pavel-675bc5d66aa08311e99cb00cf836d16a910a73df.tar.bz2
added conditional statements to keys file
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Command.hh8
-rw-r--r--src/FbTk/LogicCommands.cc75
-rw-r--r--src/FbTk/LogicCommands.hh97
-rw-r--r--src/FbTk/Makefile.am1
-rw-r--r--src/FbTk/SimpleCommand.hh12
5 files changed, 193 insertions, 0 deletions
diff --git a/src/FbTk/Command.hh b/src/FbTk/Command.hh
index 391aa78..5d38cb8 100644
--- a/src/FbTk/Command.hh
+++ b/src/FbTk/Command.hh
@@ -31,6 +31,14 @@ public:
31 virtual void execute() = 0; 31 virtual void execute() = 0;
32}; 32};
33 33
34/// Interface class for boolean commands
35class BoolCommand: public Command {
36public:
37 virtual ~BoolCommand() { }
38 virtual void execute() { bool_execute(); }
39 virtual bool bool_execute() = 0;
40};
41
34} // end namespace FbTk 42} // end namespace FbTk
35 43
36#endif // FBTK_COMMAND_HH 44#endif // FBTK_COMMAND_HH
diff --git a/src/FbTk/LogicCommands.cc b/src/FbTk/LogicCommands.cc
new file mode 100644
index 0000000..99b5b53
--- /dev/null
+++ b/src/FbTk/LogicCommands.cc
@@ -0,0 +1,75 @@
1// LogicCommands.cc for FbTk
2// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: $
23
24#include "LogicCommands.hh"
25
26namespace FbTk {
27
28void OrCommand::add(RefCount<BoolCommand> &com) {
29 m_commandlist.push_back(com);
30}
31
32size_t OrCommand::size() const {
33 return m_commandlist.size();
34}
35
36bool OrCommand::bool_execute() {
37 for (size_t i=0; i < m_commandlist.size(); ++i) {
38 if (m_commandlist[i]->bool_execute())
39 return true;
40 }
41 return false;
42}
43
44void AndCommand::add(RefCount<BoolCommand> &com) {
45 m_commandlist.push_back(com);
46}
47
48size_t AndCommand::size() const {
49 return m_commandlist.size();
50}
51
52bool AndCommand::bool_execute() {
53 for (size_t i=0; i < m_commandlist.size(); ++i) {
54 if (!m_commandlist[i]->bool_execute())
55 return false;
56 }
57 return true;
58}
59
60void XorCommand::add(RefCount<BoolCommand> &com) {
61 m_commandlist.push_back(com);
62}
63
64size_t XorCommand::size() const {
65 return m_commandlist.size();
66}
67
68bool XorCommand::bool_execute() {
69 bool ret = false;
70 for (size_t i=0; i < m_commandlist.size(); ++i)
71 ret ^= m_commandlist[i]->bool_execute();
72 return ret;
73}
74
75}; // end namespace FbTk
diff --git a/src/FbTk/LogicCommands.hh b/src/FbTk/LogicCommands.hh
new file mode 100644
index 0000000..a94dad8
--- /dev/null
+++ b/src/FbTk/LogicCommands.hh
@@ -0,0 +1,97 @@
1// LogicCommands.hh for FbTk
2// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: $
23
24#ifndef FBTK_LOGICCOMMANDS_HH
25#define FBTK_LOGICCOMMANDS_HH
26
27#include "Command.hh"
28#include "RefCount.hh"
29
30#include <vector>
31
32namespace FbTk {
33
34/// executes a boolcommand and uses the result to decide what to do
35class IfCommand: public Command {
36public:
37 IfCommand(RefCount<BoolCommand> &cond,
38 RefCount<Command> &t, RefCount<Command> &f):
39 m_cond(cond), m_t(t), m_f(f) { }
40 void execute() {
41 if (m_cond->bool_execute())
42 m_t->execute();
43 else
44 m_f->execute();
45 }
46
47private:
48 RefCount<BoolCommand> m_cond;
49 RefCount<Command> m_t, m_f;
50};
51
52/// executes a list of boolcommands until one is true
53class OrCommand: public BoolCommand {
54public:
55 void add(RefCount<BoolCommand> &com);
56 size_t size() const;
57 bool bool_execute();
58
59private:
60 std::vector<RefCount<BoolCommand> > m_commandlist;
61};
62
63/// executes a list of boolcommands until one is false
64class AndCommand: public BoolCommand {
65public:
66 void add(RefCount<BoolCommand> &com);
67 size_t size() const;
68 bool bool_execute();
69
70private:
71 std::vector<RefCount<BoolCommand> > m_commandlist;
72};
73
74/// executes a list of boolcommands, returning the parity
75class XorCommand: public BoolCommand {
76public:
77 void add(RefCount<BoolCommand> &com);
78 size_t size() const;
79 bool bool_execute();
80
81private:
82 std::vector<RefCount<BoolCommand> > m_commandlist;
83};
84
85/// executes a boolcommand and returns the negation
86class NotCommand: public BoolCommand {
87public:
88 NotCommand(RefCount<BoolCommand> &com): m_command(com) { }
89 bool bool_execute() { return !m_command->bool_execute(); }
90
91private:
92 RefCount<BoolCommand> m_command;
93};
94
95} // end namespace FbTk
96
97#endif // FBTK_LOGICCOMMANDS_HH
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am
index d98c8f6..2bf9da7 100644
--- a/src/FbTk/Makefile.am
+++ b/src/FbTk/Makefile.am
@@ -21,6 +21,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
21 FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \ 21 FbWindow.hh FbWindow.cc Font.cc Font.hh FontImp.hh \
22 I18n.cc I18n.hh \ 22 I18n.cc I18n.hh \
23 ImageControl.hh ImageControl.cc \ 23 ImageControl.hh ImageControl.cc \
24 LogicCommands.hh LogicCommands.cc \
24 MacroCommand.hh MacroCommand.cc \ 25 MacroCommand.hh MacroCommand.cc \
25 Menu.hh Menu.cc MenuItem.hh MenuItem.cc \ 26 Menu.hh Menu.cc MenuItem.hh MenuItem.cc \
26 MultiButtonMenuItem.hh MultiButtonMenuItem.cc \ 27 MultiButtonMenuItem.hh MultiButtonMenuItem.cc \
diff --git a/src/FbTk/SimpleCommand.hh b/src/FbTk/SimpleCommand.hh
index 8cc7283..7ae91a5 100644
--- a/src/FbTk/SimpleCommand.hh
+++ b/src/FbTk/SimpleCommand.hh
@@ -39,6 +39,18 @@ private:
39 Action m_action; 39 Action m_action;
40}; 40};
41 41
42template <typename Receiver, typename ReturnType=bool>
43class SimpleBoolCommand: public BoolCommand {
44public:
45 typedef ReturnType (Receiver::* Action)();
46 SimpleBoolCommand(Receiver &r, Action a):
47 m_receiver(r), m_action(a) { }
48 bool bool_execute() { return (bool)(m_receiver.*m_action)(); }
49private:
50 Receiver &m_receiver;
51 Action m_action;
52};
53
42} // end namespace FbTk 54} // end namespace FbTk
43 55
44#endif // FBTK_SIMPLECOMMAND_HH 56#endif // FBTK_SIMPLECOMMAND_HH