Remove all trace of Observers and Subjects
this marks the completion of the transition to FbTk::Signal
This commit is contained in:
parent
57acca0b60
commit
7525ca9f77
15 changed files with 2 additions and 359 deletions
|
@ -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"
|
||||
|
|
|
@ -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} \
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
|
@ -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
|
|
@ -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 <typename Receiver>
|
||||
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 <typename Receiver, typename Action>
|
||||
Observer *makeObserver(Receiver &receiver, Action action) {
|
||||
return new SimpleObserver<Receiver>( receiver, action );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <algorithm>
|
||||
#include <functional>
|
||||
|
||||
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
|
|
@ -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 <list>
|
||||
|
||||
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<Observer *> ObserverList;
|
||||
ObserverList m_observerlist;
|
||||
ObserverList m_dead_observers;
|
||||
|
||||
typedef std::list<Subject *> SubjectList;
|
||||
static SubjectList s_subjectlist;
|
||||
};
|
||||
|
||||
} // end namespace FbTk
|
||||
|
||||
#endif // FBTK_SUBJECT_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"
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#define FOCUSABLETHEME_HH
|
||||
|
||||
#include "Focusable.hh"
|
||||
#include "FbTk/MemFun.hh"
|
||||
#include "FbTk/Theme.hh"
|
||||
#include "FbTk/RelaySignal.hh"
|
||||
|
||||
template <typename BaseTheme>
|
||||
class FocusableTheme: public FbTk::ThemeProxy<BaseTheme> {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<void> {
|
||||
|
|
|
@ -27,10 +27,6 @@
|
|||
|
||||
#include "FbTk/Signal.hh"
|
||||
|
||||
namespace FbTk {
|
||||
class Observer;
|
||||
}
|
||||
|
||||
class BScreen;
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#define WINBUTTON_HH
|
||||
|
||||
#include "FbTk/Button.hh"
|
||||
#include "FbTk/Observer.hh"
|
||||
#include "FbTk/FbPixmap.hh"
|
||||
#include "FbTk/Signal.hh"
|
||||
|
||||
|
|
|
@ -317,9 +317,6 @@ public:
|
|||
void leaveNotifyEvent(XCrossingEvent &ev);
|
||||
//@}
|
||||
|
||||
/// handle Subject notifications
|
||||
void update(FbTk::Subject *subj);
|
||||
|
||||
void applyDecorations();
|
||||
void toggleDecoration();
|
||||
|
||||
|
|
Loading…
Reference in a new issue