]> git.lyx.org Git - lyx.git/blob - sigc++/macros/bind.h.m4
more FILMagain stuff
[lyx.git] / sigc++ / macros / bind.h.m4
1 dnl 
2 dnl  Bind Slot Templates
3 dnl 
4 dnl  Copyright (C) 1998-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
27 /*
28   SigC::bind
29   -------------
30   bind() alters a Slot by fixing arguments to certain values.
31
32   Argument fixing starts from the last argument.  The slot is
33   destroyed in the process and a new one is created, so references
34   holding onto the slot will no longer be valid.
35
36   Up to two arguments can be bound at a time with the default
37   header.
38
39   Simple Sample usage:
40
41     void f(int,int);
42     Slot2<void,int,int> s1=slot(f);
43
44     Slot1<void,int>  s2=bind(s1,1);  // s1 is invalid
45     s2(2);  // call f with arguments 2,1 
46
47   Multibinding usage:
48
49     void f(int,int);
50     Slot2<void,int,int> s1=slot(f);
51  
52     Slot0<void>  s2=bind(s1,1,2);  // s1 is invalid
53     s2();  // call f with arguments 1,2 
54
55   Type specified usage:
56     
57     struct A {};
58     struct B :public A {};
59     B* b;
60     Slot0<void, A*> s1;
61
62     Slot0<void> s2=bind(s1, b);  // B* converted to A*
63      
64 */
65
66 #include <sigc++/adaptor.h>
67 #include <sigc++/scope.h>
68
69 #ifdef SIGC_CXX_NAMESPACES
70 namespace SigC
71 {
72 #endif
73
74 define([FORMAT_ARG_CBASSIGN],[node->LOWER([$1])_=LOWER([$1]);])
75 define([FORMAT_ARG_CBNAME],[node->LOWER([$1])_])
76 define([FORMAT_ARG_CBBIND],[[$1] LOWER([$1])_;])
77
78 define([ARG_CBASSIGN],[PROT(ARG_LOOP([FORMAT_ARG_CBASSIGN],[[
79       ]],$*))])
80 define([ARG_CBNAME],[PROT(ARG_LOOP([FORMAT_ARG_CBNAME],[[,]],$*))])
81 define([ARG_CBBIND],[PROT(ARG_LOOP([FORMAT_ARG_CBBIND],[[
82       ]],$*))])
83
84 dnl
85 dnl ADAPTOR_BIND_SLOT([P1..PN],[C0..CM],[A0..AM])
86 dnl
87 define([ADAPTOR_BIND_SLOT],[dnl
88 /****************************************************************
89 ***** Adaptor Bind Slot NUM($1) arguments, NUM($2) hidden arguments
90 ****************************************************************/
91 ADAPTOR_BIND_SLOT_IMPL(R,[$1],[$2])
92
93 #ifndef SIGC_CXX_VOID_RETURN
94 #ifdef SIGC_CXX_PARTIAL_SPEC
95 ADAPTOR_BIND_SLOT_IMPL(void,[$1],[$2])
96 #endif
97 #endif
98
99 template <LIST(ARG_CLASS($3),[$3],[
100     ]class R,1,[
101     ]ARG_CLASS($1),[$1],[
102     ]ARG_CLASS($2),[$2])>
103 inline
104 __SLOT__(R,[$1])
105   bind(const [Slot]eval(NUM($1)+NUM($2))<LIST(R,1,ARG_TYPE($1),[$1],ARG_TYPE($2),[$2])> &s,
106        ARG_BOTH($3))
107   {return [AdaptorBindSlot]NUM($1)[_]NUM($2)<LIST(R,1,[
108            ]ARG_TYPE($1),[$1],[
109            ]ARG_TYPE($2),[$2])>::create(s.data(),ARG_NAME($3));
110   }
111
112 ])dnl
113
114
115 dnl
116 dnl ADAPTOR_BIND_SLOT_IMPL(R,[P1..PN],[C0..CN])
117 dnl
118 define([ADAPTOR_BIND_SLOT_IMPL],[dnl
119 LINE(]__line__[)dnl
120 ifelse($1,void,[dnl
121 template <LIST(ARG_CLASS($2),[$2],[
122    ]ARG_CLASS($3),[$3])>
123 struct [AdaptorBindSlot]NUM($2)[_]NUM($3)
124    <LIST(void,1,ARG_TYPE($2),[$2],[
125     ]ARG_TYPE($3),[$3])> : public AdaptorSlot_
126 ],[dnl
127 template <LIST(class R,1,[
128    ]ARG_CLASS($2),[$2],[
129    ]ARG_CLASS($3),[$3])>
130 struct [AdaptorBindSlot]NUM($2)[_]NUM($3): public AdaptorSlot_
131 ])dnl
132   {TYPEDEF_RTYPE($1,RType)
133    typedef __SLOT__($1,[$2]) SlotType;
134    typedef __SLOT__($1,[$2],[$3]) InSlotType;
135
136    struct Node:public AdaptorNode
137      {
138       ARG_CBBIND($3)
139
140       Node(ARG_BOTH($3))
141         : ARG_CBINIT($3)
142         { }
143      };
144
145    typedef CallDataObj2<typename SlotType::Func,Node> CallData;
146
147    static RType callback(LIST(void* d,1,ARG_BOTH($2),[$2]))
148      {
149       CallData* data=(CallData*)d;
150       Node* node=data->obj;
151       ifelse($1,void,,return) ((typename InSlotType::Callback&)(node->data_))(LIST(ARG_NAME($2),[$2],[
152                                      ]ARG_CBNAME($3),[$3]));
153      }
154    static SlotData* create(SlotData *s,ARG_BOTH($3))
155      {
156       Node *node=new Node(ARG_NAME($3));
157       copy_callback(s,node);
158       CallData &data=reinterpret_cast<CallData&>(s->data_);
159       data.callback=&callback;
160       data.obj=node;
161       return s;
162      }
163   };
164 ])dnl
165
166 ADAPTOR_BIND_SLOT(ARGS(P,0),ARGS(C,1),ARGS(A,1))
167 ADAPTOR_BIND_SLOT(ARGS(P,1),ARGS(C,1),ARGS(A,1))
168 ADAPTOR_BIND_SLOT(ARGS(P,2),ARGS(C,1),ARGS(A,1))
169
170 ADAPTOR_BIND_SLOT(ARGS(P,0),ARGS(C,2),ARGS(A,2))
171 ADAPTOR_BIND_SLOT(ARGS(P,1),ARGS(C,2),ARGS(A,2))
172 ADAPTOR_BIND_SLOT(ARGS(P,2),ARGS(C,2),ARGS(A,2))
173
174 #ifdef SIGC_CXX_NAMESPACES
175 } // namespace
176 #endif
177
178 #endif