]> git.lyx.org Git - lyx.git/blob - sigc++/macros/convert.h.m4
visual support for \displaystyle
[lyx.git] / sigc++ / macros / convert.h.m4
1 dnl 
2 dnl  Convert 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::convert
29   -------------
30   convert() alters a Slot by assigning a conversion function 
31   which can completely alter the parameter types of a slot. 
32
33   Only convert functions for changing with same number of
34   arguments is compiled by default.  See examples/custom_convert.h.m4 
35   for details on how to build non standard ones.
36
37   Sample usage:
38     int my_string_to_char(Callback1<int,const char*> *d,const string &s)
39     int f(const char*);
40     string s=hello;
41
42
43     Slot1<int,const string &>  s2=convert(slot(f),my_string_to_char);
44     s2(s);  
45
46 */
47 #include <sigc++/adaptor.h>
48
49 #ifdef SIGC_CXX_NAMESPACES
50 namespace SigC
51 {
52 #endif
53
54 dnl
55 dnl ADAPTOR_CONVERT_SLOT([P1..PN],[C0..CN])
56 dnl
57 define([ADAPTOR_CONVERT_SLOT],[dnl
58 /****************************************************************
59 ***** Adaptor Convert Slot NUM($1)
60 ****************************************************************/
61 ADAPTOR_CONVERT_SLOT_IMPL(R1,[$1],[$2])
62
63 #ifndef SIGC_CXX_VOID_RETURN
64 #ifdef SIGC_CXX_PARTIAL_SPEC
65 ADAPTOR_CONVERT_SLOT_IMPL(void,[$1],[$2])
66 #endif
67 #endif
68
69 template <LIST(class R1,1,ARG_CLASS($1),[$1],[
70           class R2],1,ARG_CLASS($2),[$2])>
71 __SLOT__(R1,[$1])
72   convert(const __SLOT__(R2,[$2]) &s,
73           [R1 (*func)](LIST([Callback]NUM($2)PROT(<LIST(R2,1,ARG_TYPE($2),[$2])>)*,1,ARG_TYPE($1),[$1])))
74   {return [AdaptorConvertSlot]NUM($1)[_]NUM($2)<LIST(R1,1,ARG_TYPE($1),[$1],[
75            R2],1,ARG_TYPE($2),[$2])>::create(s.obj(),func);
76   }
77
78 ])dnl
79
80 dnl
81 dnl ADAPTOR_CONVERT_SLOT_IMPL(R,[P1..PN],[C0..CN])
82 dnl
83 define([ADAPTOR_CONVERT_SLOT_IMPL],[dnl
84 LINE(]__line__[)dnl
85 ifelse($1,void,[dnl
86 template <LIST(ARG_CLASS($2),[$2],[
87           class R2],1,ARG_CLASS($3),[$3])>
88 struct [AdaptorConvertSlot]NUM($2)[_]NUM($3)
89          <LIST(void,1,ARG_TYPE($2),[$2],[
90           R2],1,ARG_TYPE($3),[$3])>
91   : public AdaptorSlot_
92 ],[dnl
93 template <LIST(class $1,1,ARG_CLASS($2),[$2],[
94           class R2],1,ARG_CLASS($3),[$3])>
95 struct [AdaptorConvertSlot]NUM($2)[_]NUM($3): public AdaptorSlot_
96 ])dnl
97   {TYPEDEF_RTYPE($1,RType)
98    typedef __SLOT__($1,[$2]) SlotType;
99    typedef __SLOT__(R2,[$3]) InSlotType;
100    typedef typename InSlotType::Callback Callback;
101    typedef RType (*Func)  (LIST(Callback*,1,ARG_TYPE($2),[$2]));
102    typedef $1    (*InFunc)(LIST(Callback*,1,ARG_TYPE($2),[$2]));
103    typedef CallDataObj3<typename SlotType::Func,Callback,Func> CallData;
104
105    static RType callback(LIST(void* d,1,ARG_BOTH($2),[$2]))
106      {
107       CallData* data=(CallData*)d;
108       ifelse($1,void,,return) (data->func)(LIST(data->obj,1,ARG_NAME($2),[$2]));
109      }
110
111    static SlotData* create(SlotData *s,InFunc func)
112      {
113       SlotData* tmp=(SlotData*)s;
114       AdaptorNode *node=new AdaptorNode();
115       copy_callback(tmp,node);
116       CallData &data=reinterpret_cast<CallData&>(tmp->data_);
117       data.callback=&callback;
118       data.func=(Func)func;
119       data.obj=(Callback*)&(node->data_);
120       return tmp;
121      }
122   };
123
124 ])dnl
125
126 ADAPTOR_CONVERT_SLOT(ARGS(P,1),ARGS(Q,1))
127 ADAPTOR_CONVERT_SLOT(ARGS(P,2),ARGS(Q,2))
128 ADAPTOR_CONVERT_SLOT(ARGS(P,3),ARGS(Q,3))
129
130 #ifdef SIGC_CXX_NAMESPACES
131 } // namespace
132 #endif
133
134 #endif