MArray-decl.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
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_MArray_decl_h)
00024 #define octave_MArray_decl_h 1
00025 
00026 // A macro that can be used to declare and instantiate OP= operators.
00027 #define MARRAY_OP_ASSIGN_DECL(A_T, E_T, OP, PFX, API, LTGT, RHS_T) \
00028   PFX API A_T<E_T>& \
00029   operator OP LTGT (A_T<E_T>&, const RHS_T&)
00030 
00031 #define MARRAY_OP_ASSIGN_DECLX(A_T, E_T, OP, PFX, API, LTGT, RHS_T) \
00032   PFX API A_T<E_T>& \
00033   OP LTGT (A_T<E_T>&, const RHS_T&)
00034 
00035 // All the OP= operators that we care about.
00036 #define MARRAY_OP_ASSIGN_DECLS(A_T, E_T, PFX, API, LTGT, RHS_T) \
00037   MARRAY_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, API, LTGT, RHS_T); \
00038   MARRAY_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, API, LTGT, RHS_T); \
00039   MARRAY_OP_ASSIGN_DECLX (A_T, E_T, product_eq, PFX, API, LTGT, RHS_T); \
00040   MARRAY_OP_ASSIGN_DECLX (A_T, E_T, quotient_eq, PFX, API, LTGT, RHS_T);
00041 
00042 #define MARRAY_OP_ASSIGN_DECLS1(A_T, E_T, PFX, API, LTGT, RHS_T) \
00043   MARRAY_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, API, LTGT, RHS_T); \
00044   MARRAY_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, API, LTGT, RHS_T); \
00045   MARRAY_OP_ASSIGN_DECL (A_T, E_T, *=, PFX, API, LTGT, RHS_T); \
00046   MARRAY_OP_ASSIGN_DECL (A_T, E_T, /=, PFX, API, LTGT, RHS_T);
00047 
00048 // Generate forward declarations for OP= operators.
00049 #define MARRAY_OP_ASSIGN_FWD_DECLS(A_T, RHS_T, API) \
00050   MARRAY_OP_ASSIGN_DECLS (A_T, T, template <typename T>, API, , RHS_T)
00051 
00052 #define MARRAY_OP_ASSIGN_FWD_DECLS1(A_T, RHS_T, API) \
00053   MARRAY_OP_ASSIGN_DECLS1 (A_T, T, template <typename T>, API, , RHS_T)
00054 
00055 // Generate friend declarations for the OP= operators.
00056 #define MARRAY_OP_ASSIGN_FRIENDS(A_T, RHS_T, API) \
00057   MARRAY_OP_ASSIGN_DECLS (A_T, T, friend, API, <>, RHS_T)
00058 
00059 #define MARRAY_OP_ASSIGN_FRIENDS1(A_T, RHS_T, API) \
00060   MARRAY_OP_ASSIGN_DECLS1 (A_T, T, friend, API, <>, RHS_T)
00061 
00062 // A function that can be used to forward OP= operations from derived
00063 // classes back to us.
00064 #define MARRAY_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
00065   inline R \
00066   F (X_T& x, const Y_T& y) \
00067   { \
00068     return R (F (C_X (x), C_Y (y))); \
00069   }
00070 
00071 // All the OP= operators that we care about forwarding.
00072 #define MARRAY_OP_ASSIGN_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
00073   MARRAY_OP_ASSIGN_FWD_FCN (R, operator +=, T, C_X, X_T, C_Y, Y_T) \
00074   MARRAY_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T) \
00075   MARRAY_OP_ASSIGN_FWD_FCN (R, product_eq, T, C_X, X_T, C_Y, Y_T) \
00076   MARRAY_OP_ASSIGN_FWD_FCN (R, quotient_eq, T, C_X, X_T, C_Y, Y_T)
00077 
00078 #define MARRAY_OP_ASSIGN_FWD_DEFS1(R, T, C_X, X_T, C_Y, Y_T) \
00079   MARRAY_OP_ASSIGN_FWD_FCN (R, operator +=, T, C_X, X_T, C_Y, Y_T) \
00080   MARRAY_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T) \
00081   MARRAY_OP_ASSIGN_FWD_FCN (R, operator *=, T, C_X, X_T, C_Y, Y_T) \
00082   MARRAY_OP_ASSIGN_FWD_FCN (R, operator /=, T, C_X, X_T, C_Y, Y_T)
00083 
00084 // A macro that can be used to declare and instantiate unary operators.
00085 #define MARRAY_UNOP(A_T, E_T, F, PFX, API, LTGT) \
00086   PFX API A_T<E_T> \
00087   F LTGT (const A_T<E_T>&)
00088 
00089 // All the unary operators that we care about.
00090 #define MARRAY_UNOP_DECLS(A_T, E_T, PFX, API, LTGT) \
00091   MARRAY_UNOP (A_T, E_T, operator +, PFX, API, LTGT); \
00092   MARRAY_UNOP (A_T, E_T, operator -, PFX, API, LTGT);
00093 
00094 // Generate forward declarations for unary operators.
00095 #define MARRAY_UNOP_FWD_DECLS(A_T, API) \
00096   MARRAY_UNOP_DECLS (A_T, T, template <typename T>, API, )
00097 
00098 // Generate friend declarations for the unary operators.
00099 #define MARRAY_UNOP_FRIENDS(A_T, API) \
00100   MARRAY_UNOP_DECLS (A_T, T, friend, API, <>)
00101 
00102 // A function that can be used to forward unary operations from derived
00103 // classes back to us.
00104 #define MARRAY_UNOP_FWD_FCN(R, F, T, C_X, X_T) \
00105   inline R \
00106   F (const X_T& x) \
00107   { \
00108     return R (F (C_X (x))); \
00109   }
00110 
00111 // All the unary operators that we care about forwarding.
00112 #define MARRAY_UNOP_FWD_DEFS(R, T, C_X, X_T) \
00113   MARRAY_UNOP_FWD_FCN (R, operator +, T, C_X, X_T) \
00114   MARRAY_UNOP_FWD_FCN (R, operator -, T, C_X, X_T)
00115 
00116 // A macro that can be used to declare and instantiate binary operators.
00117 #define MARRAY_BINOP_DECL(A_T, E_T, F, PFX, API, LTGT, X_T, Y_T) \
00118   PFX API A_T<E_T> \
00119   F LTGT (const X_T&, const Y_T&)
00120 
00121 // All the binary operators that we care about.  We have two
00122 // sets of macros since the MArray OP MArray operations use functions
00123 // (product and quotient) instead of operators (*, /).
00124 #define MARRAY_BINOP_DECLS(A_T, E_T, PFX, API, LTGT, X_T, Y_T) \
00125   MARRAY_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, X_T, Y_T); \
00126   MARRAY_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, X_T, Y_T); \
00127   MARRAY_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T); \
00128   MARRAY_BINOP_DECL (A_T, E_T, operator /, PFX, API, LTGT, X_T, Y_T);
00129 
00130 #define MARRAY_AA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT) \
00131   MARRAY_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
00132   MARRAY_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
00133   MARRAY_BINOP_DECL (A_T, E_T, quotient,   PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
00134   MARRAY_BINOP_DECL (A_T, E_T, product,    PFX, API, LTGT, A_T<E_T>, A_T<E_T>);
00135 
00136 #define MDIAGARRAY2_DAS_BINOP_DECLS(A_T, E_T, PFX, API, LTGT, X_T, Y_T) \
00137   MARRAY_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T); \
00138   MARRAY_BINOP_DECL (A_T, E_T, operator /, PFX, API, LTGT, X_T, Y_T);
00139 
00140 #define MDIAGARRAY2_SDA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT, X_T, Y_T) \
00141   MARRAY_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T);
00142 
00143 #define MDIAGARRAY2_DADA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT) \
00144   MARRAY_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
00145   MARRAY_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
00146   MARRAY_BINOP_DECL (A_T, E_T, product,    PFX, API, LTGT, A_T<E_T>, A_T<E_T>);
00147 
00148 // Generate forward declarations for binary operators.
00149 #define MARRAY_BINOP_FWD_DECLS(A_T, API) \
00150   MARRAY_BINOP_DECLS (A_T, T, template <typename T>, API, , A_T<T>, T) \
00151   MARRAY_BINOP_DECLS (A_T, T, template <typename T>, API, , T, A_T<T>) \
00152   MARRAY_AA_BINOP_DECLS (A_T, T, template <typename T>, API, )
00153 
00154 #define MDIAGARRAY2_BINOP_FWD_DECLS(A_T, API) \
00155   MDIAGARRAY2_DAS_BINOP_DECLS (A_T, T, template <typename T>, API, , A_T<T>, T) \
00156   MDIAGARRAY2_SDA_BINOP_DECLS (A_T, T, template <typename T>, API, , T, A_T<T>) \
00157   MDIAGARRAY2_DADA_BINOP_DECLS (A_T, T, template <typename T>, API, )
00158 
00159 // Generate friend declarations for the binary operators.
00160 #define MARRAY_BINOP_FRIENDS(A_T, API) \
00161   MARRAY_BINOP_DECLS (A_T, T, friend, API, <>, A_T<T>, T) \
00162   MARRAY_BINOP_DECLS (A_T, T, friend, API, <>, T, A_T<T>) \
00163   MARRAY_AA_BINOP_DECLS (A_T, T, friend, API, <>)
00164 
00165 #define MDIAGARRAY2_BINOP_FRIENDS(A_T, API) \
00166   MDIAGARRAY2_DAS_BINOP_DECLS (A_T, T, friend, API, <>, A_T<T>, T) \
00167   MDIAGARRAY2_SDA_BINOP_DECLS (A_T, T, friend, API, <>, T, A_T<T>) \
00168   MDIAGARRAY2_DADA_BINOP_DECLS (A_T, T, friend, API, <>)
00169 
00170 // A function that can be used to forward binary operations from derived
00171 // classes back to us.
00172 #define MARRAY_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
00173   inline R \
00174   F (const X_T& x, const Y_T& y) \
00175   { \
00176     return R (F (C_X (x), C_Y (y))); \
00177   }
00178 
00179 // The binary operators that we care about forwarding.  We have two
00180 // sets of macros since the MArray OP MArray operations use functions
00181 // (product and quotient) instead of operators (*, /).
00182 #define MARRAY_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
00183   MARRAY_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \
00184   MARRAY_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \
00185   MARRAY_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T) \
00186   MARRAY_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T)
00187 
00188 #define MARRAY_AA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
00189   MARRAY_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \
00190   MARRAY_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \
00191   MARRAY_BINOP_FWD_FCN (R, product,    T, C_X, X_T, C_Y, Y_T) \
00192   MARRAY_BINOP_FWD_FCN (R, quotient,   T, C_X, X_T, C_Y, Y_T)
00193 
00194 #define MDIAGARRAY2_DAS_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
00195   MARRAY_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T) \
00196   MARRAY_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T)
00197 
00198 #define MDIAGARRAY2_SDA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
00199   MARRAY_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T)
00200 
00201 #define MDIAGARRAY2_DADA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
00202   MARRAY_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \
00203   MARRAY_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \
00204   MARRAY_BINOP_FWD_FCN (R, product,    T, C_X, X_T, C_Y, Y_T)
00205 
00206 // Forward declarations for the MArray operators.
00207 #define MARRAY_OPS_FORWARD_DECLS(A_T, API) \
00208   template <class T> \
00209   class A_T; \
00210  \
00211   MARRAY_OP_ASSIGN_FWD_DECLS1 (A_T, T, API) \
00212   MARRAY_OP_ASSIGN_FWD_DECLS (A_T, A_T<T>, API) \
00213   MARRAY_UNOP_FWD_DECLS (A_T, API) \
00214   MARRAY_BINOP_FWD_DECLS (A_T, API)
00215 
00216 #define MDIAGARRAY2_OPS_FORWARD_DECLS(A_T, API) \
00217   template <class T> \
00218   class A_T; \
00219  \
00220   MARRAY_UNOP_FWD_DECLS (A_T, API) \
00221   MDIAGARRAY2_BINOP_FWD_DECLS (A_T, API)
00222 
00223 // Friend declarations for the MArray operators.
00224 #define MARRAY_OPS_FRIEND_DECLS(A_T, API) \
00225   MARRAY_OP_ASSIGN_FRIENDS1 (A_T, T, API) \
00226   MARRAY_OP_ASSIGN_FRIENDS (A_T, A_T<T>, API) \
00227   MARRAY_UNOP_FRIENDS (A_T, API) \
00228   MARRAY_BINOP_FRIENDS (A_T, API)
00229 
00230 #define MDIAGARRAY2_OPS_FRIEND_DECLS(A_T, API) \
00231   MARRAY_UNOP_FRIENDS (A_T, API) \
00232   MDIAGARRAY2_BINOP_FRIENDS (A_T, API)
00233 
00234 // Define all the MArray forwarding functions for return type R and
00235 // MArray element type T
00236 #define MARRAY_FORWARD_DEFS(B, R, T) \
00237   MARRAY_OP_ASSIGN_FWD_DEFS1 \
00238     (R, T, dynamic_cast<B<T>&>, R, , T) \
00239  \
00240   MARRAY_OP_ASSIGN_FWD_DEFS \
00241     (R, T, \
00242      dynamic_cast<B<T>&>, R, dynamic_cast<const B<T>&>, R) \
00243  \
00244   MARRAY_UNOP_FWD_DEFS \
00245     (R, T, dynamic_cast<const B<T>&>, R) \
00246  \
00247   MARRAY_BINOP_FWD_DEFS \
00248     (R, T, dynamic_cast<const B<T>&>, R, , T) \
00249  \
00250   MARRAY_BINOP_FWD_DEFS \
00251     (R, T, , T, dynamic_cast<const B<T>&>, R) \
00252  \
00253   MARRAY_AA_BINOP_FWD_DEFS \
00254     (R, T, dynamic_cast<const B<T>&>, R, dynamic_cast<const B<T>&>, R)
00255 
00256 #define MDIAGARRAY2_FORWARD_DEFS(B, R, T) \
00257   MARRAY_UNOP_FWD_DEFS \
00258     (R, T, dynamic_cast<const B<T>&>, R) \
00259  \
00260   MDIAGARRAY2_DAS_BINOP_FWD_DEFS \
00261     (R, T, dynamic_cast<const B<T>&>, R, , T) \
00262  \
00263   MDIAGARRAY2_SDA_BINOP_FWD_DEFS \
00264     (R, T, , T, dynamic_cast<const B<T>&>, R) \
00265  \
00266   MDIAGARRAY2_DADA_BINOP_FWD_DEFS \
00267     (R, T, dynamic_cast<const B<T>&>, R, dynamic_cast<const B<T>&>, R)
00268 
00269 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines