MSparse-defs.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2004-2012 David Bateman
00004 Copyright (C) 1998-2004 Andy Adler
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #if !defined (octave_MSparse_defs_h)
00025 #define octave_MSparse_defs_h 1
00026 
00027 // Nothing like a little CPP abuse to brighten everyone's day.
00028 
00029 // A macro that can be used to declare and instantiate OP= operators.
00030 #define SPARSE_OP_ASSIGN_DECL(A_T, E_T, OP, PFX, API, LTGT, RHS_T) \
00031   PFX API A_T<E_T>& \
00032   operator OP LTGT (A_T<E_T>&, const RHS_T&)
00033 
00034 // All the OP= operators that we care about.
00035 #define SPARSE_OP_ASSIGN_DECLS(A_T, E_T, PFX, API, LTGT, RHS_T) \
00036   SPARSE_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, API, LTGT, RHS_T); \
00037   SPARSE_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, API, LTGT, RHS_T);
00038 
00039 // Generate forward declarations for OP= operators.
00040 #define SPARSE_OP_ASSIGN_FWD_DECLS(A_T, RHS_T, API) \
00041   SPARSE_OP_ASSIGN_DECLS (A_T, T, template <typename T>, API, , RHS_T)
00042 
00043 // Generate friend declarations for the OP= operators.
00044 #define SPARSE_OP_ASSIGN_FRIENDS(A_T, RHS_T, API) \
00045   SPARSE_OP_ASSIGN_DECLS (A_T, T, friend, API, <>, RHS_T)
00046 
00047 // Instantiate the OP= operators.
00048 #define SPARSE_OP_ASSIGN_DEFS(A_T, E_T, RHS_T, API) \
00049   SPARSE_OP_ASSIGN_DECLS (A_T, E_T, template, API, , RHS_T)
00050 
00051 // A function that can be used to forward OP= operations from derived
00052 // classes back to us.
00053 #define SPARSE_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
00054   inline R \
00055   F (X_T& x, const Y_T& y) \
00056   { \
00057     return R (F (C_X (x), C_Y (y))); \
00058   }
00059 
00060 // All the OP= operators that we care about forwarding.
00061 #define SPARSE_OP_ASSIGN_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
00062   SPARSE_OP_ASSIGN_FWD_FCN (R, operator +=, T, C_X, X_T, C_Y, Y_T) \
00063   SPARSE_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T)
00064 
00065 // A macro that can be used to declare and instantiate unary operators.
00066 #define SPARSE_UNOP(A_T, E_T, F, PFX, API, LTGT) \
00067   PFX API A_T<E_T> \
00068   F LTGT (const A_T<E_T>&)
00069 
00070 // All the unary operators that we care about.
00071 #define SPARSE_UNOP_DECLS(A_T, E_T, PFX, API, LTGT) \
00072   SPARSE_UNOP (A_T, E_T, operator +, PFX, API, LTGT); \
00073   SPARSE_UNOP (A_T, E_T, operator -, PFX, API, LTGT);
00074 
00075 // Generate forward declarations for unary operators.
00076 #define SPARSE_UNOP_FWD_DECLS(A_T, API) \
00077   SPARSE_UNOP_DECLS (A_T, T, template <typename T>, API, )
00078 
00079 // Generate friend declarations for the unary operators.
00080 #define SPARSE_UNOP_FRIENDS(A_T, API) \
00081   SPARSE_UNOP_DECLS (A_T, T, friend, API, <>)
00082 
00083 // Instantiate the unary operators.
00084 #define SPARSE_UNOP_DEFS(A_T, E_T, API) \
00085   SPARSE_UNOP_DECLS (A_T, E_T, template, API, )
00086 
00087 // A function that can be used to forward unary operations from derived
00088 // classes back to us.
00089 #define SPARSE_UNOP_FWD_FCN(R, F, T, C_X, X_T) \
00090   inline R \
00091   F (const X_T& x) \
00092   { \
00093     return R (F (C_X (x))); \
00094   }
00095 
00096 // All the unary operators that we care about forwarding.
00097 #define SPARSE_UNOP_FWD_DEFS(R, T, C_X, X_T) \
00098   SPARSE_UNOP_FWD_FCN (R, operator +, T, C_X, X_T) \
00099   SPARSE_UNOP_FWD_FCN (R, operator -, T, C_X, X_T)
00100 
00101 // A macro that can be used to declare and instantiate binary operators.
00102 #define SPARSE_BINOP_DECL(A_T, E_T, F, PFX, API, LTGT, X_T, Y_T) \
00103   PFX API A_T<E_T> \
00104   F LTGT (const X_T&, const Y_T&)
00105 
00106 // All the binary operators that we care about.  We have two
00107 // sets of macros since the MArray OP MArray operations use functions
00108 // (product and quotient) instead of operators (*, /).
00109 #define SPARSE_BINOP_DECLS(A_T, F_T, E_T, PFX, API, LTGT, X_T, Y_T)      \
00110   SPARSE_BINOP_DECL (F_T, E_T, operator +, PFX, API, LTGT, X_T, Y_T); \
00111   SPARSE_BINOP_DECL (F_T, E_T, operator -, PFX, API, LTGT, X_T, Y_T); \
00112   SPARSE_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T); \
00113   SPARSE_BINOP_DECL (A_T, E_T, operator /, PFX, API, LTGT, X_T, Y_T);
00114 
00115 #define SPARSE_AA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT) \
00116   SPARSE_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
00117   SPARSE_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
00118   SPARSE_BINOP_DECL (A_T, E_T, quotient,   PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
00119   SPARSE_BINOP_DECL (A_T, E_T, product,    PFX, API, LTGT, A_T<E_T>, A_T<E_T>);
00120 
00121 // Generate forward declarations for binary operators.
00122 #define SPARSE_BINOP_FWD_DECLS(A_T, F_T, API) \
00123   SPARSE_BINOP_DECLS (A_T, F_T, T, template <typename T>, API, , A_T<T>, T)     \
00124   SPARSE_BINOP_DECLS (A_T, F_T, T, template <typename T>, API, , T, A_T<T>) \
00125   SPARSE_AA_BINOP_DECLS (A_T, T, template <typename T>, API, )
00126 
00127 // Generate friend declarations for the binary operators.
00128 #define SPARSE_BINOP_FRIENDS(A_T, F_T, API)                  \
00129   SPARSE_BINOP_DECLS (A_T, F_T, T, friend, API, <>, A_T<T>, T)  \
00130   SPARSE_BINOP_DECLS (A_T, F_T, T, friend, API, <>, T, A_T<T>)  \
00131   SPARSE_AA_BINOP_DECLS (A_T, T, friend, API, <>)
00132 
00133 // Instantiate the binary operators.
00134 #define SPARSE_BINOP_DEFS(A_T, F_T, E_T, API) \
00135   SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, API, , A_T<E_T>, E_T)    \
00136   SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, API, , E_T, A_T<E_T>)    \
00137   SPARSE_AA_BINOP_DECLS (A_T, E_T, template, API, )
00138 
00139 // A function that can be used to forward binary operations from derived
00140 // classes back to us.
00141 #define SPARSE_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
00142   inline R \
00143   F (const X_T& x, const Y_T& y) \
00144   { \
00145     return R (F (C_X (x), C_Y (y))); \
00146   }
00147 
00148 // The binary operators that we care about forwarding.  We have two
00149 // sets of macros since the MSparse OP MSparse operations use functions
00150 // (product and quotient) instead of operators (*, /).
00151 #define SPARSE_BINOP_FWD_DEFS(R, F, T, C_X, X_T, C_Y, Y_T)     \
00152   SPARSE_BINOP_FWD_FCN (F, operator +, T, C_X, X_T, C_Y, Y_T) \
00153   SPARSE_BINOP_FWD_FCN (F, operator -, T, C_X, X_T, C_Y, Y_T) \
00154   SPARSE_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T) \
00155   SPARSE_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T)
00156 
00157 #define SPARSE_AA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
00158   SPARSE_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \
00159   SPARSE_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \
00160   SPARSE_BINOP_FWD_FCN (R, product,    T, C_X, X_T, C_Y, Y_T) \
00161   SPARSE_BINOP_FWD_FCN (R, quotient,   T, C_X, X_T, C_Y, Y_T)
00162 
00163 // Forward declarations for the MSparse operators.
00164 #define SPARSE_OPS_FORWARD_DECLS(A_T, F_T, API) \
00165   template <class T> \
00166   class A_T; \
00167  \
00168   /* SPARSE_OP_ASSIGN_FWD_DECLS (A_T, T) */ \
00169   SPARSE_OP_ASSIGN_FWD_DECLS (A_T, A_T<T>, API) \
00170   SPARSE_UNOP_FWD_DECLS (A_T, API) \
00171   SPARSE_BINOP_FWD_DECLS (A_T, F_T, API)
00172 
00173 // Friend declarations for the MSparse operators.
00174 #define SPARSE_OPS_FRIEND_DECLS(A_T, F_T, API)  \
00175   /* SPARSE_OP_ASSIGN_FRIENDS (A_T, T) */ \
00176   SPARSE_OP_ASSIGN_FRIENDS (A_T, A_T<T>, API) \
00177   SPARSE_UNOP_FRIENDS (A_T, API) \
00178     SPARSE_BINOP_FRIENDS (A_T, F_T, API)
00179 
00180 // The following macros are for external use.
00181 
00182 // Instantiate all the MSparse friends for MSparse element type T.
00183 #define INSTANTIATE_SPARSE_FRIENDS(T, API) \
00184   /* SPARSE_OP_ASSIGN_DEFS (MSparse, T, T) */ \
00185   SPARSE_OP_ASSIGN_DEFS (MSparse, T, MSparse<T>, API) \
00186   SPARSE_UNOP_DEFS (MSparse, T, API) \
00187   SPARSE_BINOP_DEFS (MSparse, MArray, T, API)
00188 
00189 // Define all the MSparse forwarding functions for return type R and
00190 // MSparse element type T
00191 #define SPARSE_FORWARD_DEFS(B, R, F, T)         \
00192   /* SPARSE_OP_ASSIGN_FWD_DEFS  */ \
00193   /* (R, T, dynamic_cast<B<T>&>, R, , T) */     \
00194  \
00195   SPARSE_OP_ASSIGN_FWD_DEFS \
00196     (R, T, \
00197      dynamic_cast<B<T>&>, R, dynamic_cast<const B<T>&>, R) \
00198  \
00199   SPARSE_UNOP_FWD_DEFS \
00200     (R, T, dynamic_cast<const B<T>&>, R) \
00201  \
00202   SPARSE_BINOP_FWD_DEFS \
00203     (R, F, T, dynamic_cast<const B<T>&>, R, , T) \
00204  \
00205   SPARSE_BINOP_FWD_DEFS \
00206     (R, F, T, , T, dynamic_cast<const B<T>&>, R)        \
00207  \
00208   SPARSE_AA_BINOP_FWD_DEFS \
00209     (R, T, dynamic_cast<const B<T>&>, R, dynamic_cast<const B<T>&>, R)
00210 
00211 // Now we have all the definitions we need.
00212 
00213 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines