00001 #ifndef Impala_Core_Array_Trait_TalkBpo_h
00002 #define Impala_Core_Array_Trait_TalkBpo_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 Src1ArrayT, class Src2ArrayT>
00019 class TalkBpoPtrE1
00020 {
00021 public:
00023 typedef Pattern::TagTransInVar TransVarianceCategory;
00024
00026 typedef Pattern::TagCallPointer CallCategory;
00027
00028 typedef typename DstArrayT::StorType DstStorType;
00029 typedef typename DstArrayT::ArithType DstArithType;
00030 typedef typename Src1ArrayT::StorType Src1StorType;
00031 typedef typename Src1ArrayT::ArithType Src1ArithType;
00032 typedef typename Src2ArrayT::StorType Src2StorType;
00033 typedef typename Src2ArrayT::ArithType Src2ArithType;
00034
00036 TalkBpoPtrE1(bool verbose, bool doAdd)
00037 {
00038 mVerbose = verbose;
00039 mDoAdd = doAdd;
00040 }
00041
00043 void
00044 DoIt(DstStorType* dPtr, Src1StorType* s1Ptr, Src2StorType* s2Ptr)
00045 {
00046 DstStorType res;
00047 res = (mDoAdd) ? *s1Ptr + *s2Ptr : *s1Ptr * *s2Ptr;
00048 if (mVerbose)
00049 {
00050 std::cout << " TalkBpo::doIt(" << *s1Ptr << "," << *s2Ptr
00051 << ") = " << res << std::endl;
00052 }
00053 *dPtr = res;
00054 }
00055
00056 private:
00057 bool mVerbose;
00058 bool mDoAdd;
00059 };
00060
00061
00064 template<class DstArrayT, class Src1ArrayT, class Src2ArrayT>
00065 class TalkBpoPtrEn
00066 {
00067 public:
00069 typedef Pattern::TagTransInVar TransVarianceCategory;
00070
00072 typedef Pattern::TagCallPointer CallCategory;
00073
00074 typedef typename DstArrayT::StorType DstStorType;
00075 typedef typename DstArrayT::ArithType DstArithType;
00076 typedef typename Src1ArrayT::StorType Src1StorType;
00077 typedef typename Src1ArrayT::ArithType Src1ArithType;
00078 typedef typename Src2ArrayT::StorType Src2StorType;
00079 typedef typename Src2ArrayT::ArithType Src2ArithType;
00080
00082 TalkBpoPtrEn(bool verbose, bool doAdd)
00083 {
00084 mVerbose = verbose;
00085 mDoAdd = doAdd;
00086 }
00087
00089 void
00090 DoIt(DstStorType* dPtr, Src1StorType* s1Ptr, Src2StorType* s2Ptr)
00091 {
00092 Src1ArithType x = Pattern::PtrRead(s1Ptr, Src1ArithType());
00093 Src2ArithType y = Pattern::PtrRead(s2Ptr, Src2ArithType());
00094 DstArithType res;
00095 res = Element::E1Cast((mDoAdd) ? x+y : x*y, DstArithType());
00096 if (mVerbose)
00097 {
00098 std::cout << " TalkBpo::doIt(" << x << "," << y
00099 << ") = " << res << std::endl;
00100 }
00101 Pattern::PtrWrite(dPtr, res);
00102 }
00103
00104 private:
00105 bool mVerbose;
00106 bool mDoAdd;
00107 };
00108
00109
00112 template<class DstArrayT, class Src1ArrayT, class Src2ArrayT>
00113 class TalkBpoVal
00114 {
00115 public:
00117 typedef Pattern::TagTransInVar TransVarianceCategory;
00118
00120 typedef Pattern::TagCallValue CallCategory;
00121
00122 typedef typename DstArrayT::StorType DstStorType;
00123 typedef typename DstArrayT::ArithType DstArithType;
00124 typedef typename Src1ArrayT::StorType Src1StorType;
00125 typedef typename Src1ArrayT::ArithType Src1ArithType;
00126 typedef typename Src2ArrayT::StorType Src2StorType;
00127 typedef typename Src2ArrayT::ArithType Src2ArithType;
00128
00130 TalkBpoVal(bool verbose, bool doAdd)
00131 {
00132 mVerbose = verbose;
00133 mDoAdd = doAdd;
00134 }
00135
00137 DstArithType
00138 DoIt(Src1ArithType x, Src2ArithType y)
00139 {
00140 DstArithType res;
00141 res = Element::E1Cast((mDoAdd) ? (x+y) : x*y, DstArithType());
00142 if (mVerbose)
00143 {
00144 std::cout << " TalkBpo::doIt(" << x<< "," << y
00145 << ") = " << res << std::endl;
00146 }
00147 return res;
00148 }
00149
00150 private:
00151 bool mVerbose;
00152 bool mDoAdd;
00153 };
00154
00155 }
00156 }
00157 }
00158 }
00159
00160 #endif