Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

macroOps.h

00001 /*****************************************************************************
00002  * Author:   Valient Gough <vgough@pobox.com>
00003  *
00004  *****************************************************************************
00005  * Copyright (c) 2001, Valient Gough
00006  *
00007  * This library is free software; you can distribute it and/or modify it under
00008  * the terms of the GNU Lesser General Public License (LGPL), as published by
00009  * the Free Software Foundation; either version 2.1 of the License, or (at your
00010  * option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE.  See the LGPL in the file COPYING for more
00015  * details.
00016  *
00017  */
00018                                                                                                 
00019 #ifndef _MacroOps_incl_
00020 #define _MacroOps_incl_
00021 
00022 
00023 /* Macro to expand a list of function calls with indexed arguments.
00024    For example, if you wanted:
00025 
00026        if( func(arg1) && func(arg2) && func(arg3) )
00027 
00028    That would be:
00029 
00030        if( FUNCALL_3(func,arg,&&) )
00031 */
00032 #define FUNCALL_1(FUN,A1,SEP)                           FUN ( A1##1 )
00033 #define FUNCALL_2(FUN,A1,SEP) FUNCALL_1(FUN,A1,SEP) SEP FUN ( A1##2 )
00034 #define FUNCALL_3(FUN,A1,SEP) FUNCALL_2(FUN,A1,SEP) SEP FUN ( A1##3 )
00035 #define FUNCALL_4(FUN,A1,SEP) FUNCALL_3(FUN,A1,SEP) SEP FUN ( A1##4 )
00036 #define FUNCALL_5(FUN,A1,SEP) FUNCALL_4(FUN,A1,SEP) SEP FUN ( A1##5 )
00037 #define FUNCALL_6(FUN,A1,SEP) FUNCALL_5(FUN,A1,SEP) SEP FUN ( A1##6 )
00038 #define FUNCALL_7(FUN,A1,SEP) FUNCALL_6(FUN,A1,SEP) SEP FUN ( A1##7 )
00039 #define FUNCALL_8(FUN,A1,SEP) FUNCALL_7(FUN,A1,SEP) SEP FUN ( A1##8 )
00040 #define FUNCALL_9(FUN,A1,SEP) FUNCALL_8(FUN,A1,SEP) SEP FUN ( A1##9 )
00041 
00042 
00043 /* Macro to build a chain expression with 2 indexed arguments.
00044 
00045    For example, to build:
00046 
00047       Type1 value1;
00048       Type2 value2;
00049       Type3 value3;
00050 
00051    That would be:
00052 
00053        CHAINBUILD2_3(Type,value,;)
00054 */
00055 #define CHAINBUILD2_1(A1,A2,POST)                           A1##1 A2##1 POST
00056 #define CHAINBUILD2_2(A1,A2,POST) CHAINBUILD2_1(A1,A2,POST) A1##2 A2##2 POST
00057 #define CHAINBUILD2_3(A1,A2,POST) CHAINBUILD2_2(A1,A2,POST) A1##3 A2##3 POST
00058 #define CHAINBUILD2_4(A1,A2,POST) CHAINBUILD2_3(A1,A2,POST) A1##4 A2##4 POST
00059 #define CHAINBUILD2_5(A1,A2,POST) CHAINBUILD2_4(A1,A2,POST) A1##5 A2##5 POST
00060 #define CHAINBUILD2_6(A1,A2,POST) CHAINBUILD2_5(A1,A2,POST) A1##6 A2##6 POST
00061 #define CHAINBUILD2_7(A1,A2,POST) CHAINBUILD2_6(A1,A2,POST) A1##7 A2##7 POST
00062 #define CHAINBUILD2_8(A1,A2,POST) CHAINBUILD2_7(A1,A2,POST) A1##8 A2##8 POST
00063 #define CHAINBUILD2_9(A1,A2,POST) CHAINBUILD2_8(A1,A2,POST) A1##9 A2##9 POST
00064 
00065 
00066 /* Macro to build a comma separated list of indexed values
00067 
00068    For example, to build:
00069 
00070       func( arg1, arg2, arg3, arg4 );
00071 
00072    That would be:
00073 
00074       func( LISTBUILD_4(,arg) );
00075 
00076 
00077    To build:
00078    
00079       void func( int a1, int a2, int a3);
00080 
00081    use:
00082    
00083       void func( LISTBUILD_3(int,a) );
00084 */
00085 #define LISTBUILD_1(PRE, ARG)                        PRE ARG##1
00086 #define LISTBUILD_2(PRE, ARG) LISTBUILD_1(PRE, ARG), PRE ARG##2
00087 #define LISTBUILD_3(PRE, ARG) LISTBUILD_2(PRE, ARG), PRE ARG##3
00088 #define LISTBUILD_4(PRE, ARG) LISTBUILD_3(PRE, ARG), PRE ARG##4
00089 #define LISTBUILD_5(PRE, ARG) LISTBUILD_4(PRE, ARG), PRE ARG##5
00090 #define LISTBUILD_6(PRE, ARG) LISTBUILD_5(PRE, ARG), PRE ARG##6
00091 #define LISTBUILD_7(PRE, ARG) LISTBUILD_6(PRE, ARG), PRE ARG##7
00092 #define LISTBUILD_8(PRE, ARG) LISTBUILD_7(PRE, ARG), PRE ARG##8
00093 #define LISTBUILD_9(PRE, ARG) LISTBUILD_8(PRE, ARG), PRE ARG##9
00094 
00095 
00096 #define FLISTBUILD_1(PR, AR, PO)                           PR AR##1 PO
00097 #define FLISTBUILD_2(PR, AR, PO) FLISTBUILD_1(PR, AR, PO), PR AR##2 PO
00098 #define FLISTBUILD_3(PR, AR, PO) FLISTBUILD_2(PR, AR, PO), PR AR##3 PO
00099 #define FLISTBUILD_4(PR, AR, PO) FLISTBUILD_3(PR, AR, PO), PR AR##4 PO
00100 #define FLISTBUILD_5(PR, AR, PO) FLISTBUILD_4(PR, AR, PO), PR AR##5 PO
00101 #define FLISTBUILD_6(PR, AR, PO) FLISTBUILD_5(PR, AR, PO), PR AR##6 PO
00102 #define FLISTBUILD_7(PR, AR, PO) FLISTBUILD_6(PR, AR, PO), PR AR##7 PO
00103 #define FLISTBUILD_8(PR, AR, PO) FLISTBUILD_7(PR, AR, PO), PR AR##8 PO
00104 #define FLISTBUILD_9(PR, AR, PO) FLISTBUILD_8(PR, AR, PO), PR AR##9 PO
00105 
00106 /* Macro to build a comma separated list with two indexed values.
00107 
00108    Same usage as LISTBUILD_* 
00109 */
00110 #define LISTBUILD2_1(PRE,ARGA,ARGB) \
00111     PRE ARGA##1 ARGB##1
00112 #define LISTBUILD2_2(PRE,ARGA,ARGB) LISTBUILD2_1(PRE,ARGA,ARGB), \
00113     PRE ARGA##2 ARGB##2
00114 #define LISTBUILD2_3(PRE,ARGA,ARGB) LISTBUILD2_2(PRE,ARGA,ARGB), \
00115     PRE ARGA##3 ARGB##3
00116 #define LISTBUILD2_4(PRE,ARGA,ARGB) LISTBUILD2_3(PRE,ARGA,ARGB), \
00117     PRE ARGA##4 ARGB##4
00118 #define LISTBUILD2_5(PRE,ARGA,ARGB) LISTBUILD2_4(PRE,ARGA,ARGB), \
00119     PRE ARGA##5 ARGB##5
00120 #define LISTBUILD2_6(PRE,ARGA,ARGB) LISTBUILD2_5(PRE,ARGA,ARGB), \
00121     PRE ARGA##6 ARGB##6
00122 #define LISTBUILD2_7(PRE,ARGA,ARGB) LISTBUILD2_6(PRE,ARGA,ARGB), \
00123     PRE ARGA##7 ARGB##7
00124 #define LISTBUILD2_8(PRE,ARGA,ARGB) LISTBUILD2_7(PRE,ARGA,ARGB), \
00125     PRE ARGA##8 ARGB##8
00126 #define LISTBUILD2_9(PRE,ARGA,ARGB) LISTBUILD2_8(PRE,ARGA,ARGB), \
00127     PRE ARGA##9 ARGB##9
00128 
00129 /*
00130     Operation output.
00131 */
00132 #define OPBUILD_1(STREAM, ARG, OP)                     STREAM OP ARG##1
00133 #define OPBUILD_2(STREAM, ARG, OP)  OPBUILD_1(STREAM,ARG, OP) OP ARG##2
00134 #define OPBUILD_3(STREAM, ARG, OP)  OPBUILD_2(STREAM,ARG, OP) OP ARG##3
00135 #define OPBUILD_4(STREAM, ARG, OP)  OPBUILD_3(STREAM,ARG, OP) OP ARG##4
00136 #define OPBUILD_5(STREAM, ARG, OP)  OPBUILD_4(STREAM,ARG, OP) OP ARG##5
00137 #define OPBUILD_6(STREAM, ARG, OP)  OPBUILD_5(STREAM,ARG, OP) OP ARG##6
00138 #define OPBUILD_7(STREAM, ARG, OP)  OPBUILD_6(STREAM,ARG, OP) OP ARG##7
00139 #define OPBUILD_8(STREAM, ARG, OP)  OPBUILD_7(STREAM,ARG, OP) OP ARG##8
00140 #define OPBUILD_9(STREAM, ARG, OP)  OPBUILD_8(STREAM,ARG, OP) OP ARG##9
00141 
00142 // create template specification with 'Arg' as argument base
00143 #define TEMPLATEDEF_N(N) template< LISTBUILD_##N(class, Arg) >
00144 // create template argument list, no 'class' specification
00145 #define TEMPLATEARGS_N(N) < LISTBUILD_##N(,Arg) >
00146 // create argument list, eg (a1,a2,a3,a4)
00147 #define ARGUSAGE_N(N) LISTBUILD_##N(,a)
00148 // create argument definition, eg (Arg1 a1, Arg2 a2, Arg3 a3)
00149 #define ARGDEF_N(N) LISTBUILD2_##N(,Arg,a)
00150 // define a set of variables, eg (Arg1 a1; Arg2 a2; Arg3 a3;)
00151 #define VARIABLEDEF_N(N,TYPE,NAME) CHAINBUILD2_##N(TYPE,NAME,;)
00152 
00153 // operation output
00154 #define OP_OUTPUT_N(N, STREAM, ARG) OPBUILD_##N(STREAM,ARG,<<)
00155 // operation input
00156 #define OP_INPUT_N(N, STREAM, ARG) OPBUILD_##N(STREAM,ARG,>>)
00157 
00158 
00159 #endif
00160 

Generated at Sat Sep 22 02:20:00 2001 for librel by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001