GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MArray-decl.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_MArray_decl_h)
24 #define octave_MArray_decl_h 1
25 
26 // A macro that can be used to declare and instantiate OP= operators.
27 #define MARRAY_OP_ASSIGN_DECL(A_T, E_T, OP, PFX, API, LTGT, RHS_T) \
28  PFX API A_T<E_T>& \
29  operator OP LTGT (A_T<E_T>&, const RHS_T&)
30 
31 #define MARRAY_OP_ASSIGN_DECLX(A_T, E_T, OP, PFX, API, LTGT, RHS_T) \
32  PFX API A_T<E_T>& \
33  OP LTGT (A_T<E_T>&, const RHS_T&)
34 
35 // All the OP= operators that we care about.
36 #define MARRAY_OP_ASSIGN_DECLS(A_T, E_T, PFX, API, LTGT, RHS_T) \
37  MARRAY_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, API, LTGT, RHS_T); \
38  MARRAY_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, API, LTGT, RHS_T); \
39  MARRAY_OP_ASSIGN_DECLX (A_T, E_T, product_eq, PFX, API, LTGT, RHS_T); \
40  MARRAY_OP_ASSIGN_DECLX (A_T, E_T, quotient_eq, PFX, API, LTGT, RHS_T);
41 
42 #define MARRAY_OP_ASSIGN_DECLS1(A_T, E_T, PFX, API, LTGT, RHS_T) \
43  MARRAY_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, API, LTGT, RHS_T); \
44  MARRAY_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, API, LTGT, RHS_T); \
45  MARRAY_OP_ASSIGN_DECL (A_T, E_T, *=, PFX, API, LTGT, RHS_T); \
46  MARRAY_OP_ASSIGN_DECL (A_T, E_T, /=, PFX, API, LTGT, RHS_T);
47 
48 // Generate forward declarations for OP= operators.
49 #define MARRAY_OP_ASSIGN_FWD_DECLS(A_T, RHS_T, API) \
50  MARRAY_OP_ASSIGN_DECLS (A_T, T, template <typename T>, API, , RHS_T)
51 
52 #define MARRAY_OP_ASSIGN_FWD_DECLS1(A_T, RHS_T, API) \
53  MARRAY_OP_ASSIGN_DECLS1 (A_T, T, template <typename T>, API, , RHS_T)
54 
55 // Generate friend declarations for the OP= operators.
56 #define MARRAY_OP_ASSIGN_FRIENDS(A_T, RHS_T, API) \
57  MARRAY_OP_ASSIGN_DECLS (A_T, T, friend, API, <>, RHS_T)
58 
59 #define MARRAY_OP_ASSIGN_FRIENDS1(A_T, RHS_T, API) \
60  MARRAY_OP_ASSIGN_DECLS1 (A_T, T, friend, API, <>, RHS_T)
61 
62 // A function that can be used to forward OP= operations from derived
63 // classes back to us.
64 #define MARRAY_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
65  inline R \
66  F (X_T& x, const Y_T& y) \
67  { \
68  return R (F (C_X (x), C_Y (y))); \
69  }
70 
71 // All the OP= operators that we care about forwarding.
72 #define MARRAY_OP_ASSIGN_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
73  MARRAY_OP_ASSIGN_FWD_FCN (R, operator +=, T, C_X, X_T, C_Y, Y_T) \
74  MARRAY_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T) \
75  MARRAY_OP_ASSIGN_FWD_FCN (R, product_eq, T, C_X, X_T, C_Y, Y_T) \
76  MARRAY_OP_ASSIGN_FWD_FCN (R, quotient_eq, T, C_X, X_T, C_Y, Y_T)
77 
78 #define MARRAY_OP_ASSIGN_FWD_DEFS1(R, T, C_X, X_T, C_Y, Y_T) \
79  MARRAY_OP_ASSIGN_FWD_FCN (R, operator +=, T, C_X, X_T, C_Y, Y_T) \
80  MARRAY_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T) \
81  MARRAY_OP_ASSIGN_FWD_FCN (R, operator *=, T, C_X, X_T, C_Y, Y_T) \
82  MARRAY_OP_ASSIGN_FWD_FCN (R, operator /=, T, C_X, X_T, C_Y, Y_T)
83 
84 // A macro that can be used to declare and instantiate unary operators.
85 #define MARRAY_UNOP(A_T, E_T, F, PFX, API, LTGT) \
86  PFX API A_T<E_T> \
87  F LTGT (const A_T<E_T>&)
88 
89 // All the unary operators that we care about.
90 #define MARRAY_UNOP_DECLS(A_T, E_T, PFX, API, LTGT) \
91  MARRAY_UNOP (A_T, E_T, operator +, PFX, API, LTGT); \
92  MARRAY_UNOP (A_T, E_T, operator -, PFX, API, LTGT);
93 
94 // Generate forward declarations for unary operators.
95 #define MARRAY_UNOP_FWD_DECLS(A_T, API) \
96  MARRAY_UNOP_DECLS (A_T, T, template <typename T>, API, )
97 
98 // Generate friend declarations for the unary operators.
99 #define MARRAY_UNOP_FRIENDS(A_T, API) \
100  MARRAY_UNOP_DECLS (A_T, T, friend, API, <>)
101 
102 // A function that can be used to forward unary operations from derived
103 // classes back to us.
104 #define MARRAY_UNOP_FWD_FCN(R, F, T, C_X, X_T) \
105  inline R \
106  F (const X_T& x) \
107  { \
108  return R (F (C_X (x))); \
109  }
110 
111 // All the unary operators that we care about forwarding.
112 #define MARRAY_UNOP_FWD_DEFS(R, T, C_X, X_T) \
113  MARRAY_UNOP_FWD_FCN (R, operator +, T, C_X, X_T) \
114  MARRAY_UNOP_FWD_FCN (R, operator -, T, C_X, X_T)
115 
116 // A macro that can be used to declare and instantiate binary operators.
117 #define MARRAY_BINOP_DECL(A_T, E_T, F, PFX, API, LTGT, X_T, Y_T) \
118  PFX API A_T<E_T> \
119  F LTGT (const X_T&, const Y_T&)
120 
121 // All the binary operators that we care about. We have two
122 // sets of macros since the MArray OP MArray operations use functions
123 // (product and quotient) instead of operators (*, /).
124 #define MARRAY_BINOP_DECLS(A_T, E_T, PFX, API, LTGT, X_T, Y_T) \
125  MARRAY_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, X_T, Y_T); \
126  MARRAY_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, X_T, Y_T); \
127  MARRAY_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T); \
128  MARRAY_BINOP_DECL (A_T, E_T, operator /, PFX, API, LTGT, X_T, Y_T);
129 
130 #define MARRAY_AA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT) \
131  MARRAY_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
132  MARRAY_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
133  MARRAY_BINOP_DECL (A_T, E_T, quotient, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
134  MARRAY_BINOP_DECL (A_T, E_T, product, PFX, API, LTGT, A_T<E_T>, A_T<E_T>);
135 
136 #define MDIAGARRAY2_DAS_BINOP_DECLS(A_T, E_T, PFX, API, LTGT, X_T, Y_T) \
137  MARRAY_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T); \
138  MARRAY_BINOP_DECL (A_T, E_T, operator /, PFX, API, LTGT, X_T, Y_T);
139 
140 #define MDIAGARRAY2_SDA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT, X_T, Y_T) \
141  MARRAY_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T);
142 
143 #define MDIAGARRAY2_DADA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT) \
144  MARRAY_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
145  MARRAY_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
146  MARRAY_BINOP_DECL (A_T, E_T, product, PFX, API, LTGT, A_T<E_T>, A_T<E_T>);
147 
148 // Generate forward declarations for binary operators.
149 #define MARRAY_BINOP_FWD_DECLS(A_T, API) \
150  MARRAY_BINOP_DECLS (A_T, T, template <typename T>, API, , A_T<T>, T) \
151  MARRAY_BINOP_DECLS (A_T, T, template <typename T>, API, , T, A_T<T>) \
152  MARRAY_AA_BINOP_DECLS (A_T, T, template <typename T>, API, )
153 
154 #define MDIAGARRAY2_BINOP_FWD_DECLS(A_T, API) \
155  MDIAGARRAY2_DAS_BINOP_DECLS (A_T, T, template <typename T>, API, , A_T<T>, T) \
156  MDIAGARRAY2_SDA_BINOP_DECLS (A_T, T, template <typename T>, API, , T, A_T<T>) \
157  MDIAGARRAY2_DADA_BINOP_DECLS (A_T, T, template <typename T>, API, )
158 
159 // Generate friend declarations for the binary operators.
160 #define MARRAY_BINOP_FRIENDS(A_T, API) \
161  MARRAY_BINOP_DECLS (A_T, T, friend, API, <>, A_T<T>, T) \
162  MARRAY_BINOP_DECLS (A_T, T, friend, API, <>, T, A_T<T>) \
163  MARRAY_AA_BINOP_DECLS (A_T, T, friend, API, <>)
164 
165 #define MDIAGARRAY2_BINOP_FRIENDS(A_T, API) \
166  MDIAGARRAY2_DAS_BINOP_DECLS (A_T, T, friend, API, <>, A_T<T>, T) \
167  MDIAGARRAY2_SDA_BINOP_DECLS (A_T, T, friend, API, <>, T, A_T<T>) \
168  MDIAGARRAY2_DADA_BINOP_DECLS (A_T, T, friend, API, <>)
169 
170 // A function that can be used to forward binary operations from derived
171 // classes back to us.
172 #define MARRAY_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
173  inline R \
174  F (const X_T& x, const Y_T& y) \
175  { \
176  return R (F (C_X (x), C_Y (y))); \
177  }
178 
179 // The binary operators that we care about forwarding. We have two
180 // sets of macros since the MArray OP MArray operations use functions
181 // (product and quotient) instead of operators (*, /).
182 #define MARRAY_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
183  MARRAY_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \
184  MARRAY_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \
185  MARRAY_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T) \
186  MARRAY_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T)
187 
188 #define MARRAY_AA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
189  MARRAY_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \
190  MARRAY_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \
191  MARRAY_BINOP_FWD_FCN (R, product, T, C_X, X_T, C_Y, Y_T) \
192  MARRAY_BINOP_FWD_FCN (R, quotient, T, C_X, X_T, C_Y, Y_T)
193 
194 #define MDIAGARRAY2_DAS_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
195  MARRAY_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T) \
196  MARRAY_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T)
197 
198 #define MDIAGARRAY2_SDA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
199  MARRAY_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T)
200 
201 #define MDIAGARRAY2_DADA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
202  MARRAY_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \
203  MARRAY_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \
204  MARRAY_BINOP_FWD_FCN (R, product, T, C_X, X_T, C_Y, Y_T)
205 
206 // Forward declarations for the MArray operators.
207 #define MARRAY_OPS_FORWARD_DECLS(A_T, API) \
208  template <class T> \
209  class A_T; \
210  \
211  MARRAY_OP_ASSIGN_FWD_DECLS1 (A_T, T, API) \
212  MARRAY_OP_ASSIGN_FWD_DECLS (A_T, A_T<T>, API) \
213  MARRAY_UNOP_FWD_DECLS (A_T, API) \
214  MARRAY_BINOP_FWD_DECLS (A_T, API)
215 
216 #define MDIAGARRAY2_OPS_FORWARD_DECLS(A_T, API) \
217  template <class T> \
218  class A_T; \
219  \
220  MARRAY_UNOP_FWD_DECLS (A_T, API) \
221  MDIAGARRAY2_BINOP_FWD_DECLS (A_T, API)
222 
223 // Friend declarations for the MArray operators.
224 #define MARRAY_OPS_FRIEND_DECLS(A_T, API) \
225  MARRAY_OP_ASSIGN_FRIENDS1 (A_T, T, API) \
226  MARRAY_OP_ASSIGN_FRIENDS (A_T, A_T<T>, API) \
227  MARRAY_UNOP_FRIENDS (A_T, API) \
228  MARRAY_BINOP_FRIENDS (A_T, API)
229 
230 #define MDIAGARRAY2_OPS_FRIEND_DECLS(A_T, API) \
231  MARRAY_UNOP_FRIENDS (A_T, API) \
232  MDIAGARRAY2_BINOP_FRIENDS (A_T, API)
233 
234 // Define all the MArray forwarding functions for return type R and
235 // MArray element type T
236 #define MARRAY_FORWARD_DEFS(B, R, T) \
237  MARRAY_OP_ASSIGN_FWD_DEFS1 \
238  (R, T, dynamic_cast<B<T>&>, R, , T) \
239  \
240  MARRAY_OP_ASSIGN_FWD_DEFS \
241  (R, T, \
242  dynamic_cast<B<T>&>, R, dynamic_cast<const B<T>&>, R) \
243  \
244  MARRAY_UNOP_FWD_DEFS \
245  (R, T, dynamic_cast<const B<T>&>, R) \
246  \
247  MARRAY_BINOP_FWD_DEFS \
248  (R, T, dynamic_cast<const B<T>&>, R, , T) \
249  \
250  MARRAY_BINOP_FWD_DEFS \
251  (R, T, , T, dynamic_cast<const B<T>&>, R) \
252  \
253  MARRAY_AA_BINOP_FWD_DEFS \
254  (R, T, dynamic_cast<const B<T>&>, R, dynamic_cast<const B<T>&>, R)
255 
256 #define MDIAGARRAY2_FORWARD_DEFS(B, R, T) \
257  MARRAY_UNOP_FWD_DEFS \
258  (R, T, dynamic_cast<const B<T>&>, R) \
259  \
260  MDIAGARRAY2_DAS_BINOP_FWD_DEFS \
261  (R, T, dynamic_cast<const B<T>&>, R, , T) \
262  \
263  MDIAGARRAY2_SDA_BINOP_FWD_DEFS \
264  (R, T, , T, dynamic_cast<const B<T>&>, R) \
265  \
266  MDIAGARRAY2_DADA_BINOP_FWD_DEFS \
267  (R, T, dynamic_cast<const B<T>&>, R, dynamic_cast<const B<T>&>, R)
268 
269 #endif