00001 #ifndef Impala_Core_Array_Trait_TalkBpoAssign_h
00002 #define Impala_Core_Array_Trait_TalkBpoAssign_h
00003
00004 #include "Core/Array/Pattern/Categories.h"
00005
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Array
00011 {
00012 namespace Trait
00013 {
00014
00015
00018 template<class DstArrayT, class SrcArrayT>
00019 struct TalkBpoAssignPtrE1
00020 {
00022 typedef Pattern::TagTransInVar TransVarianceCategory;
00023
00025 typedef Pattern::TagCallPointer CallCategory;
00026
00027 typedef typename DstArrayT::StorType DstStorType;
00028 typedef typename DstArrayT::ArithType DstArithType;
00029 typedef typename SrcArrayT::StorType SrcStorType;
00030 typedef typename SrcArrayT::ArithType SrcArithType;
00031
00033 TalkBpoAssignPtrE1(bool verbose, bool doMin, int nrToGroup)
00034 {
00035 mVerbose = verbose;
00036 mDoMin = doMin;
00037 mNrToGroup = nrToGroup;
00038 mCurNr = 1;
00039 }
00040
00042 void
00043 setNeutral(DstStorType* dPtr)
00044 {
00045 *dPtr = 0;
00046 }
00047
00049 void
00050 DoIt(DstStorType* dPtr, SrcStorType* sPtr)
00051 {
00052 DstStorType res;
00053 res = (mDoMin) ? Min(*dPtr, *sPtr) : *dPtr + *sPtr;
00054 if (mVerbose)
00055 {
00056 std::cout << " TalkBpoAssign::doIt("
00057 << *dPtr << "," << *sPtr << ") = " << res << std::endl;
00058 }
00059 if (mVerbose && (mCurNr++ >= mNrToGroup))
00060 {
00061 mCurNr = 1;
00062 std::cout << std::endl;
00063 }
00064 *dPtr = res;
00065
00066
00067
00068
00069
00070
00071 }
00072
00074 static DstStorType
00075 NeutralElement()
00076 {
00077 return 0;
00078 }
00079
00080 private:
00081 bool mVerbose;
00082 bool mDoMin;
00083 static int mNrToGroup;
00084 static int mCurNr;
00085 };
00086
00087 template <class DstStorT, class SrcStorT>
00088 int TalkBpoAssignPtrE1<DstStorT,SrcStorT>::mNrToGroup;
00089 template <class DstStorT, class SrcStorT>
00090 int TalkBpoAssignPtrE1<DstStorT,SrcStorT>::mCurNr;
00091
00092
00095 template<class DstArrayT, class SrcArrayT>
00096 struct TalkBpoAssignPtrEn
00097 {
00099 typedef Pattern::TagTransInVar TransVarianceCategory;
00100
00102 typedef Pattern::TagCallPointer CallCategory;
00103
00104 typedef typename DstArrayT::StorType DstStorType;
00105 typedef typename DstArrayT::ArithType DstArithType;
00106 typedef typename SrcArrayT::StorType SrcStorType;
00107 typedef typename SrcArrayT::ArithType SrcArithType;
00108
00110 TalkBpoAssignPtrEn(bool verbose, bool doMin, int nrToGroup)
00111 {
00112 mVerbose = verbose;
00113 mDoMin = doMin;
00114 mNrToGroup = nrToGroup;
00115 mCurNr = 1;
00116 }
00117
00119 void
00120 setNeutral(DstStorType* dPtr)
00121 {
00122 Pattern::PtrWrite(dPtr, Element::E1Cast(0, DstArithType()));
00123 }
00124
00126 void
00127 DoIt(DstStorType* dPtr, SrcStorType* sPtr)
00128 {
00129 DstArithType x(Pattern::PtrRead(dPtr, DstArithType()));
00130 SrcArithType y(Pattern::PtrRead(sPtr, SrcArithType()));
00131 DstArithType res;
00132 res = (mDoMin) ? Min(x, y) : x + y;
00133 if (mVerbose)
00134 {
00135 std::cout << " TalkBpoAssign::doIt("
00136 << x << "," << y << ") = " << res << std::endl;
00137 }
00138 if (mVerbose && (mCurNr++ >= mNrToGroup))
00139 {
00140 mCurNr = 1;
00141 std::cout << std::endl;
00142 }
00143 Pattern::PtrWrite(dPtr, res);
00144
00145
00146
00147
00148
00149
00150 }
00151
00153 static DstArithType
00154 NeutralElement()
00155 {
00156 return 0;
00157 }
00158
00159 private:
00160 bool mVerbose;
00161 bool mDoMin;
00162 static int mNrToGroup;
00163 static int mCurNr;
00164 };
00165
00166 template <class DstStorT, class SrcStorT>
00167 int TalkBpoAssignPtrEn<DstStorT,SrcStorT>::mNrToGroup;
00168 template <class DstStorT, class SrcStorT>
00169 int TalkBpoAssignPtrEn<DstStorT,SrcStorT>::mCurNr;
00170
00171
00174 template<class DstArrayT, class SrcArrayT>
00175 struct TalkBpoAssignVal
00176 {
00178 typedef Pattern::TagTransInVar TransVarianceCategory;
00179
00181 typedef Pattern::TagCallValue CallCategory;
00182
00183 typedef typename DstArrayT::StorType DstStorType;
00184 typedef typename DstArrayT::ArithType DstArithType;
00185 typedef typename SrcArrayT::StorType SrcStorType;
00186 typedef typename SrcArrayT::ArithType SrcArithType;
00187
00189 TalkBpoAssignVal(bool verbose, bool doMin, int nrToGroup)
00190 {
00191 mVerbose = verbose;
00192 mDoMin = doMin;
00193 mNrToGroup = nrToGroup;
00194 mCurNr = 1;
00195 }
00196
00198 void
00199 DoIt(DstArithType& x, const SrcArithType& y)
00200 {
00201 DstArithType res;
00202 res = (mDoMin) ? Min(x, y) : x + y;
00203 if (mVerbose)
00204 {
00205 std::cout << " TalkBpoAssign::doIt("
00206 << x << "," << y << ") = " << res << std::endl;
00207 }
00208 if (mVerbose && (mCurNr++ >= mNrToGroup))
00209 {
00210 mCurNr = 1;
00211 std::cout << std::endl;
00212 }
00213 x = res;
00214
00215
00216
00217
00218
00219
00220 }
00221
00223 static DstArithType
00224 NeutralElement()
00225 {
00226 return Element::E1Cast(0, DstArithType());
00227 }
00228
00229 private:
00230 bool mVerbose;
00231 bool mDoMin;
00232 static int mNrToGroup;
00233 static int mCurNr;
00234 };
00235
00236 template <class DstStorT, class SrcStorT>
00237 int TalkBpoAssignVal<DstStorT,SrcStorT>::mNrToGroup;
00238 template <class DstStorT, class SrcStorT>
00239 int TalkBpoAssignVal<DstStorT,SrcStorT>::mCurNr;
00240
00241 }
00242 }
00243 }
00244 }
00245
00246 #endif