src/Field/Assign.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef ASSIGN_H
00012 #define ASSIGN_H
00013 
00014 // include files
00015 #include "PETE/IpplExpressions.h"
00016 #include "AppTypes/dcomplex.h"
00017 
00018 // forward declarations
00019 template<class T, unsigned Dim> class BareField;
00020 template<class T, unsigned Dim> class LField;
00021 template<class T, unsigned Dim, unsigned Brackets> class IndexedBareField;
00022 
00023 // a debugging output message macro for assign functions.  This is
00024 // only enabled if you specificall add -DDEBUG_ASSIGN somewhere.
00025 #ifdef DEBUG_ASSIGN
00026 #define ASSIGNMSG(x) x
00027 #else
00028 #define ASSIGNMSG(x)
00029 #endif
00030 
00031 
00033 //
00034 // Currently, some of the assignment algorithms depend
00035 // on knowing that there is just one Field on the rhs.
00036 // We detect these here by building a simple tag class ExprTag
00037 // that has a bool template argument.  The arg is true
00038 // if the the assign should deal with general expressions,
00039 // and false if it can use the special purpose single field version.
00040 //
00041 // This wouldn't be needed if we had partial specialization,
00042 // but this will disambiguate expressions even without it.
00043 //
00045 
00046 template <bool IsExpr>
00047 class ExprTag
00048 {
00049 #ifdef IPPL_PURIFY
00050 public:
00051   ExprTag() {}
00052   ExprTag(const ExprTag<IsExpr> &) {}
00053   ExprTag<IsExpr>& operator=(const ExprTag<IsExpr> &) { return *this; }
00054 #endif
00055 };
00056 
00058 
00059 // BareField = Expression 
00060 template<class T, unsigned Dim, class RHS, class OP>
00061 void
00062 assign(const BareField<T,Dim>& a, RHS b, OP op, ExprTag<true>);
00063 
00064 // IndexedBareField = Expression 
00065 template<class T1, unsigned Dim, class RHS, class OP>
00066 void
00067 assign(const IndexedBareField<T1,Dim,Dim> &a, RHS b, OP op, ExprTag<true>,
00068        bool fillGC); // tjw added fillGC 12/16/1997 new BC hack
00069 
00070 // IndexedBareField = Expression 
00071 template<class T1, unsigned Dim, class RHS, class OP>
00072 inline void
00073 assign(const IndexedBareField<T1,Dim,Dim> &a, RHS b, OP op, ExprTag<true> et) {
00074   assign(a, b, op, et, true);
00075 }
00076 
00077 #ifdef __MWERKS__
00078 // Work around CodeWarrior 4.0 bug
00079 // Component = Expression
00080 template<class A, class RHS, class OP, class Tag, class TP>
00081 void
00082 assign(PETE_TUTree<OpParens<TP>,A> lhs, RHS rhs, OP op, Tag tag) {
00083   assign(lhs, rhs, op, tag, true);
00084 }
00085 
00086 // Component = Expression
00087 template<class A, class RHS, class OP, class Tag, class TP>
00088 void
00089 assign(PETE_TUTree<OpParens<TP>,A> lhs, RHS rhs, OP op, Tag,
00090        bool fillGC); // tjw added fillGC 12/16/1997 new BC hack
00091 
00092 #else
00093 // Component = Expression
00094 template<class A, class RHS, class OP, class Tag, class TP>
00095 void
00096 assign(PETE_TUTree<OpParens<TP>,A> lhs, RHS rhs, OP op, Tag,
00097        bool fillGC=true); // tjw added fillGC 12/16/1997 new BC hack
00098 #endif // __MWERKS__
00099 
00100 // BareField = BareField, with communication.
00101 template<class T1, unsigned D1, class RHS, class Op>
00102 void
00103 assign(const BareField<T1,D1>& lhs, RHS rhs, Op op, ExprTag<false>);
00104 
00105 // IndexedBareField = IndexedBareField, different dimensions.
00106 template<class T1, unsigned D1, class RHS, class Op>
00107 void
00108 assign(IndexedBareField<T1,D1,D1> lhs, RHS rhs, Op, ExprTag<false>);
00109 
00111 
00112 // Expression = constant; 
00113 template<class T, unsigned D, class OP>
00114 inline void
00115 assign(BareField<T,D>& a,const T& b, OP op, ExprTag<true>)
00116 {
00117   assign(a, PETE_Scalar<T>(b), op, ExprTag<true>());
00118 }
00119 
00120 template<class T, unsigned D, class OP>
00121 inline void
00122 assign(IndexedBareField<T,D,D> a, const T& b, OP op, ExprTag<true>)
00123 {
00124   assign(a, PETE_Scalar<T>(b), op, ExprTag<true>());
00125 }
00126 
00128 
00129 template<class T> struct IsExprTrait { enum { IsExpr = T::IsExpr } ; };
00130 template<> struct IsExprTrait<double>   { enum { IsExpr = 1 }; };
00131 template<> struct IsExprTrait<dcomplex> { enum { IsExpr = 1 }; };
00132 template<> struct IsExprTrait<float>    { enum { IsExpr = 1 }; };
00133 template<> struct IsExprTrait<short>    { enum { IsExpr = 1 }; };
00134 template<> struct IsExprTrait<int>      { enum { IsExpr = 1 }; };
00135 template<> struct IsExprTrait<long>     { enum { IsExpr = 1 }; };
00136 template<> struct IsExprTrait<Index>    { enum { IsExpr = 1 }; };
00137 
00138 #define ASSIGNMENT_OPERATORS(FUNC,OP)                           \
00139                                                                 \
00140 template<class LHS, class RHS>                                  \
00141 inline void                                                     \
00142 FUNC(const PETE_Expr<LHS>& lhs, const PETE_Expr<RHS>& rhs)      \
00143 {                                                               \
00144   assign(lhs.PETE_unwrap(), rhs.PETE_unwrap().MakeExpression(), \
00145          OP(),ExprTag< IsExprTrait<RHS>::IsExpr >());           \
00146 }                                                               \
00147                                                                 \
00148 template<class T, unsigned D>                                   \
00149 inline void                                                     \
00150 FUNC(const IndexedBareField<T,D,D>& lhs, const T& rhs)          \
00151 {                                                               \
00152   assign(lhs,PETE_Scalar<T>(rhs), OP(),ExprTag<true>(),true);   \
00153 }                                                               \
00154                                                                 \
00155 template<class T, unsigned D>                                   \
00156 inline void                                                     \
00157 FUNC(const BareField<T,D>& lhs, const T& rhs)                   \
00158 {                                                               \
00159   assign(lhs,PETE_Scalar<T>(rhs),OP(),ExprTag<true>());         \
00160 }                                                               \
00161                                                                 \
00162 template<class A, class TP>                                     \
00163 inline void                                                     \
00164 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const bool& rhs)   \
00165 {                                                               \
00166   assign(lhs,PETE_Scalar<bool>(rhs),OP(),ExprTag<true>());      \
00167 }                                                               \
00168 template<class A, class TP>                                     \
00169 inline void                                                     \
00170 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const char& rhs)   \
00171 {                                                               \
00172   assign(lhs,PETE_Scalar<char>(rhs),OP(),ExprTag<true>());      \
00173 }                                                               \
00174 template<class A, class TP>                                     \
00175 inline void                                                     \
00176 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const int& rhs)    \
00177 {                                                               \
00178   assign(lhs,PETE_Scalar<int>(rhs),OP(),ExprTag<true>());       \
00179 }                                                               \
00180 template<class A,class TP>                                      \
00181 inline void                                                     \
00182 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const float& rhs)  \
00183 {                                                               \
00184   assign(lhs,PETE_Scalar<float>(rhs),OP(),ExprTag<true>());     \
00185 }                                                               \
00186 template<class A, class TP>                                     \
00187 inline void                                                     \
00188 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const double& rhs) \
00189 {                                                               \
00190   assign(lhs,PETE_Scalar<double>(rhs),OP(),ExprTag<true>());    \
00191 }                                                               \
00192 template<class A, class TP>                                     \
00193 inline void                                                     \
00194 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const dcomplex& rhs)\
00195 {                                                               \
00196   assign(lhs,PETE_Scalar<dcomplex>(rhs),OP(),ExprTag<true>());  \
00197 }
00198 
00199 #ifdef UNDEFINED
00200 
00201 template<class LHS>                                                     \
00202 inline void                                                             \
00203 FUNC(const PETE_Expr<LHS>& lhs, double rhs)                             \
00204 {                                                                       \
00205   assign(lhs.PETE_unwrap(),PETE_Scalar<double>(rhs),OP(),ExprTag<true>());      \
00206 }                                                                       \
00207                                                                         \
00208 template<class LHS>                                                     \
00209 inline void                                                             \
00210 FUNC(const PETE_Expr<LHS>& lhs, float rhs)                              \
00211 {                                                                       \
00212   assign(lhs.PETE_unwrap(),PETE_Scalar<float>(rhs),OP(),ExprTag<true>());       \
00213 }                                                                       \
00214                                                                         \
00215 template<class LHS>                                                     \
00216 inline void                                                             \
00217 FUNC(const PETE_Expr<LHS>& lhs, int rhs)                                \
00218 {                                                                       \
00219   assign(lhs.PETE_unwrap(),PETE_Scalar<int>(rhs),OP(),ExprTag<true>()); \
00220 }
00221 
00222 #endif
00223 
00224 ASSIGNMENT_OPERATORS(assign,OpAssign)
00225 ASSIGNMENT_OPERATORS(operator<<,OpAssign)
00226 ASSIGNMENT_OPERATORS(operator+=,OpAddAssign)                                  
00227 ASSIGNMENT_OPERATORS(operator-=,OpSubtractAssign)                             
00228 ASSIGNMENT_OPERATORS(operator*=,OpMultipplyAssign)
00229 ASSIGNMENT_OPERATORS(operator/=,OpDivideAssign)
00230 ASSIGNMENT_OPERATORS(mineq,OpMinAssign)
00231 ASSIGNMENT_OPERATORS(maxeq,OpMaxAssign)
00232 
00233 
00234 // Determine whether to compress or uncompress the
00235 // left hand side given information about the expression.
00236 // This prototype is defined here because the SubField assignment
00237 // files need this functionality as well.
00238 template<class T, unsigned Dim, class A, class Op>
00239 bool TryCompressLHS(LField<T,Dim>&, A&, Op, const NDIndex<Dim>&);
00240 
00241 
00242 // Include the .cpp function definitions.
00243 #include "Field/Assign.cpp"
00244 #include "Field/AssignGeneralBF.cpp"
00245 #include "Field/AssignGeneralIBF.cpp"
00246 
00247 #endif // ASSIGN_H
00248 
00249 /***************************************************************************
00250  * $RCSfile: Assign.h,v $   $Author: adelmann $
00251  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:26 $
00252  * IPPL_VERSION_ID: $Id: Assign.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $ 
00253  ***************************************************************************/

Generated on Mon Jan 16 13:23:43 2006 for IPPL by  doxygen 1.4.6