2 dnl Abstract Slot templates
4 dnl Copyright (C) 1998 Karl Nelson <kenelson@ece.ucdavis.edu>
6 dnl This library is free software; you can redistribute it and/or
7 dnl modify it under the terms of the GNU Library General Public
8 dnl License as published by the Free Software Foundation; either
9 dnl version 2 of the License, or (at your option) any later version.
11 dnl This library is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 dnl Library General Public License for more details.
16 dnl You should have received a copy of the GNU Library General Public
17 dnl License along with this library; if not, write to the Free
18 dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 dnl Ignore the next line
22 /* This is a generated file, do not edit. Generated from __file__ */
23 include(template.macros.m4)
30 This file just gives the basic definition of Slots.
32 Callback# is the 4 byte data necessary for representing all
35 CallData is a specific interpretation of the Callback data.
37 Slot_ is a pimple on SlotData containing an Object for
38 holding its referencees, a Dependency that removes the slot
39 when its caller or receiver die, and a Callback.
41 Slot is a handle to a Slot_.
45 #include <sigc++/sigc++config.h>
46 #include <sigc++/type.h>
47 #include <sigc++/object.h>
48 #include <sigc++/handle.h>
50 #ifdef SIGC_CXX_NAMESPACES
55 // Base node for a polymorphic list of "extra" data needed
57 struct LIBSIGC_API SlotNode
61 virtual ~SlotNode()=0;
64 struct LIBSIGC_API SlotIterator_
66 typedef SlotNode NodeType;
67 typedef SlotIterator_ Iterator;
70 NodeType* node() {return node_;}
71 const NodeType* node() const {return node_;}
76 const NodeType& operator*() const
80 bool operator==(const Iterator& i) const
81 {return node_==i.node_;
83 bool operator!=(const Iterator& i) const
84 {return node_!=i.node_;
87 Iterator& operator++()
90 node_=(NodeType*)node_->next_;
94 Iterator operator++(int)
100 Iterator& operator= (const Iterator& i)
106 SlotIterator_():node_(0) {}
107 SlotIterator_(NodeType *node):node_(node) {}
110 // This is a list for storing internal data for slots
111 struct LIBSIGC_API SlotList_
113 typedef SlotNode NodeType;
114 typedef SlotIterator_ Iterator;
117 Iterator begin() {return ((NodeType*)head_);}
118 Iterator end() {return Iterator();}
119 const Iterator begin() const {return ((NodeType*)head_);}
120 const Iterator end() const {return Iterator();}
122 // this is best used at the begining of list.
123 Iterator insert_direct(Iterator pos,NodeType *n);
126 bool empty() const {return head_==0;}
134 SlotList_(const SlotList_&);
140 // SlotDependent is an internal of SlotData used to unreference the
141 // Slot when either the sender or receiver have gone away
142 struct LIBSIGC_API SlotDependent:public ScopeNode
144 struct LIBSIGC_API Dep: public ScopeNode
147 virtual void erase();
152 ScopeNode* receiver() {return &dep;}
153 ScopeNode* sender() {return this;}
154 SlotData* parent() {return dep.parent;}
157 {return (next_!=this);}
159 virtual void erase();
161 void set_parent(SlotData *s)
164 SlotDependent(SlotData &s)
170 virtual ~SlotDependent();
173 // common data to all callbacks.
177 void* (*func_)(void*);
190 // Object pointer or function pointer
191 union {C1 a1; C2 a2;};
194 // All slots have the same base
195 struct LIBSIGC_API SlotData:public ObjectScoped
197 typedef SlotList_ List;
201 ScopeNode* receiver() {return dep_.receiver();}
202 ScopeNode* sender() {return dep_.sender();}
204 // Called from signals to tell slot object it is connected
205 // invalidates list and sets weak reference
211 Callback_& callback() {return data_;}
214 {dep_.set_parent(this);}
219 typedef Scopes::Extend SlotExtend;
221 #pragma warning(disable: 4231)
222 LIBSIGC_TMPL template class LIBSIGC_API Handle<SlotData,SlotExtend>;
224 class LIBSIGC_API Connection:protected Handle<SlotData,SlotExtend>
226 typedef Handle<SlotData,SlotExtend> Base;
228 // hides virtual method
229 void disconnect() {if (obj()) obj()->invalid();}
230 bool connected() {return Base::connected ();}
232 Connection():Base() {}
233 Connection(SlotData *s):Base(s) {}
234 Connection(const Connection& s):Base(s) {}
237 // possible casts of Callback
238 template <class C,class F>
245 template <class C,class O>
252 template <class C,class O,class F>
260 // from Abstract_Slots we build abstract slots
261 // with various lengths of arguments
262 // A slot is not concrete til it has a call
265 dnl SLOT([P1,P2,...])
268 /****************************************************************
269 ***** Abstract Slot NUM($1)
270 ****************************************************************/
273 #ifndef SIGC_CXX_VOID_RETURN
274 #ifdef SIGC_CXX_PARTIAL_SPEC
282 dnl SLOT_IMPL(R,[P1,P2,...])
284 define([SLOT_IMPL],[dnl
288 template <ARG_CLASS($2)>
289 struct [Callback]NUM($2)<LIST(void,1,ARG_TYPE($2),[$2])>:public Callback_
292 typedef RType (*Func)(LIST([void*],1,ARG_TYPE($2),[$2]));
293 inline RType call(ARG_REF($2))
294 {((Func)(func_))(LIST([(void*)this],1,ARG_NAME($2),[$2]));}
295 inline RType operator()(ARG_REF($2))
296 {((Func)(func_))(LIST([(void*)this],1,ARG_NAME($2),[$2]));}
299 template <LIST(class R,1,ARG_CLASS($2),[$2])>
300 struct [Callback]NUM($2):public Callback_
302 #ifdef SIGC_CXX_PARTIAL_SPEC
305 typedef Trait<R>::type RType;
307 typedef RType (*Func)(LIST([void*],1,ARG_TYPE($2),[$2]));
308 inline RType call(ARG_REF($2))
309 {return ((Func)(func_))(LIST([(void*)this],1,ARG_NAME($2),[$2]));}
310 inline RType operator()(ARG_REF($2))
311 {return ((Func)(func_))(LIST([(void*)this],1,ARG_NAME($2),[$2]));}
316 template <ARG_CLASS($2)>
317 class __SLOT__(void,[$2])
319 template <LIST(class R,1,ARG_CLASS($2),[$2])>
322 :public Handle<SlotData,SlotExtend>
325 typedef Handle<SlotData,SlotExtend> Base;
326 typedef [Callback]NUM($2)<LIST($1,1,ARG_TYPE($2),[$2])> Callback;
327 typedef ifelse([$1$2],void,,typename) Callback::RType RType;
328 typedef RType (*Func)(LIST([void*],1,ARG_TYPE($2),[$2]));
330 SlotData* data() const {return (SlotData*)(scope_.object());}
333 [Slot]NUM($2)(SlotData *s):Base(s) {}
334 [Slot]NUM($2)(const [Slot]NUM($2)& s):Base(s.obj()) {}
336 inline RType call(ARG_REF($2))
340 ((Callback&)(data()->callback())).call(ARG_NAME($2));
342 return ((Callback&)(data()->callback())).call(ARG_NAME($2));
346 inline RType operator()(ARG_REF($2))
350 ((Callback&)(data()->callback())).call(ARG_NAME($2));
352 return ((Callback&)(data()->callback())).call(ARG_NAME($2));
366 #ifdef SIGC_CXX_NAMESPACES