Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
signal.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21
22#include "signal.hh"
23
24namespace lout {
25namespace signal {
26
27using namespace container::typed;
28
29// ------------
30// Emitter
31// ------------
32
34{
35 receivers = new List <Receiver> (false);
36}
37
39{
40 for (Iterator<Receiver> it = receivers->iterator (); it.hasNext (); ) {
41 Receiver *receiver = it.getNext ();
42 receiver->unconnectFrom (this);
43 }
44 delete receivers;
45}
46
48{
49 sb->append ("<emitter: ");
50 receivers->intoStringBuffer (sb);
51 sb->append (">");
52}
53
55{
56 receivers->removeRef (receiver);
57}
58
65void Emitter::connect (Receiver *receiver)
66{
67 receivers->append (receiver);
68 receiver->connectTo (this);
69}
70
77void Emitter::emitVoid (int signalNo, int argc, Object **argv)
78{
79 for (Iterator <Receiver> it = receivers->iterator (); it.hasNext (); ) {
80 Receiver *receiver = it.getNext();
81 emitToReceiver (receiver, signalNo, argc, argv);
82 }
83}
84
91bool Emitter::emitBool (int signalNo, int argc, Object **argv)
92{
93 bool b = false, bt;
94
95 for (Iterator <Receiver> it = receivers->iterator (); it.hasNext (); ) {
96 Receiver *receiver = it.getNext();
97 // Note: All receivers are called, even if one returns true.
98 // Therefore, something like
99 // b = b || emitToReceiver (receiver, signalNo, argc, argv);
100 // does not work.
101 bt = emitToReceiver (receiver, signalNo, argc, argv);
102 b = b || bt;
103 }
104
105 return b;
106}
107
108
109// --------------
110// Receiver
111// --------------
112
114{
115 emitters = new List <Emitter> (false);
116}
117
119{
120 for (Iterator<Emitter> it = emitters->iterator(); it.hasNext(); ) {
121 Emitter *emitter = it.getNext();
122 emitter->unconnect (this);
123 }
124 delete emitters;
125}
126
128{
129 // emitters are not listed, to prevent recursion
130 sb->append ("<receiver>");
131}
132
134{
135 emitters->append (emitter);
136}
137
139{
140 emitters->removeRef (emitter);
141}
142
143// ------------------------
144// ObservedObject
145// ------------------------
146
148 int signalNo,
149 int argc, Object **argv)
150{
151 object::TypedPointer <ObservedObject> *p =
153 ((DeletionReceiver*)receiver)->deleted (p->getTypedValue ());
154 return false;
155}
156
158{
159 object::TypedPointer <ObservedObject> p(obj);
160 object::Object *argv[1] = { &p };
161 emitVoid (0, 1, argv);
162}
163
168
169} // namespace signal
170} // namespace lout
Typed version of container::untyped::Iterator.
Definition container.hh:395
A class for fast concatenation of a large number of strings.
Definition misc.hh:570
void append(const char *str)
Append a NUL-terminated string to the buffer, with copying.
Definition misc.hh:593
This is the base class for many other classes, which defines very common virtual methods.
Definition object.hh:25
A typed version of object::Pointer.
Definition object.hh:116
The base class for signal emitters.
Definition signal.hh:213
void connect(Receiver *receiver)
Connect a receiver to the emitter.
Definition signal.cc:65
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition signal.cc:47
void unconnect(Receiver *receiver)
Definition signal.cc:54
bool emitBool(int signalNo, int argc, Object **argv)
Emit a boolean signal.
Definition signal.cc:91
void emitVoid(int signalNo, int argc, Object **argv)
Emit a void signal.
Definition signal.cc:77
virtual bool emitToReceiver(Receiver *receiver, int signalNo, int argc, Object **argv)=0
A sub class must implement this for a call to a single receiver.
container::typed::List< Receiver > * receivers
Definition signal.hh:217
bool emitToReceiver(signal::Receiver *receiver, int signalNo, int argc, Object **argv)
A sub class must implement this for a call to a single receiver.
Definition signal.cc:147
void emitDeletion(ObservedObject *obj)
Definition signal.cc:157
An observed object has a signal emitter, which tells the receivers, when the object is deleted.
Definition signal.hh:275
DeletionEmitter deletionEmitter
Definition signal.hh:297
The base class for signal receiver base classes.
Definition signal.hh:254
void unconnectFrom(Emitter *emitter)
Definition signal.cc:138
void connectTo(Emitter *emitter)
Definition signal.cc:133
container::typed::List< Emitter > * emitters
Definition signal.hh:258
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition signal.cc:127