]> git.lyx.org Git - lyx.git/blob - src/xtl/macros.h
more FILMagain stuff
[lyx.git] / src / xtl / macros.h
1 /*
2  * Some ugly macros for XTL. Keep out!
3  *
4  * Copyright (C) 1998-2000 Jose' Orlando Pereira, jop@di.uminho.pt
5  */
6 /* XTL - eXternalization Template Library - http://gsd.di.uminho.pt/~jop/xtl
7  * Copyright (C) 1998-2000 Jose' Orlando Pereira, Universidade do Minho
8  *
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.
13  * 
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.
18  * 
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,
22  * MA 02111-1307, USA
23  *
24  * Id: macros.h 1.3 Fri, 05 May 2000 18:57:58 +0100 jop 
25  */
26
27 #ifndef __XTL_MACROS
28 #define __XTL_MACROS
29
30 // Extremely yucky pre-processor wizardry. Don't look. Just pretend it
31 // is not here. :-)
32
33 #define tparam(i) class T##i
34
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:\
38                         simple(val##i);\
39                         break;
40
41 #define o_param(i) T##i* tag##i
42 #define o_case(i) case i:\
43                         reference(tag##i);\
44                         ptr=(Base*)tag##i;\
45                         break;
46 #define o_elseif(i) else if (typeid(*ptr)==typeid(T##i)) { \
47                         simple(i); \
48                         tag##i=(T##i*)ptr; \
49                         reference(tag##i); \
50                 }
51
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)
56
57 #define X_tparam(i) tparam_##i
58
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)
63
64 #define X_ci_param(i) ci_param_##i
65
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)
70
71 #define X_co_param(i) co_param_##i
72
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)
77
78 #define X_c_case(i) c_case_##i
79
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)
84
85 #define X_o_param(i) o_param_##i
86
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)
91
92 #define X_o_case(i) o_case_##i
93
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)
98
99 #define X_o_elseif(i) o_elseif_##i
100
101 #define decl_ich_method(i) \
102         template <class Discr, X_tparam(i)> \
103         inline obj_input& choices(Discr& discr, X_ci_param(i)) { \
104                 simple(discr); \
105                 switch(discr) { \
106                         X_c_case(i) \
107                  default: \
108                         throw std::range_error("XTL invalid choice"); \
109                 }; \
110                 return *this; \
111         }
112
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)) { \
116                 simple(discr); \
117                 switch(discr) { \
118                         X_c_case(i) \
119                  default: \
120                         throw std::range_error("XTL invalid choice"); \
121                 }; \
122                 return *this; \
123         }
124
125 #define decl_iobj_method(i) \
126         template <class Base, X_tparam(i)> \
127         inline obj_input& object(Base*& ptr, X_o_param(i)) { \
128                 int discr; \
129                 simple(discr); \
130                 switch(discr) { \
131                         X_o_case(i) \
132                  default: \
133                         throw std::range_error("XTL invalid choice"); \
134                 }; \
135                 return *this; \
136         }
137
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)) { \
142                         simple(0); \
143                         tag0=(T0*)ptr; \
144                         reference(tag0); \
145                 } X_o_elseif(i) \
146                 else \
147                         throw std::range_error("XTL invalid choice"); \
148                 return *this; \
149         } 
150
151 #endif