1 #ifndef __pbd_shiva_h__
2 #define __pbd_shiva_h__
4 #include <sigc++/sigc++.h>
8 /* named after the Hindu god Shiva, The Destroyer */
10 template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
13 Shiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver) {
15 /* if the emitter goes away, destroy the receiver */
17 _connection = emitter.GoingAway.connect
18 (sigc::bind (sigc::mem_fun
19 (*this, &Shiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
28 sigc::connection _connection;
30 void destroy (ObjectToBeDestroyed* obj) {
36 _connection.disconnect ();
41 template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
44 ProxyShiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver, void (*callback)(ObjectToBeDestroyed*, ObjectWithGoingAway*)) {
46 /* if the emitter goes away, destroy the receiver */
49 _callback_argument1 = &receiver;
50 _callback_argument2 = &emitter;
52 _connection = emitter.GoingAway.connect
53 (sigc::bind (sigc::mem_fun
54 (*this, &ProxyShiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
63 sigc::connection _connection;
64 void (*_callback) (ObjectToBeDestroyed*, ObjectWithGoingAway*);
65 ObjectToBeDestroyed* _callback_argument1;
66 ObjectWithGoingAway* _callback_argument2;
68 void destroy (ObjectToBeDestroyed* obj) {
69 /* callback must destroy obj if appropriate, not done here */
70 _callback (obj, _callback_argument2);
75 _connection.disconnect ();
79 template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
82 PairedShiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver) {
84 /* if the emitter goes away, destroy the receiver */
86 _connection1 = emitter.GoingAway.connect
87 (sigc::bind (sigc::mem_fun
88 (*this, &PairedShiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
91 /* if the receiver goes away, forget all this nonsense */
93 _connection2 = receiver.GoingAway.connect
94 (sigc::mem_fun (*this, &PairedShiva<ObjectWithGoingAway,ObjectToBeDestroyed>::forget));
102 sigc::connection _connection1;
103 sigc::connection _connection2;
105 void destroy (ObjectToBeDestroyed* obj) {
111 _connection1.disconnect ();
112 _connection2.disconnect ();
119 #endif /* __pbd_shiva_h__ */