Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef _GMTL_VEC_EXPR_META_H
00007 #define _GMTL_VEC_EXPR_META_H
00008
00009 #include <gmtl/Util/Meta.h>
00010 #include <gmtl/VecOpsMeta.h>
00011 #include <gmtl/VecBase.h>
00012
00015 namespace gmtl
00016 {
00017 namespace meta
00018 {
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00037 template <typename T>
00038 struct ScalarArg
00039 {
00040 typedef T DataType;
00041
00042 const T mScalar;
00043
00044 inline ScalarArg(const T scalar) : mScalar(scalar) {}
00045 inline T operator[](const unsigned) const
00046 { return mScalar; }
00047 };
00048
00049 template <typename T>
00050 inline ScalarArg<T> makeScalarArg(T val)
00051 { return ScalarArg<T>(val); }
00052
00053
00058 template<typename T>
00059 struct ExprTraits
00060 {
00061 typedef const T ExprRef;
00062 };
00063
00064 template<typename T, unsigned SIZE>
00065 struct ExprTraits< VecBase<T, SIZE, ScalarArg<T> > >
00066 {
00067 typedef const VecBase<T,SIZE,ScalarArg<T> > ExprRef;
00068 };
00069
00070 template<typename T, unsigned SIZE>
00071 struct ExprTraits< VecBase<T, SIZE, DefaultVecTag> >
00072 {
00073 typedef const VecBase<T,SIZE,DefaultVecTag>& ExprRef;
00074 };
00075
00076
00077
00082 template <typename EXP1_T, typename EXP2_T, typename OP>
00083 struct VecBinaryExpr
00084 {
00085 typedef typename EXP1_T::DataType DataType;
00086
00087 typename ExprTraits<EXP1_T>::ExprRef Exp1;
00088 typename ExprTraits<EXP2_T>::ExprRef Exp2;
00089
00090 inline VecBinaryExpr(const EXP1_T& e1, const EXP2_T& e2) : Exp1(e1), Exp2(e2) {;}
00091 inline DataType operator[](const unsigned i) const
00092 { return OP::eval(Exp1[i], Exp2[i]); }
00093 };
00094
00098 template <typename EXP1_T, typename OP>
00099 struct VecUnaryExpr
00100 {
00101 typedef typename EXP1_T::DataType DataType;
00102
00103 typename ExprTraits<EXP1_T>::ExprRef Exp1;
00104
00105 inline VecUnaryExpr(const EXP1_T& e1) : Exp1(e1) {;}
00106 inline DataType operator[](const unsigned i) const
00107 { return OP::eval(Exp1[i]); }
00108 };
00109
00110
00111
00112 struct VecPlusBinary
00113 {
00114 template <typename T>
00115 static inline T eval(const T a1, const T a2)
00116 { return a1+a2; }
00117 };
00118
00119
00120 struct VecMinusBinary
00121 {
00122 template <typename T>
00123 static inline T eval(const T a1, const T a2)
00124 { return a1-a2; }
00125 };
00126
00127 struct VecMultBinary
00128 {
00129 template<typename T>
00130 static inline T eval(const T a1, const T a2)
00131 { return a1 * a2; }
00132 };
00133
00134 struct VecDivBinary
00135 {
00136 template<typename T>
00137 static inline T eval(const T a1, const T a2)
00138 { return a1/a2; }
00139 };
00140
00142 struct VecNegUnary
00143 {
00144 template <typename T>
00145 static inline T eval(const T a1)
00146 { return -a1; }
00147 };
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00178
00179
00180 }
00181 }
00182
00183
00184 #endif