]> git.lyx.org Git - lyx.git/blob - sigc++/macros/basic_signal.h.m4
3dfddad94e18ed9c9ac52e9a7f6173c9809aadc2
[lyx.git] / sigc++ / macros / basic_signal.h.m4
1 dnl 
2 dnl Basic Signal Templates
3 dnl 
4 dnl  Copyright 1999 Karl Nelson <kenelson@ece.ucdavis.edu>
5 dnl 
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.
10 dnl 
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.
15 dnl 
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.
19 dnl 
20 // -*- c++ -*-
21 dnl Ignore the next line
22 /* This is a generated file, do not edit.  Generated from __file__ */
23 include(template.macros.m4)
24 #ifndef __header__
25 #define __header__
26 #include <sigc++/marshal.h>
27 #include <sigc++/slot.h>
28
29 QT_FIREWALL
30
31 #ifdef SIGC_CXX_NAMESPACES
32 namespace SigC
33 {
34 #endif
35
36 /****************************************************************
37 *****  Signals (build by macros)
38 ****************************************************************/
39
40 // common part to all signals
41 class LIBSIGC_API Signal_
42   {
43     private:
44       Signal_(const Signal_&);
45
46     protected:
47       typedef ScopeList List;
48    
49       struct LIBSIGC_API Impl 
50         { 
51           typedef ScopeList List;
52           List incoming_;
53           List outgoing_;
54           Impl();
55           ~Impl();
56         };
57
58       Impl *impl;
59
60       SlotData* in_connect();
61       SlotData* out_connect(SlotData *s);
62
63       Signal_();
64       ~Signal_();
65
66     public:
67       bool empty() const;
68       void clear();
69   };
70
71 dnl
72 dnl BASIC_SIGNAL([P1, P2, ...])
73 dnl
74 define([BASIC_SIGNAL],
75 [/****************************************************************
76 *****  Signal NUM($1)
77 ****************************************************************/
78 LINE(]__line__[)dnl
79
80 template <LIST(class R,1,ARG_CLASS($1),[$1],[typename Marsh=class Marshal<R> ],1)>
81   class [Signal]NUM($1):public Signal_
82   {
83    public:
84      typedef __SLOT__(R,[$1])                       InSlotType;
85      typedef __SLOT__(typename Marsh::OutType,[$1]) OutSlotType;
86
87    private:
88 #ifdef SIGC_CXX_PARTIAL_SPEC
89      typedef typename Marsh::OutType SType;
90      typedef R RType;
91 #else
92      typedef Trait<typename Marsh::OutType>::type SType;
93      typedef Trait<R>::type RType;
94 #endif
95      typedef typename InSlotType::Callback Callback;
96      typedef [Signal]NUM($1)<LIST(R,1,ARG_TYPE($1),[$1],Marsh,1)> Self;
97      typedef CallDataObj2<typename OutSlotType::Func,Self> CallData;
98
99      static SType callback(LIST(void* d,1,ARG_BOTH($1),[$1]))
100        {
101         CallData* data=(CallData*)d;
102         return data->obj->emit(ARG_NAME($1));
103        }
104
105    public:
106      OutSlotType slot()
107        {
108         SlotData* tmp=in_connect();
109         CallData &data=reinterpret_cast<CallData&>(tmp->data_);
110         data.callback=(typename OutSlotType::Func)callback;
111         data.obj=this;
112         return tmp;
113        }
114
115      Connection connect(const InSlotType &s)
116        {
117         return out_connect(s.data());
118        }
119
120      SType emit(ARG_REF($1));
121      SType operator()(ARG_REF($1))
122        {return emit(ARG_NAME($1));}
123
124      [Signal]NUM($1)() {}
125      [Signal]NUM($1)(const InSlotType &s) {connect(s);}
126      ~[Signal]NUM($1)() {}
127   };
128
129
130 // emit
131 template <LIST(class R,1,ARG_CLASS($1),[$1],class Marsh,1)>
132 typename  [Signal]NUM($1)<LIST(R,1,ARG_TYPE($1),[$1],Marsh,1)>::SType [Signal]NUM($1)<LIST(R,1,ARG_TYPE($1),[$1],Marsh,1)>::
133   emit(ARG_REF($1))
134   {
135    if (!impl||impl->outgoing_.empty()) return Marsh::default_value();
136    List &out=impl->outgoing_; 
137    Marsh rc;
138    SlotData *data;
139    List::Iterator i=out.begin();
140    while (i!=out.end())
141      {
142       data=((SlotDependent*)(i.node()))->parent();
143       ++i;
144       Callback& s=(Callback&)(data->callback());
145       if (rc.marshal(s.call(ARG_NAME($1)))) return rc.value();
146      } 
147    return rc.value();
148   }
149
150 #ifdef SIGC_CXX_PARTIAL_SPEC
151 template <LIST(ARG_CLASS($1),[$1],[class Marsh],1)>
152 class [Signal]NUM($1)<LIST(void,1,ARG_TYPE($1),[$1],Marsh,1)>
153   :public Signal_
154   {
155    public:
156      typedef __SLOT__(void,[$1]) InSlotType;
157      typedef __SLOT__(void,[$1]) OutSlotType;
158    private:
159      typedef ifelse([$1],,,[typename ])InSlotType::Callback Callback;
160      typedef [Signal]NUM($1)<LIST(void,1,ARG_TYPE($1),[$1],Marsh,1)> Self;
161      typedef CallDataObj2<ifelse([$1],,,[typename ])OutSlotType::Func,Self> CallData;
162
163      static void callback(LIST(void* d,1,ARG_BOTH($1),[$1]))
164        {
165         CallData* data=(CallData*)d;
166         data->obj->emit(ARG_NAME($1));
167        }
168
169    public:
170      OutSlotType slot()
171        {
172         SlotData* tmp=in_connect();
173         CallData& data=reinterpret_cast<CallData&>(tmp->data_);
174         data.callback=callback;
175         data.obj=this;
176         return tmp;
177        }
178
179      Connection connect(const InSlotType &s)
180        {
181         return out_connect(s.data());
182        }
183
184      void emit(ARG_REF($1));
185      void operator()(ARG_REF($1))
186        {emit(ARG_NAME($1));}
187
188      [Signal]NUM($1)() {}
189      [Signal]NUM($1)(const InSlotType &s) {connect(s);}
190      ~[Signal]NUM($1)() {}
191   };
192
193
194 // emit
195 template <LIST(ARG_CLASS($1),[$1],class Marsh,1)>
196 void [Signal]NUM($1)<LIST(void,1,ARG_TYPE($1),[$1],Marsh,1)>::
197   emit(ARG_REF($1))
198   {
199    if (!impl||impl->outgoing_.empty()) return;
200    List &out=impl->outgoing_; 
201    SlotData *data;
202    List::Iterator i=out.begin();
203    while (i!=out.end())
204      {
205       data=((SlotDependent*)(i.node()))->parent();
206       ++i;
207       Callback& s=(Callback&)(data->callback());
208       s.call(ARG_NAME($1));
209      }
210   }
211
212 #endif
213
214 ])dnl
215
216 BASIC_SIGNAL(ARGS(P,0))
217 BASIC_SIGNAL(ARGS(P,1))
218 BASIC_SIGNAL(ARGS(P,2))
219 BASIC_SIGNAL(ARGS(P,3))
220
221 #ifdef SIGC_CXX_NAMESPACES
222 } // namespace
223 #endif
224
225 END_QT_FIREWALL
226
227 #endif // __header__
228