aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-04-28 09:31:06 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-05-10 11:00:46 (GMT)
commit7525ca9f7745a7d8ef4461dc1f3c911498546b00 (patch)
tree60b1fcca80140e205009683274bd374566d21e59 /src/FbTk
parent57acca0b601277982e63fa34eb78ae7881873e09 (diff)
downloadfluxbox_paul-7525ca9f7745a7d8ef4461dc1f3c911498546b00.zip
fluxbox_paul-7525ca9f7745a7d8ef4461dc1f3c911498546b00.tar.bz2
Remove all trace of Observers and Subjects
this marks the completion of the transition to FbTk::Signal
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Makefile.am3
-rw-r--r--src/FbTk/Observer.cc31
-rw-r--r--src/FbTk/Observer.hh37
-rw-r--r--src/FbTk/RelaySignal.hh62
-rw-r--r--src/FbTk/SimpleObserver.hh70
-rw-r--r--src/FbTk/Subject.cc85
-rw-r--r--src/FbTk/Subject.hh57
7 files changed, 1 insertions, 344 deletions
diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am
index 8619cc1..4c38f84 100644
--- a/src/FbTk/Makefile.am
+++ b/src/FbTk/Makefile.am
@@ -46,7 +46,6 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
46 StringUtil.hh StringUtil.cc Parser.hh Parser.cc \ 46 StringUtil.hh StringUtil.cc Parser.hh Parser.cc \
47 RegExp.hh RegExp.cc \ 47 RegExp.hh RegExp.cc \
48 FbString.hh FbString.cc \ 48 FbString.hh FbString.cc \
49 Subject.hh Subject.cc Observer.hh Observer.cc SimpleObserver.hh \
50 AutoReloadHelper.hh AutoReloadHelper.cc \ 49 AutoReloadHelper.hh AutoReloadHelper.cc \
51 Transparent.hh Transparent.cc \ 50 Transparent.hh Transparent.cc \
52 FbPixmap.hh FbPixmap.cc \ 51 FbPixmap.hh FbPixmap.cc \
@@ -63,7 +62,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \
63 TypeAhead.hh SearchResult.hh SearchResult.cc ITypeAheadable.hh \ 62 TypeAhead.hh SearchResult.hh SearchResult.cc ITypeAheadable.hh \
64 Select2nd.hh STLUtil.hh \ 63 Select2nd.hh STLUtil.hh \
65 CachedPixmap.hh CachedPixmap.cc \ 64 CachedPixmap.hh CachedPixmap.cc \
66 Slot.hh Signal.hh MemFun.hh RelaySignal.hh SelectArg.hh \ 65 Slot.hh Signal.hh MemFun.hh SelectArg.hh \
67 Util.hh \ 66 Util.hh \
68 ${xpm_SOURCE} \ 67 ${xpm_SOURCE} \
69 ${xft_SOURCE} \ 68 ${xft_SOURCE} \
diff --git a/src/FbTk/Observer.cc b/src/FbTk/Observer.cc
deleted file mode 100644
index dcd115f..0000000
--- a/src/FbTk/Observer.cc
+++ /dev/null
@@ -1,31 +0,0 @@
1// Observer.cc for FbTk
2// Copyright (c) 2002 - 2006 Henrik Kinnunen (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#include "Observer.hh"
23#include "Subject.hh"
24
25namespace FbTk {
26
27Observer::~Observer() {
28 Subject::removeObserver(this); // make sure no subject has this observer attached
29}
30
31}
diff --git a/src/FbTk/Observer.hh b/src/FbTk/Observer.hh
deleted file mode 100644
index 3f1a8c3..0000000
--- a/src/FbTk/Observer.hh
+++ /dev/null
@@ -1,37 +0,0 @@
1// Observer.hh for FbTk
2// Copyright (c) 2002 Henrik Kinnunen (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#ifndef FBTK_OBSERVER_HH
23#define FBTK_OBSERVER_HH
24
25namespace FbTk {
26
27class Subject;
28
29class Observer {
30public:
31 virtual ~Observer();
32 virtual void update(Subject *changedSubj) = 0;
33};
34
35} // end namespace FBTK
36
37#endif // FBTK_OBSERVER_HH
diff --git a/src/FbTk/RelaySignal.hh b/src/FbTk/RelaySignal.hh
deleted file mode 100644
index e9b7281..0000000
--- a/src/FbTk/RelaySignal.hh
+++ /dev/null
@@ -1,62 +0,0 @@
1// RelaySignal.hh
2// Copyright (c) 2010 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#ifndef FBTK_RELAY_SIGNAL_HH
23#define FBTK_RELAY_SIGNAL_HH
24
25#include "Signal.hh"
26#include "MemFun.hh"
27#include "Subject.hh"
28
29namespace FbTk {
30
31/**
32 * Relays a new signal type to the old subject type signal. When the new signal
33 * emits the subject notify() will be called.
34 * This function is temporary and just a helper during transition between old
35 * and new signal system.
36 *
37 * @param from The original source of the signal.
38 * @param to_subject The destination Subject.
39 */
40template < typename Signal >
41void relaySignal(Signal& from, FbTk::Subject& to_subject) {
42 from.connect(MemFunIgnoreArgs(to_subject, &FbTk::Subject::notify));
43}
44
45/**
46 * Relays a new signal type to the old subject type signal. When the new signal
47 * emits the subject notify() will be called.
48 * This function is temporary and just a helper during transition between old
49 * and new signal system.
50 *
51 * @param tracker Keeps track of signals
52 * @param from The original source of the signal.
53 * @param to_subject The destination Subject
54 */
55template < typename Signal >
56void relaySignal(SignalTracker& tracker, Signal& from, FbTk::Subject& to_subject) {
57 tracker.join(from, MemFunIgnoreArgs(to_subject, &FbTk::Subject::notify));
58}
59
60} // end namespace FbTk
61
62#endif // FBTK_RELAY_SIGNAL_HH
diff --git a/src/FbTk/SimpleObserver.hh b/src/FbTk/SimpleObserver.hh
deleted file mode 100644
index aafdf59..0000000
--- a/src/FbTk/SimpleObserver.hh
+++ /dev/null
@@ -1,70 +0,0 @@
1// SimpleObserver.hh
2// Copyright (c) 2008 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#include "Observer.hh"
23#include "SimpleCommand.hh"
24
25namespace FbTk {
26
27/** Functor for observers, instead of using this directly use makeObserver.
28 * Usage:
29 * @code
30 * class SomeClass {
31 * public:
32 * void doAction();
33 * };
34 *
35 * SomeClass some;
36 *
37 * Observer* obs = makeProxyObserver(some, &SomeClass::doAction);
38 * SomeSubject subj;
39 * subj.attach(obs);
40 * @endcode
41 */
42template <typename Receiver>
43class SimpleObserver: public Observer {
44public:
45 typedef void (Receiver::* Action)();
46 SimpleObserver(Receiver &r, Action a):
47 m_receiver(r), m_action(a) {
48
49 }
50 void update(Subject *changedSubj) {
51 (m_receiver.*m_action)();
52 }
53private:
54 Receiver &m_receiver;
55 Action m_action;
56};
57
58// Helpers
59/** Creates an observer that takes no arguments.
60 * @param receiver The receiving instance.
61 * @param action A function in the receiving class.
62 * @return allocated simple observer. @see SimpleObserver
63 */
64template <typename Receiver, typename Action>
65Observer *makeObserver(Receiver &receiver, Action action) {
66 return new SimpleObserver<Receiver>( receiver, action );
67}
68
69}
70
diff --git a/src/FbTk/Subject.cc b/src/FbTk/Subject.cc
deleted file mode 100644
index 594eb23..0000000
--- a/src/FbTk/Subject.cc
+++ /dev/null
@@ -1,85 +0,0 @@
1// Subject.cc for FbTk
2// Copyright (c) 2002 - 2006 Henrik Kinnunen (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#include "Subject.hh"
23#include "Observer.hh"
24
25#include <algorithm>
26#include <functional>
27
28namespace FbTk {
29
30Subject::SubjectList Subject::s_subjectlist;
31
32Subject::Subject():m_notify_mode(false) {
33 s_subjectlist.push_back(this);
34}
35
36Subject::~Subject() {
37 s_subjectlist.erase(std::remove(s_subjectlist.begin(),
38 s_subjectlist.end(), this));
39}
40
41void Subject::attach(Observer *obj) {
42 m_observerlist.push_back(obj);
43 // no need to have more than one instance of an observer
44 m_observerlist.erase(std::unique(m_observerlist.begin(), m_observerlist.end()),
45 m_observerlist.end());
46}
47
48void Subject::detach(Observer *obj) {
49 if (m_notify_mode)
50 m_dead_observers.push_back(obj);
51 else {
52 m_observerlist.erase(std::remove(m_observerlist.begin(),
53 m_observerlist.end(), obj),
54 m_observerlist.end());
55 }
56}
57
58void Subject::notify() {
59 ObserverList::iterator it = m_observerlist.begin(),
60 it_end = m_observerlist.end();
61 for (; it != it_end; ++it) {
62 m_notify_mode = true;
63 (*it)->update(this);
64 ObserverList::iterator d_it = m_dead_observers.begin(),
65 d_it_end = m_dead_observers.end();
66 m_notify_mode = false;
67
68 // there might be dead observers later in the list, so we must remove
69 // them now
70 for (; d_it != d_it_end; ++d_it) {
71 if (*d_it == *it)
72 --it; // don't invalidate our iterator
73 detach(*d_it);
74 }
75 m_dead_observers.clear();
76 }
77}
78
79void Subject::removeObserver(Observer *obj) {
80 std::for_each(s_subjectlist.begin(), s_subjectlist.end(),
81 std::bind2nd(std::mem_fun(&Subject::detach), obj));
82
83}
84
85} // end namespace FbTk
diff --git a/src/FbTk/Subject.hh b/src/FbTk/Subject.hh
deleted file mode 100644
index f2cde41..0000000
--- a/src/FbTk/Subject.hh
+++ /dev/null
@@ -1,57 +0,0 @@
1// Subject.hh for FbTk
2// Copyright (c) 2002-2003 Henrik Kinnunen (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#ifndef FBTK_SUBJECT_HH
23#define FBTK_SUBJECT_HH
24
25#include "NotCopyable.hh"
26
27#include <list>
28
29namespace FbTk {
30
31class Observer;
32
33class Subject:private FbTk::NotCopyable {
34public:
35 Subject();
36 virtual ~Subject();
37 /// attach an observer
38 void attach(Observer *obs);
39 /// detach an observer
40 void detach(Observer *obs);
41 /// notify all attached observers
42 void notify();
43 static void removeObserver(Observer *obs);
44private:
45 bool m_notify_mode;
46
47 typedef std::list<Observer *> ObserverList;
48 ObserverList m_observerlist;
49 ObserverList m_dead_observers;
50
51 typedef std::list<Subject *> SubjectList;
52 static SubjectList s_subjectlist;
53};
54
55} // end namespace FbTk
56
57#endif // FBTK_SUBJECT_HH