From 7525ca9f7745a7d8ef4461dc1f3c911498546b00 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 28 Apr 2011 11:31:06 +0200 Subject: [PATCH] Remove all trace of Observers and Subjects this marks the completion of the transition to FbTk::Signal --- src/AttentionNoticeHandler.cc | 1 - src/FbTk/Makefile.am | 3 +- src/FbTk/Observer.cc | 31 ------------- src/FbTk/Observer.hh | 37 --------------- src/FbTk/RelaySignal.hh | 62 ------------------------- src/FbTk/SimpleObserver.hh | 70 ----------------------------- src/FbTk/Subject.cc | 85 ----------------------------------- src/FbTk/Subject.hh | 57 ----------------------- src/FocusableList.hh | 2 - src/FocusableTheme.hh | 2 +- src/Screen.hh | 2 - src/SendToMenu.cc | 1 - src/SendToMenu.hh | 4 -- src/WinButton.hh | 1 - src/Window.hh | 3 -- 15 files changed, 2 insertions(+), 359 deletions(-) delete mode 100644 src/FbTk/Observer.cc delete mode 100644 src/FbTk/Observer.hh delete mode 100644 src/FbTk/RelaySignal.hh delete mode 100644 src/FbTk/SimpleObserver.hh delete mode 100644 src/FbTk/Subject.cc delete mode 100644 src/FbTk/Subject.hh diff --git a/src/AttentionNoticeHandler.cc b/src/AttentionNoticeHandler.cc index 7edd8e20..0aaf266a 100644 --- a/src/AttentionNoticeHandler.cc +++ b/src/AttentionNoticeHandler.cc @@ -25,7 +25,6 @@ #include "Screen.hh" #include "FbTk/STLUtil.hh" -#include "FbTk/Subject.hh" #include "FbTk/Timer.hh" #include "FbTk/Resource.hh" #include "FbTk/MemFun.hh" diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am index 8619cc11..4c38f84b 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 \ StringUtil.hh StringUtil.cc Parser.hh Parser.cc \ RegExp.hh RegExp.cc \ FbString.hh FbString.cc \ - Subject.hh Subject.cc Observer.hh Observer.cc SimpleObserver.hh \ AutoReloadHelper.hh AutoReloadHelper.cc \ Transparent.hh Transparent.cc \ FbPixmap.hh FbPixmap.cc \ @@ -63,7 +62,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ TypeAhead.hh SearchResult.hh SearchResult.cc ITypeAheadable.hh \ Select2nd.hh STLUtil.hh \ CachedPixmap.hh CachedPixmap.cc \ - Slot.hh Signal.hh MemFun.hh RelaySignal.hh SelectArg.hh \ + Slot.hh Signal.hh MemFun.hh SelectArg.hh \ Util.hh \ ${xpm_SOURCE} \ ${xft_SOURCE} \ diff --git a/src/FbTk/Observer.cc b/src/FbTk/Observer.cc deleted file mode 100644 index dcd115f9..00000000 --- a/src/FbTk/Observer.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Observer.cc for FbTk -// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -#include "Observer.hh" -#include "Subject.hh" - -namespace FbTk { - -Observer::~Observer() { - Subject::removeObserver(this); // make sure no subject has this observer attached -} - -} diff --git a/src/FbTk/Observer.hh b/src/FbTk/Observer.hh deleted file mode 100644 index 3f1a8c3b..00000000 --- a/src/FbTk/Observer.hh +++ /dev/null @@ -1,37 +0,0 @@ -// Observer.hh for FbTk -// Copyright (c) 2002 Henrik Kinnunen (fluxgen at fluxbox dot org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -#ifndef FBTK_OBSERVER_HH -#define FBTK_OBSERVER_HH - -namespace FbTk { - -class Subject; - -class Observer { -public: - virtual ~Observer(); - virtual void update(Subject *changedSubj) = 0; -}; - -} // end namespace FBTK - -#endif // FBTK_OBSERVER_HH diff --git a/src/FbTk/RelaySignal.hh b/src/FbTk/RelaySignal.hh deleted file mode 100644 index e9b7281b..00000000 --- a/src/FbTk/RelaySignal.hh +++ /dev/null @@ -1,62 +0,0 @@ -// RelaySignal.hh -// Copyright (c) 2010 Fluxbox Team (fluxgen at fluxbox dot org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -#ifndef FBTK_RELAY_SIGNAL_HH -#define FBTK_RELAY_SIGNAL_HH - -#include "Signal.hh" -#include "MemFun.hh" -#include "Subject.hh" - -namespace FbTk { - -/** - * Relays a new signal type to the old subject type signal. When the new signal - * emits the subject notify() will be called. - * This function is temporary and just a helper during transition between old - * and new signal system. - * - * @param from The original source of the signal. - * @param to_subject The destination Subject. - */ -template < typename Signal > -void relaySignal(Signal& from, FbTk::Subject& to_subject) { - from.connect(MemFunIgnoreArgs(to_subject, &FbTk::Subject::notify)); -} - -/** - * Relays a new signal type to the old subject type signal. When the new signal - * emits the subject notify() will be called. - * This function is temporary and just a helper during transition between old - * and new signal system. - * - * @param tracker Keeps track of signals - * @param from The original source of the signal. - * @param to_subject The destination Subject - */ -template < typename Signal > -void relaySignal(SignalTracker& tracker, Signal& from, FbTk::Subject& to_subject) { - tracker.join(from, MemFunIgnoreArgs(to_subject, &FbTk::Subject::notify)); -} - -} // end namespace FbTk - -#endif // FBTK_RELAY_SIGNAL_HH diff --git a/src/FbTk/SimpleObserver.hh b/src/FbTk/SimpleObserver.hh deleted file mode 100644 index aafdf596..00000000 --- a/src/FbTk/SimpleObserver.hh +++ /dev/null @@ -1,70 +0,0 @@ -// SimpleObserver.hh -// Copyright (c) 2008 Fluxbox Team (fluxgen at fluxbox dot org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -#include "Observer.hh" -#include "SimpleCommand.hh" - -namespace FbTk { - -/** Functor for observers, instead of using this directly use makeObserver. - * Usage: - * @code - * class SomeClass { - * public: - * void doAction(); - * }; - * - * SomeClass some; - * - * Observer* obs = makeProxyObserver(some, &SomeClass::doAction); - * SomeSubject subj; - * subj.attach(obs); - * @endcode - */ -template -class SimpleObserver: public Observer { -public: - typedef void (Receiver::* Action)(); - SimpleObserver(Receiver &r, Action a): - m_receiver(r), m_action(a) { - - } - void update(Subject *changedSubj) { - (m_receiver.*m_action)(); - } -private: - Receiver &m_receiver; - Action m_action; -}; - -// Helpers -/** Creates an observer that takes no arguments. - * @param receiver The receiving instance. - * @param action A function in the receiving class. - * @return allocated simple observer. @see SimpleObserver - */ -template -Observer *makeObserver(Receiver &receiver, Action action) { - return new SimpleObserver( receiver, action ); -} - -} - diff --git a/src/FbTk/Subject.cc b/src/FbTk/Subject.cc deleted file mode 100644 index 594eb232..00000000 --- a/src/FbTk/Subject.cc +++ /dev/null @@ -1,85 +0,0 @@ -// Subject.cc for FbTk -// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -#include "Subject.hh" -#include "Observer.hh" - -#include -#include - -namespace FbTk { - -Subject::SubjectList Subject::s_subjectlist; - -Subject::Subject():m_notify_mode(false) { - s_subjectlist.push_back(this); -} - -Subject::~Subject() { - s_subjectlist.erase(std::remove(s_subjectlist.begin(), - s_subjectlist.end(), this)); -} - -void Subject::attach(Observer *obj) { - m_observerlist.push_back(obj); - // no need to have more than one instance of an observer - m_observerlist.erase(std::unique(m_observerlist.begin(), m_observerlist.end()), - m_observerlist.end()); -} - -void Subject::detach(Observer *obj) { - if (m_notify_mode) - m_dead_observers.push_back(obj); - else { - m_observerlist.erase(std::remove(m_observerlist.begin(), - m_observerlist.end(), obj), - m_observerlist.end()); - } -} - -void Subject::notify() { - ObserverList::iterator it = m_observerlist.begin(), - it_end = m_observerlist.end(); - for (; it != it_end; ++it) { - m_notify_mode = true; - (*it)->update(this); - ObserverList::iterator d_it = m_dead_observers.begin(), - d_it_end = m_dead_observers.end(); - m_notify_mode = false; - - // there might be dead observers later in the list, so we must remove - // them now - for (; d_it != d_it_end; ++d_it) { - if (*d_it == *it) - --it; // don't invalidate our iterator - detach(*d_it); - } - m_dead_observers.clear(); - } -} - -void Subject::removeObserver(Observer *obj) { - std::for_each(s_subjectlist.begin(), s_subjectlist.end(), - std::bind2nd(std::mem_fun(&Subject::detach), obj)); - -} - -} // end namespace FbTk diff --git a/src/FbTk/Subject.hh b/src/FbTk/Subject.hh deleted file mode 100644 index f2cde417..00000000 --- a/src/FbTk/Subject.hh +++ /dev/null @@ -1,57 +0,0 @@ -// Subject.hh for FbTk -// Copyright (c) 2002-2003 Henrik Kinnunen (fluxgen at fluxbox dot org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -#ifndef FBTK_SUBJECT_HH -#define FBTK_SUBJECT_HH - -#include "NotCopyable.hh" - -#include - -namespace FbTk { - -class Observer; - -class Subject:private FbTk::NotCopyable { -public: - Subject(); - virtual ~Subject(); - /// attach an observer - void attach(Observer *obs); - /// detach an observer - void detach(Observer *obs); - /// notify all attached observers - void notify(); - static void removeObserver(Observer *obs); -private: - bool m_notify_mode; - - typedef std::list ObserverList; - ObserverList m_observerlist; - ObserverList m_dead_observers; - - typedef std::list SubjectList; - static SubjectList s_subjectlist; -}; - -} // end namespace FbTk - -#endif // FBTK_SUBJECT_HH diff --git a/src/FocusableList.hh b/src/FocusableList.hh index aea79092..48881d0c 100644 --- a/src/FocusableList.hh +++ b/src/FocusableList.hh @@ -23,9 +23,7 @@ #define FOCUSABLELIST_HH #include "FbTk/NotCopyable.hh" -#include "FbTk/Observer.hh" #include "FbTk/RefCount.hh" -#include "FbTk/Subject.hh" #include "FbTk/Signal.hh" #include "ClientPattern.hh" diff --git a/src/FocusableTheme.hh b/src/FocusableTheme.hh index df738811..49d79453 100644 --- a/src/FocusableTheme.hh +++ b/src/FocusableTheme.hh @@ -23,8 +23,8 @@ #define FOCUSABLETHEME_HH #include "Focusable.hh" +#include "FbTk/MemFun.hh" #include "FbTk/Theme.hh" -#include "FbTk/RelaySignal.hh" template class FocusableTheme: public FbTk::ThemeProxy { diff --git a/src/Screen.hh b/src/Screen.hh index a237b36d..de3a5a15 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -35,10 +35,8 @@ #include "FbTk/MenuTheme.hh" #include "FbTk/EventHandler.hh" #include "FbTk/Resource.hh" -#include "FbTk/Subject.hh" #include "FbTk/MultLayers.hh" #include "FbTk/NotCopyable.hh" -#include "FbTk/Observer.hh" #include "FbTk/Signal.hh" #include "FocusControl.hh" diff --git a/src/SendToMenu.cc b/src/SendToMenu.cc index b148a308..afdc854a 100644 --- a/src/SendToMenu.cc +++ b/src/SendToMenu.cc @@ -30,7 +30,6 @@ #include "FbTk/MultiButtonMenuItem.hh" #include "FbTk/Command.hh" -#include "FbTk/SimpleObserver.hh" #include "FbTk/MemFun.hh" class SendToCmd: public FbTk::Command { diff --git a/src/SendToMenu.hh b/src/SendToMenu.hh index 37f45fc9..05093601 100644 --- a/src/SendToMenu.hh +++ b/src/SendToMenu.hh @@ -27,10 +27,6 @@ #include "FbTk/Signal.hh" -namespace FbTk { -class Observer; -} - class BScreen; /** diff --git a/src/WinButton.hh b/src/WinButton.hh index 35befa85..80fc4b1d 100644 --- a/src/WinButton.hh +++ b/src/WinButton.hh @@ -23,7 +23,6 @@ #define WINBUTTON_HH #include "FbTk/Button.hh" -#include "FbTk/Observer.hh" #include "FbTk/FbPixmap.hh" #include "FbTk/Signal.hh" diff --git a/src/Window.hh b/src/Window.hh index 4ecfe052..a5bcb665 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -317,9 +317,6 @@ public: void leaveNotifyEvent(XCrossingEvent &ev); //@} - /// handle Subject notifications - void update(FbTk::Subject *subj); - void applyDecorations(); void toggleDecoration();