]> git.lyx.org Git - lyx.git/blob - sigc++/macros/template.macros.m4
visual support for \displaystyle
[lyx.git] / sigc++ / macros / template.macros.m4
1 dnl-----------------------------------------------------------------------
2 dnl 
3 dnl Karls M4 macros for the signal system used by gtk--
4 dnl 
5 dnl  Copyright (C) 1998 Karl Nelson <kenelson@ece.ucdavis.edu>
6 dnl                     Tero Pulkkinen
7 dnl 
8 dnl  Currently maintained by Tero Pulkkinen. <terop@modeemi.cs.tut.fi>
9 dnl                                                         
10 dnl  This library is free software; you can redistribute it and/or
11 dnl  modify it under the terms of the GNU Library General Public
12 dnl  License as published by the Free Software Foundation; either
13 dnl  version 2 of the License, or (at your option) any later version.
14 dnl 
15 dnl  This library is distributed in the hope that it will be useful,
16 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 dnl  Library General Public License for more details.
19 dnl 
20 dnl  You should have received a copy of the GNU Library General Public
21 dnl  License along with this library; if not, write to the Free
22 dnl  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 dnl 
24 dnl-----------------------------------------------------------------------
25 dnl  Recursion prevention.  (Don't attempt to understand why this works!) 
26 changequote(, )dnl
27 changequote([, ])dnl
28 pushdef([DIVERSION],divnum)dnl
29 divert(-1)dnl
30
31 ifdef([__template_macros__],[],[
32 define(__template_macros__)
33 dnl-----------------------------------------------------------------------
34
35
36 dnl
37 dnl  M4 macros for general sanity 
38 dnl
39
40 dnl  M4 Quotas are hard to work with, so use braces like autoconf
41 dnl    (which are matched by vi, emacs)
42 changequote(, )
43 changequote([, ])
44
45 dnl
46 dnl  M4 comments conflict with compiler directives
47 changecom(, )
48
49 dnl  BRACE(text) => [text]
50 dnl    When we want something to appear with braces 
51 define([BRACE],[[[$*]]])
52
53 dnl
54 dnl  PROT(macro)
55 dnl    If a macro generates an output with commas we need to protect it
56 dnl    from being broken down and interpreted
57 define([PROT],[[$*]])
58
59 dnl
60 dnl  LOWER(string)
61 dnl    lowercase a string
62 define([LOWER],[translit([$*],[ABCDEFGHIJKLMNOPQRSTUVWXYZ],[abcdefghijklmnopqrstuvwxyz])])
63
64 dnl
65 dnl  UPPER(string)
66 dnl    uppercase a string
67 define([UPPER],[translit([$*],[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
68 define([UPPER_SAFE],[translit([$*],[abcdefghijklmnopqrstuvwxyz.-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ__])])
69
70 dnl
71 dnl  BASENAME(string)
72 dnl    extract the basename of a string
73 define([BASENAME],[patsubst([$*],[^.*/],[])])
74
75 dnl
76 dnl  M4NAME(string)
77 dnl    extract the basename of a string
78 define([M4NAME],[patsubst(BASENAME([$*]),[\.m4$],[])])
79
80 dnl  NUM(arg,arg,...)
81 dnl    M4 defines $# very badly (empty list=1).  So we need a better one
82 define([NUM],[ifelse(len([$*]),0,0,[$#])])
83
84 dnl
85 dnl  IF(cond,string1,string2)
86 dnl    places string1 if length (without spaces) of cond is zero,
87 dnl    else string2
88 define([IF],[ifelse(len(PROT(translit([$1],[ ]))),0,[$3],[$2])])
89 dnl define([IF],[ifelse(len(PROT(patsubst([$1],[ ]))),0,[$3],[$2])])
90
91 dnl
92 dnl minclude(filename)
93 dnl   This includes only the macros from a file but throws away the output.
94 dnl   Used to take the macros from a file without getting it extra output.
95 define([minclude],[IF([$1],[dnl
96 pushdef([CURRENT_DIVERSION],divnum)dnl
97 divert(-1)
98 include($1)
99 divert(CURRENT_DIVERSION)dnl
100 popdef([CURRENT_DIVERSION])dnl],[[minclude]])])
101
102 dnl
103 dnl    makes the current filename into a string approprate for use as 
104 dnl    C identified define.  (Defaults to this library name)
105 dnl
106 dnl    example:  (filename test.hh.m4) 
107 dnl      __header__          => SIGCXX_TEST_H 
108 dnl      __header__(MYHEAD)  => MYHEAD_TEST_H 
109 dnl define([__header__],[ifelse($1,,[SIGCXX],UPPER($1))[_]UPPER(patsubst(translit(BASENAME(__file__),[.-],[__]),[_m4],[]))])
110 define([__header__],[ifelse($1,,[SIGCXX],UPPER($1))[_]UPPER_SAFE(M4NAME(__file__))])
111
112 dnl
113 dnl Set of M4 macros for variable argument template building
114 dnl
115
116 dnl ARGS(name,number)
117 dnl  Builds a comma seperated protected list of numbered names  
118 dnl  Use this as short hand to specify arguement names
119 dnl
120 dnl  ARGS(arg,3)  => ARG1,ARG2,ARG3
121 define([_ARGS],[ifelse(eval($2<$3),0,[$1$2],[$1$2,_ARGS($1,eval($2+1),$3)])])
122 define([ARGS],[ifelse(eval($2>0),1,[PROT(_ARGS(UPPER([$1]),1,$2))],[PROT])])
123
124 dnl
125 dnl LIST/C_LIST(string1,cond1,string2,cond2,...)
126 dnl   These are intended for making extended argument lists
127 dnl   parameters are in pairs,  the first is output if the 
128 dnl   2nd is nonzero length,  the process is then repeated 
129 dnl   with the next set of arguments.
130 dnl
131 dnl   Macro expansions that expand to result in commas must call
132 dnl   PROT to prevent permature expansion.  ARG* macros do
133 dnl   this automatically.  (If unsure, add braces until it stops
134 dnl   interpreting inter macros, remove one set of braces, if
135 dnl   still not right use PROT)
136 dnl 
137 dnl   C_LIST adds a comma in front
138 dnl   (LIST is probably the most useful macro in the set.)
139 define([LIST],[ifelse($#,1,,len([$2]),0,[LIST(shift(shift($@)))],len([$1]),0,[LIST(shift(shift($@)))],[[$1]C_LIST(shift(shift($@)))])])
140 dnl
141 define([C_LIST],[ifelse($#,1,,len([$2]),0,[C_LIST(shift(shift($@)))],len([$1]),0,[C_LIST(shift(shift($@)))],[,[$1]C_LIST(shift(shift($@)))])])
142
143 dnl
144 dnl ARG_LOOP(macro_name,seperator,argument_list)
145 dnl   Very powerful macro for construction of list of variables
146 dnl   formated in specify ways.  To use define a macro taking
147 dnl   one variable which is called the format.  The second argument
148 dnl   is a seperator which will appear between each argument.
149 dnl   The rest is then interpreted as arguments to form the list.
150 dnl
151 dnl   Example:
152 dnl     define([FOO],[foo([$1])])
153 dnl     ARG_LOOP([FOO],[[, ]],A,B,C)
154 dnl
155 dnl     Gives:  foo(A), foo(B), foo(C)
156 dnl 
157 define([_ARG_LOOP],[dnl
158 ifelse(NUM($*),0,,NUM($*),1,[dnl
159 indir(LOOP_FORMAT,[$1])],[dnl
160 indir(LOOP_FORMAT,[$1])[]LOOP_SEPERATOR[]_ARG_LOOP(shift($*))])])
161
162 define([ARG_LOOP],[dnl
163 pushdef([LOOP_FORMAT],[[$1]])dnl
164 pushdef([LOOP_SEPERATOR],[$2])dnl
165 _ARG_LOOP(shift(shift($*)))[]dnl
166 popdef([LOOP_FORMAT])dnl
167 popdef([LOOP_SEPERATOR])dnl
168 ])
169
170
171 dnl 
172 dnl  Define some useful formats for use with ARG_LOOP.
173 define([FORMAT_ARG_CLASS],[class [$1]])
174 define([FORMAT_ARG_BOTH],[[$1] LOWER([$1])])
175 define([FORMAT_ARG_REF],[typename Trait<[$1]>::ref LOWER([$1])])
176 define([FORMAT_ARG_TYPE],[[$1]])
177 define([FORMAT_ARG_NAME],[LOWER($1)])
178 define([FORMAT_ARG_CBNAME],[LOWER($1)_])
179 define([FORMAT_ARG_CBDECL],[[$1] LOWER([$1])_;])
180 define([FORMAT_ARG_CBINIT],[LOWER([$1])_(LOWER([$1]))])
181
182
183 dnl
184 dnl  The following functions generate various types of parameter lists
185 dnl    For parameter lists
186 dnl      ARG_CLASS([P1,P2]) ->  class P1,class P2
187 dnl      ARG_BOTH([P1,P2])  ->  P1 p1,P2 p2
188 dnl      ARG_TYPE([P1,P2])  ->  P1,P2
189 dnl      ARG_NAME([P1,P2])  ->  p1,p2
190 dnl    For callback lists
191 dnl      ARG_CBNAME([C1,C2]) ->  c1_,c2_
192 dnl      ARG_CBINIT([C1,C2]) ->  c1_(c1),c2_(c2)
193 dnl      ARG_CBDECL([C1,C2]) ->  C1 c1_; C2 c2_;
194 dnl
195 define([ARG_CLASS],[PROT(ARG_LOOP([FORMAT_ARG_CLASS],[[,]],$*))])
196 define([ARG_BOTH],[PROT(ARG_LOOP([FORMAT_ARG_BOTH],[[,]],$*))])
197 define([ARG_REF],[PROT(ARG_LOOP([FORMAT_ARG_REF],[[,]],$*))])
198 define([ARG_TYPE],[PROT([$*])])
199 define([ARG_NAME],[PROT(LOWER($*))])
200 define([ARG_CBNAME],[PROT(ARG_LOOP([FORMAT_ARG_CBNAME],[[,]],$*))])
201 define([ARG_CBDECL],[PROT(ARG_LOOP([FORMAT_ARG_CBDECL],[ ],$*))])
202 define([ARG_CBINIT],[PROT(ARG_LOOP([FORMAT_ARG_CBINIT],[[,]],$*))])
203
204
205 dnl
206 dnl  C_* - the same with a comma in front  
207 dnl     (we should obsolete these, LIST is better)
208 define([C_ARG_CLASS], [ifelse(NUM($*),0,,[,ARG_CLASS($*)])])
209 define([C_ARG_BOTH],[ifelse(NUM($*),0,,[,ARG_BOTH($*)])])
210 define([C_ARG_TYPE],[ifelse(NUM($*),0,,[,ARG_TYPE($*)])])
211 define([C_ARG_NAME],[ifelse(NUM($*),0,,[,ARG_NAME($*)])])
212 define([C_ARG_CBNAME],[ifelse(NUM($*),0,,[,ARG_CNAME($*)])])
213 define([C_ARG_CBINIT],[ifelse(NUM($*),0,,[,ARG_INIT($*)])])
214
215 dnl
216 dnl T_DROP(string)
217 dnl   Removes unnecessary <> with empty templates
218 dnl   (occasionally useful)
219 define([T_DROP],[ifelse([$1],<>,,[$*])])
220
221 dnl
222 dnl DROP(string,drop)
223 dnl   Removes unnecessary strings if they match drop
224 dnl   (occasionally useful)
225 define([DROP],[ifelse([$1],[$2],,[$*])])
226
227 dnl
228 dnl LINE(linenum) 
229 dnl   places a #line statement if __debug__ set
230 dnl   Use this at top of macro template and following 
231 dnl   macros that contain newlines.
232 dnl
233 dnl   example:  
234 dnl      LINE(]__line__[)dnl
235 define([LINE],[ifdef([__debug__],[#line $1 "]__file__["
236 ])])
237
238 dnl-----------------------------------------------------------------------
239
240 dnl Libsigc++ macros to simpilify typing of internal macros
241
242 define([TYPEDEF_RTYPE],[
243 ifelse($1,void,[dnl
244    typedef void $2;dnl
245 ],[dnl
246 #ifdef SIGC_CXX_PARTIAL_SPEC
247    typedef $1 $2;
248 #else
249    typedef typename Trait<$1>::type $2;
250 #endif])])
251
252 define([__SLOT__],[dnl
253 ifelse([$2$3],,[Slot0<$1>],
254 [$3],,[Slot[]NUM($2)<$1,$2>],
255 [$2],,[Slot[]NUM($3)<$1,$3>],
256 [Slot[]eval(NUM($2)+NUM($3))<$1,$2,$3>])])
257
258 define([QT_FIREWALL],[dnl
259 // Qt steals a method name.
260 #ifdef SIGC_QT
261 #undef emit
262 #endif
263
264 #ifdef emit
265 #define SIGC_QT
266 #undef emit
267 #endif
268
269 ])
270
271 define([END_QT_FIREWALL],[dnl
272 #ifdef SIGC_QT
273 #define emit
274 #endif
275 ])
276
277
278 dnl-----------------------------------------------------------------------
279 dnl End of recursion protection.  Do not put anything below this line.
280 ])
281 divert(DIVERSION)dnl
282 popdef([DIVERSION])dnl