2 * Some ugly macros for XTL. Keep out!
4 * Copyright (C) 1998-2000 Jose' Orlando Pereira, jop@di.uminho.pt
6 /* XTL - eXternalization Template Library - http://gsd.di.uminho.pt/~jop/xtl
7 * Copyright (C) 1998-2000 Jose' Orlando Pereira, Universidade do Minho
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 * Id: macros.h 1.3 Fri, 05 May 2000 18:57:58 +0100 jop
30 // Extremely yucky pre-processor wizardry. Don't look. Just pretend it
33 #define tparam(i) class T##i
35 #define ci_param(i) T##i& val##i
36 #define co_param(i) const T##i& val##i
37 #define c_case(i) case i:\
41 #define o_param(i) T##i* tag##i
42 #define o_case(i) case i:\
46 #define o_elseif(i) else if (typeid(*ptr)==typeid(T##i)) { \
52 #define tparam_2 tparam(0), tparam(1)
53 #define tparam_3 tparam_2, tparam(2)
54 #define tparam_4 tparam_3, tparam(3)
55 #define tparam_5 tparam_4, tparam(4)
57 #define X_tparam(i) tparam_##i
59 #define ci_param_2 ci_param(0), ci_param(1)
60 #define ci_param_3 ci_param_2, ci_param(2)
61 #define ci_param_4 ci_param_3, ci_param(3)
62 #define ci_param_5 ci_param_4, ci_param(4)
64 #define X_ci_param(i) ci_param_##i
66 #define co_param_2 co_param(0), co_param(1)
67 #define co_param_3 co_param_2, co_param(2)
68 #define co_param_4 co_param_3, co_param(3)
69 #define co_param_5 co_param_4, co_param(4)
71 #define X_co_param(i) co_param_##i
73 #define c_case_2 c_case(0) c_case(1)
74 #define c_case_3 c_case_2 c_case(2)
75 #define c_case_4 c_case_3 c_case(3)
76 #define c_case_5 c_case_4 c_case(4)
78 #define X_c_case(i) c_case_##i
80 #define o_param_2 o_param(0), o_param(1)
81 #define o_param_3 o_param_2, o_param(2)
82 #define o_param_4 o_param_3, o_param(3)
83 #define o_param_5 o_param_4, o_param(4)
85 #define X_o_param(i) o_param_##i
87 #define o_case_2 o_case(0) o_case(1)
88 #define o_case_3 o_case_2 o_case(2)
89 #define o_case_4 o_case_3 o_case(3)
90 #define o_case_5 o_case_4 o_case(4)
92 #define X_o_case(i) o_case_##i
94 #define o_elseif_2 o_elseif(1)
95 #define o_elseif_3 o_elseif_2 o_elseif(2)
96 #define o_elseif_4 o_elseif_3 o_elseif(3)
97 #define o_elseif_5 o_elseif_4 o_elseif(4)
99 #define X_o_elseif(i) o_elseif_##i
101 #define decl_ich_method(i) \
102 template <class Discr, X_tparam(i)> \
103 inline obj_input& choices(Discr& discr, X_ci_param(i)) { \
108 throw std::range_error("XTL invalid choice"); \
113 #define decl_och_method(i) \
114 template <class Discr, X_tparam(i)> \
115 inline obj_output& choices(const Discr& discr, X_co_param(i)) { \
120 throw std::range_error("XTL invalid choice"); \
125 #define decl_iobj_method(i) \
126 template <class Base, X_tparam(i)> \
127 inline obj_input& object(Base*& ptr, X_o_param(i)) { \
133 throw std::range_error("XTL invalid choice"); \
138 #define decl_oobj_method(i) \
139 template <class Base, X_tparam(i)> \
140 inline obj_output& object(Base*& ptr, X_o_param(i)) { \
141 if (typeid(*ptr)==typeid(T0)) { \
147 throw std::range_error("XTL invalid choice"); \