lo-macros.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2010-2012 VZLU Prague
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave 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 GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_liboctave_macros_h)
00024 #define octave_liboctave_macros_h 1
00025 
00026 // Core macros. Iteration is supported up to count 10.
00027 
00028 #define OCT_ITERATE_PARAM_MACRO0(MACRO, PARAM)
00029 #define OCT_ITERATE_PARAM_MACRO1(MACRO, PARAM) \
00030 MACRO(0, PARAM)
00031 #define OCT_ITERATE_PARAM_MACRO2(MACRO, PARAM) \
00032 MACRO(0, PARAM) MACRO(1, PARAM)
00033 #define OCT_ITERATE_PARAM_MACRO3(MACRO, PARAM) \
00034 MACRO(0, PARAM) MACRO(1, PARAM) MACRO(2, PARAM)
00035 #define OCT_ITERATE_PARAM_MACRO4(MACRO, PARAM) \
00036 MACRO(0, PARAM) MACRO(1, PARAM) MACRO(2, PARAM) MACRO(3, PARAM)
00037 #define OCT_ITERATE_PARAM_MACRO5(MACRO, PARAM) \
00038 MACRO(0, PARAM) MACRO(1, PARAM) MACRO(2, PARAM) MACRO(3, PARAM) MACRO(4, PARAM)
00039 #define OCT_ITERATE_PARAM_MACRO6(MACRO, PARAM) \
00040 OCT_ITERATE_PARAM_MACRO5(MACRO, PARAM) MACRO(5, PARAM)
00041 #define OCT_ITERATE_PARAM_MACRO7(MACRO, PARAM) \
00042 OCT_ITERATE_PARAM_MACRO5(MACRO, PARAM) MACRO(5, PARAM) MACRO(6, PARAM)
00043 #define OCT_ITERATE_PARAM_MACRO8(MACRO, PARAM) \
00044 OCT_ITERATE_PARAM_MACRO5(MACRO, PARAM) MACRO(5, PARAM) MACRO(6, PARAM) MACRO(7, PARAM)
00045 #define OCT_ITERATE_PARAM_MACRO9(MACRO, PARAM) \
00046 OCT_ITERATE_PARAM_MACRO8(MACRO, PARAM) MACRO(8, PARAM)
00047 #define OCT_ITERATE_PARAM_MACRO10(MACRO, PARAM) \
00048 OCT_ITERATE_PARAM_MACRO8(MACRO, PARAM) MACRO(8, PARAM) MACRO(9, PARAM)
00049 
00050 // expands to MACRO(0, PARAM) MACRO(1, PARAM) ... MACRO(NUM-1, PARAM)
00051 #define OCT_ITERATE_PARAM_MACRO(MACRO, PARAM, NUM) OCT_ITERATE_PARAM_MACRO##NUM(MACRO,PARAM)
00052 
00053 #define OCT_IF_PARAM0(MACRO, PARAM)
00054 #define OCT_IF_PARAM1(MACRO, PARAM) MACRO(PARAM)
00055 #define OCT_IF_PARAM2(MACRO, PARAM) MACRO(PARAM)
00056 #define OCT_IF_PARAM3(MACRO, PARAM) MACRO(PARAM)
00057 #define OCT_IF_PARAM4(MACRO, PARAM) MACRO(PARAM)
00058 #define OCT_IF_PARAM5(MACRO, PARAM) MACRO(PARAM)
00059 #define OCT_IF_PARAM6(MACRO, PARAM) MACRO(PARAM)
00060 #define OCT_IF_PARAM7(MACRO, PARAM) MACRO(PARAM)
00061 #define OCT_IF_PARAM8(MACRO, PARAM) MACRO(PARAM)
00062 #define OCT_IF_PARAM9(MACRO, PARAM) MACRO(PARAM)
00063 
00064 // expands to MACRO(PARAM) if NUM > 0
00065 #define OCT_IF_PARAM(NUM, MACRO, PARAM) OCT_IF_PARAM##NUM(MACRO, PARAM)
00066 
00067 // concatenation and reverse concat
00068 #define OCT_CONCAT2(ARG1, ARG2) ARG1 ## ARG2
00069 #define OCT_CONCAT2_REVERSE(ARG1, ARG2) ARG2 ## ARG1
00070 
00071 #define OCT_IF_HELPER(X) X
00072 
00073 // expands to X if NUM > 0
00074 #define OCT_IF(NUM, X) OCT_IF_PARAM(NUM, OCT_IF_HELPER, X)
00075 
00076 #define OCT_ITERATE_MACRO_HELPER(NUM, MACRO) MACRO(NUM)
00077 
00078 // expands to MACRO(0) ... MACRO(NUM-1)
00079 #define OCT_ITERATE_MACRO(MACRO, NUM) OCT_ITERATE_PARAM_MACRO(OCT_ITERATE_MACRO_HELPER, MACRO, NUM)
00080 
00081 #define OCT_MAKE_LIST_HELPER1(ARG) ARG,
00082 
00083 // expands to MACRO(0), MACRO(1), ..., MACRO(NUM-1)
00084 #define OCT_MAKE_LIST_HELPER(NUM, MACRO) OCT_IF_PARAM(NUM,OCT_MAKE_LIST_HELPER1,) MACRO(NUM)
00085 
00086 #define OCT_MAKE_LIST(MACRO, NUM) OCT_ITERATE_PARAM_MACRO(OCT_MAKE_LIST_HELPER, MACRO, NUM)
00087 
00088 #define OCT_MAKE_DECL_LIST_HELPER(NUM, PREFIX) \
00089   OCT_IF_PARAM(NUM,OCT_MAKE_LIST_HELPER1,) OCT_CONCAT2(PREFIX, NUM)
00090 
00091 // expands to TYPE PREFIX0, TYPE PREFIX1, ..., TYPE PREFIX ## (NUM-1)
00092 #define OCT_MAKE_DECL_LIST(TYPE, PREFIX, NUM) \
00093   OCT_ITERATE_PARAM_MACRO(OCT_MAKE_DECL_LIST_HELPER, TYPE PREFIX, NUM)
00094 
00095 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines