00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef VECTOR3_EXPRESSION_HPP
00021 #define VECTOR3_EXPRESSION_HPP
00022
00023 #include <Expression.hpp>
00024 #include <RealExpression.hpp>
00025
00026 #include <EmbededFunctions.hpp>
00027
00028 #include <Stringify.hpp>
00029 #include <ErrorHandler.hpp>
00030
00031 #include <cmath>
00032
00033 class Vector3Expression
00034 : public Expression
00035 {
00036 private:
00037 std::ostream& put(std::ostream& os) const
00038 {
00039 os << '(' << this->value(0)
00040 << ',' << this->value(1)
00041 << ',' << this->value(2) << ')';
00042 return os;
00043 }
00044
00045 public:
00050 virtual real_t value(const size_t& i) const = 0;
00051
00056 virtual ReferenceCounting<RealExpression>
00057 component(const size_t& i) const = 0;
00058
00059 Vector3Expression(const Vector3Expression& e)
00060 : Expression(e)
00061 {
00062 ;
00063 }
00064
00065 Vector3Expression()
00066 : Expression(Expression::vector3)
00067 {
00068 ;
00069 }
00070
00071 virtual ~Vector3Expression()
00072 {
00073 ;
00074 }
00075 };
00076
00077
00078 class Vector3ExpressionValue
00079 : public Vector3Expression
00080 {
00081 private:
00082 ReferenceCounting<RealExpression> __v0;
00083 ReferenceCounting<RealExpression> __v1;
00084 ReferenceCounting<RealExpression> __v2;
00085
00086 public:
00087 real_t value(const size_t& i) const
00088 {
00089 ASSERT (i<3);
00090 switch (i) {
00091 case 0:
00092 return (*__v0).realValue();
00093 case 1:
00094 return (*__v1).realValue();
00095 case 2:
00096 return (*__v2).realValue();
00097 default: {
00098 throw ErrorHandler(__FILE__,__LINE__,
00099 "trying to access a component not in set {0,1,2}",
00100 ErrorHandler::unexpected);
00101 }
00102 }
00103 return 0;
00104 }
00105
00106 ReferenceCounting<RealExpression> component(const size_t& i) const
00107 {
00108 ASSERT (i<3);
00109 switch (i) {
00110 case 0:
00111 return __v0;
00112 case 1:
00113 return __v1;
00114 case 2:
00115 return __v2;
00116 default: {
00117 throw ErrorHandler(__FILE__,__LINE__,
00118 "trying to access a component not in set {0,1,2}",
00119 ErrorHandler::unexpected);
00120 }
00121 }
00122 return 0;
00123 }
00124
00125 void execute()
00126 {
00127 (*__v0).execute();
00128 (*__v1).execute();
00129 (*__v2).execute();
00130 }
00131
00132 Vector3ExpressionValue(ReferenceCounting<RealExpression> v0,
00133 ReferenceCounting<RealExpression> v1,
00134 ReferenceCounting<RealExpression> v2)
00135 : __v0(v0),
00136 __v1(v1),
00137 __v2(v2)
00138 {
00139 ;
00140 }
00141
00142 Vector3ExpressionValue(const Vector3ExpressionValue& re)
00143 : __v0(re.__v0),
00144 __v1(re.__v1),
00145 __v2(re.__v2)
00146 {
00147 ;
00148 }
00149
00150 ~Vector3ExpressionValue()
00151 {
00152 ;
00153 }
00154 };
00155
00156 class Vector3ExpressionTimesScalar
00157 : public Vector3Expression
00158 {
00159 private:
00160 ReferenceCounting<Vector3Expression> __vector;
00161 ReferenceCounting<RealExpression> __scalar;
00162
00163 public:
00164 real_t value(const size_t& i) const
00165 {
00166 ASSERT (i<3);
00167 return ((*__vector).value(i) * (*__scalar).realValue());
00168 }
00169
00170 ReferenceCounting<RealExpression> component(const size_t& i) const
00171 {
00172 ASSERT (i<3);
00173 return new RealExpressionBinaryOperator<product>((*__vector).component(i),__scalar);
00174 }
00175
00176 void execute()
00177 {
00178 (*__vector).execute();
00179 (*__scalar).execute();
00180 }
00181
00182 Vector3ExpressionTimesScalar(ReferenceCounting<Vector3Expression> v,
00183 ReferenceCounting<RealExpression> s)
00184 : __vector(v),
00185 __scalar(s)
00186 {
00187 ;
00188 }
00189
00190 Vector3ExpressionTimesScalar(const Vector3ExpressionTimesScalar& re)
00191 : __vector(re.__vector),
00192 __scalar(re.__scalar)
00193 {
00194 ;
00195 }
00196
00197 ~Vector3ExpressionTimesScalar()
00198 {
00199 ;
00200 }
00201 };
00202
00203 class Vector3Variable;
00204 class Vector3ExpressionVariable
00205 : public Vector3Expression
00206 {
00207 private:
00208 const std::string __vector3Name;
00209 ReferenceCounting<Vector3Variable> __vector3Variable;
00210 real_t __value[3];
00211
00212 public:
00213 real_t value(const size_t& i) const;
00214
00215 ReferenceCounting<RealExpression> component(const size_t& i) const;
00216
00217 void execute();
00218
00219 Vector3ExpressionVariable(const std::string& vector3Name);
00220
00221 Vector3ExpressionVariable(const Vector3ExpressionVariable& e);
00222
00223 ~Vector3ExpressionVariable();
00224 };
00225
00226 #include <cmath>
00227
00228 template <real_t(*B)(const real_t x, const real_t y)>
00229 class Vector3ExpressionBinaryOperator
00230 : public Vector3Expression
00231 {
00232 private:
00233 ReferenceCounting<Vector3Expression> __r1;
00234 ReferenceCounting<Vector3Expression> __r2;
00235
00236 public:
00237 real_t value(const size_t& i) const
00238 {
00239 return B((*__r1).value(i), (*__r2).value(i));
00240 }
00241
00242 ReferenceCounting<RealExpression> component(const size_t& i) const
00243 {
00244 return new RealExpressionBinaryOperator<B>((*__r1).component(i), (*__r2).component(i));
00245 }
00246
00247 void execute()
00248 {
00249 (*__r1).execute();
00250 (*__r2).execute();
00251 }
00252
00253 Vector3ExpressionBinaryOperator(ReferenceCounting<Vector3Expression> r1,
00254 ReferenceCounting<Vector3Expression> r2)
00255 : __r1(r1),
00256 __r2(r2)
00257 {
00258 ;
00259 }
00260
00261 Vector3ExpressionBinaryOperator(const Vector3ExpressionBinaryOperator<B>& e)
00262 : __r1(e.__r1),
00263 __r2(e.__r2)
00264 {
00265 ;
00266 }
00267
00268 ~Vector3ExpressionBinaryOperator()
00269 {
00270 ;
00271 }
00272 };
00273
00274 #endif // VECTOR3_EXPRESSION_HPP