]> git.lyx.org Git - lyx.git/blob - sigc++/macros/retbind.h.m4
move the most important changes from branch new_insets to head. Still dependant on...
[lyx.git] / sigc++ / macros / retbind.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  Copyright (C) 2000 Carl Nygard <cnygard@bellatlantic.net>
6 dnl 
7 dnl  This library is free software; you can redistribute it and/or
8 dnl  modify it under the terms of the GNU Library General Public
9 dnl  License as published by the Free Software Foundation; either
10 dnl  version 2 of the License, or (at your option) any later version.
11 dnl 
12 dnl  This library is distributed in the hope that it will be useful,
13 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 dnl  Library General Public License for more details.
16 dnl 
17 dnl  You should have received a copy of the GNU Library General Public
18 dnl  License along with this library; if not, write to the Free
19 dnl  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 dnl 
21 // -*- c++ -*-
22 dnl Ignore the next line
23 /* This is a generated file, do not edit.  Generated from __file__ */
24 /* This was also shamelessly copied, hacked, munched, and carefully 
25  * tweaked from KNelson's original bind.h.m4
26  * CJN 3.22.00
27  */
28 include(template.macros.m4)
29 #ifndef __header__
30 #define __header__
31
32 /*
33   SigC::retbind
34   -------------
35   retbind() alters a Slot by fixing the return value to certain values
36
37   Return value fixing ignores any slot return value.  The slot is
38   destroyed in the process and a new one is created, so references
39   holding onto the slot will no longer be valid.
40
41   Typecasting may be necessary to match arguments between the
42   slot and the binding return value.  Types must be an exact match.
43   To insure the proper type, the type can be explicitly specified
44   on template instantation.
45
46   Simple Sample usage:
47
48     void f(int,int);
49     Slot2<void,int,int> s1=slot(f);
50
51     Slot1<int,int,int>  s2=retbind(s1,1);  // s1 is invalid
52     cout << "s2: " << s2(2,1) << endl;
53
54   Type specified usage:
55     
56     struct A {};
57     struct B :public A {};
58     B* b;
59     Slot1<void> s1;
60
61     Slot0<A*> s2=retbind<A*>(s1,b);  // B* must be told to match A*
62      
63 */
64
65 #include <sigc++/adaptor.h>
66 #include <sigc++/scope.h>
67
68 #ifdef SIGC_CXX_NAMESPACES
69 namespace SigC
70 {
71 #endif
72
73 dnl
74 dnl ADAPTOR_RETBIND_SLOT([P1..PN])
75 dnl
76 define([ADAPTOR_RETBIND_SLOT],[dnl
77 /****************************************************************
78 ***** Adaptor RetBind Slot NUM($1) arguments
79 ****************************************************************/
80 ADAPTOR_RETBIND_SLOT_IMPL(R,[$1])
81
82 #ifndef SIGC_CXX_VOID_RETURN
83 #ifdef SIGC_CXX_PARTIAL_SPEC
84 ADAPTOR_RETBIND_SLOT_IMPL(void,[$1])
85 #endif
86 #endif
87
88 template <LIST(class Ret,1,[
89     ]class R,1,[
90     ]ARG_CLASS($1),[$1])>
91 __SLOT__(Ret,[$1])
92   retbind(const [Slot]NUM($1)<LIST(R,1,ARG_TYPE($1),[$1])> &s,
93        Ret ret)
94   {return [AdaptorRetBindSlot]NUM($1)<LIST(Ret,1,R,1,[
95            ]ARG_TYPE($1),[$1])>::create(s.data(),ret);
96   }
97
98 ])dnl
99
100
101 dnl
102 dnl ADAPTOR_RETBIND_SLOT_IMPL(R,[P1..PN])
103 dnl
104 define([ADAPTOR_RETBIND_SLOT_IMPL],[dnl
105 LINE(]__line__[)dnl
106 ifelse($1,void,[dnl
107 template <LIST(class Ret,1,ARG_CLASS($2),[$2])>
108 struct [AdaptorRetBindSlot]NUM($2)
109    <LIST(Ret,1,void,1,[
110    ]ARG_TYPE($2),[$2])> : public AdaptorSlot_
111 ],[dnl
112 template <LIST(class Ret,1,class $1,1,[
113    ]ARG_CLASS($2),[$2])>
114 struct [AdaptorRetBindSlot]NUM($2): public AdaptorSlot_
115 ])dnl
116   {TYPEDEF_RTYPE(Ret,RType)
117    typedef __SLOT__(Ret,[$2]) SlotType;
118    typedef __SLOT__($1,[$2]) InSlotType;
119
120    struct Node:public AdaptorNode
121      {
122            Ret ret_;
123      };
124
125    typedef CallDataObj2<typename SlotType::Func,Node> CallData;
126
127    static RType callback(LIST(void* d,1,ARG_BOTH($2),[$2]))
128      {
129       CallData* data=(CallData*)d;
130       Node* node=data->obj;
131       ((typename InSlotType::Callback&)(node->data_))(LIST(ARG_NAME($2),[$2]));
132       return node->ret_;
133      }
134    static SlotData* create(SlotData *s,Ret ret)
135      {
136       SlotData* tmp=(SlotData*)s;
137       Node *node=new Node();
138       copy_callback(tmp,node);
139       node->ret_ = ret;
140       CallData &data=reinterpret_cast<CallData&>(tmp->data_);
141       data.callback=&callback;
142       data.obj=node;
143       return tmp;
144      }
145   };
146 ])dnl
147
148 ADAPTOR_RETBIND_SLOT(ARGS(P,0))
149 ADAPTOR_RETBIND_SLOT(ARGS(P,1))
150 ADAPTOR_RETBIND_SLOT(ARGS(P,2))
151 ADAPTOR_RETBIND_SLOT(ARGS(P,3))
152
153 #ifdef SIGC_CXX_NAMESPACES
154 } // namespace
155 #endif
156
157 #endif