2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __pbd_shiva_h__
21 #define __pbd_shiva_h__
23 #include <sigc++/sigc++.h>
27 /* named after the Hindu god Shiva, The Destroyer */
29 template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
30 class Shiva : public sigc::trackable
33 Shiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver) {
35 /* if the emitter goes away, destroy the receiver */
37 _connection = emitter.GoingAway.connect
38 (sigc::bind (sigc::mem_fun
39 (*this, &Shiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
48 sigc::connection _connection;
50 void destroy (ObjectToBeDestroyed* obj) {
56 _connection.disconnect ();
61 template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
62 class ProxyShiva : public sigc::trackable
65 ProxyShiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver, void (*callback)(ObjectToBeDestroyed*, ObjectWithGoingAway*)) {
67 /* if the emitter goes away, destroy the receiver */
70 _callback_argument = &emitter;
72 _connection = emitter.GoingAway.connect
73 (sigc::bind (sigc::mem_fun
74 (*this, &ProxyShiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
83 sigc::connection _connection;
84 void (*_callback) (ObjectToBeDestroyed*, ObjectWithGoingAway*);
85 ObjectWithGoingAway* _callback_argument;
87 void destroy (ObjectToBeDestroyed* obj) {
88 /* callback must destroy obj if appropriate, not done here */
89 _callback (obj, _callback_argument);
94 _connection.disconnect ();
98 template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
99 class PairedShiva : public sigc::trackable
102 PairedShiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver) {
104 /* if the emitter goes away, destroy the receiver */
106 _connection1 = emitter.GoingAway.connect
107 (sigc::bind (sigc::mem_fun
108 (*this, &PairedShiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
111 /* if the receiver goes away, forget all this nonsense */
113 _connection2 = receiver.GoingAway.connect
114 (sigc::mem_fun (*this, &PairedShiva<ObjectWithGoingAway,ObjectToBeDestroyed>::forget));
122 sigc::connection _connection1;
123 sigc::connection _connection2;
125 void destroy (ObjectToBeDestroyed* obj) {
131 _connection1.disconnect ();
132 _connection2.disconnect ();
139 #endif /* __pbd_shiva_h__ */