]>
Dogcows Code - chaz/yoink/blob - src/Moof/cml/vector/vecop_macros.h
1 /* -*- C++ -*- ------------------------------------------------------------
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
8 *-----------------------------------------------------------------------*/
10 * @brief Defines the various combinations of vector expressions.
12 * Create unary and binary operators with macros. The available combinations
22 * Vector op Vector -> Vector
23 * VecXpr op Vector -> VecXpr
24 * Vector op VecXpr -> VecXpr
25 * VecXpr op VecXpr -> VecXpr
27 * Vector op Scalar -> Vector
28 * Scalar op Vector -> Vector
29 * VecXpr op Scalar -> VecXpr
30 * Scalar op VecXpr -> VecXpr
32 * All of the generator functions compress the expression tree by hoisting
33 * subexpressions into the containing expression. This has the effect of
34 * forcing only the root node of the expression tree to be a VectorXpr.
35 * Every other node is a Unary or BinaryVectorOp.
37 * @todo Should ScalarT in expressions be passed by reference or by value?
40 #ifndef vecop_macros_h
41 #define vecop_macros_h
43 /** Declare a unary operator taking a vector operand. */
44 #define CML_VEC_UNIOP(_op_, _OpT_) \
45 template<typename E, class AT> \
46 inline et::VectorXpr< \
47 et::UnaryVectorOp< vector<E,AT>, _OpT_ <E> > \
50 _op_ (const vector<E,AT>& arg) \
52 typedef et::UnaryVectorOp< \
53 vector<E,AT>, _OpT_ <E> \
55 return et::VectorXpr<ExprT>(ExprT(arg)); \
59 /** Declare a unary operator taking a et::VectorXpr operand. */
60 #define CML_VECXPR_UNIOP(_op_, _OpT_) \
61 template<class XprT> \
62 inline et::VectorXpr< \
63 et::UnaryVectorOp< XprT, _OpT_ <typename XprT::value_type> > \
66 _op_ (VECXPR_ARG_TYPE arg) \
68 typedef et::UnaryVectorOp< \
69 XprT, _OpT_ <typename XprT::value_type> \
71 return et::VectorXpr<ExprT>(ExprT(arg.expression())); \
75 /** Declare an operator taking two vector operands. */
76 #define CML_VEC_VEC_BINOP(_op_, _OpT_) \
77 template<typename E1, class AT1, typename E2, class AT2> \
78 inline et::VectorXpr< \
80 vector<E1,AT1>, vector<E2,AT2>, _OpT_ <E1,E2> \
85 const vector<E1,AT1>& left, \
86 const vector<E2,AT2>& right) \
88 typedef et::BinaryVectorOp< \
89 vector<E1,AT1>, vector<E2,AT2>, _OpT_ <E1,E2> \
91 return et::VectorXpr<ExprT>(ExprT(left,right)); \
95 /** Declare an operator taking a vector and a et::VectorXpr. */
96 #define CML_VEC_VECXPR_BINOP(_op_, _OpT_) \
97 template<typename E, class AT, class XprT> \
98 inline et::VectorXpr< \
100 vector<E,AT>, XprT, _OpT_ <E, typename XprT::value_type> \
105 const vector<E,AT>& left, \
106 VECXPR_ARG_TYPE right) \
108 typedef et::BinaryVectorOp< \
109 vector<E,AT>, XprT, \
110 _OpT_ <E, typename XprT::value_type> \
112 return et::VectorXpr<ExprT>(ExprT(left,right.expression())); \
116 /** Declare an operator taking an et::VectorXpr and a vector. */
117 #define CML_VECXPR_VEC_BINOP(_op_, _OpT_) \
118 template<class XprT, typename E, class AT> \
119 inline et::VectorXpr< \
120 et::BinaryVectorOp< \
121 XprT, vector<E,AT>, _OpT_ <typename XprT::value_type, E> \
126 VECXPR_ARG_TYPE left, \
127 const vector<E,AT>& right) \
129 typedef et::BinaryVectorOp< \
130 XprT, vector<E,AT>, \
131 _OpT_ <typename XprT::value_type, E> \
133 return et::VectorXpr<ExprT>(ExprT(left.expression(),right)); \
137 /** Declare an operator taking two et::VectorXpr operands. */
138 #define CML_VECXPR_VECXPR_BINOP(_op_, _OpT_) \
139 template<class XprT1, class XprT2> \
140 inline et::VectorXpr< \
141 et::BinaryVectorOp< \
144 typename XprT1::value_type, \
145 typename XprT2::value_type \
151 VECXPR_ARG_TYPE_N(1) left, \
152 VECXPR_ARG_TYPE_N(2) right) \
154 typedef et::BinaryVectorOp< \
157 typename XprT1::value_type, \
158 typename XprT2::value_type> \
160 return et::VectorXpr<ExprT>( \
161 ExprT(left.expression(),right.expression())); \
165 /** Declare an operator taking a vector and a scalar. */
166 #define CML_VEC_SCALAR_BINOP(_op_, _OpT_) \
167 template<typename E, class AT, typename ScalarT> \
168 inline et::VectorXpr< \
169 et::BinaryVectorOp< \
170 vector<E,AT>, ScalarT, _OpT_ <E,ScalarT> \
175 const vector<E,AT>& left, \
176 SCALAR_ARG_TYPE right) \
178 typedef et::BinaryVectorOp< \
179 vector<E,AT>, ScalarT, _OpT_ <E,ScalarT> \
181 return et::VectorXpr<ExprT>(ExprT(left,right)); \
185 /** Declare an operator taking a scalar and a vector. */
186 #define CML_SCALAR_VEC_BINOP(_op_, _OpT_) \
187 template<typename ScalarT, typename E, class AT> \
188 inline et::VectorXpr< \
189 et::BinaryVectorOp< \
190 ScalarT, vector<E,AT>, _OpT_ <ScalarT,E> \
195 SCALAR_ARG_TYPE left, \
196 const vector<E,AT>& right) \
198 typedef et::BinaryVectorOp< \
199 ScalarT, vector<E,AT>, _OpT_ <ScalarT,E> \
201 return et::VectorXpr<ExprT>(ExprT(left,right)); \
205 /** Declare an operator taking a et::VectorXpr and a scalar. */
206 #define CML_VECXPR_SCALAR_BINOP(_op_, _OpT_) \
207 template<class XprT, typename ScalarT> \
208 inline et::VectorXpr< \
209 et::BinaryVectorOp< \
210 XprT, ScalarT, _OpT_ <typename XprT::value_type,ScalarT> \
215 VECXPR_ARG_TYPE left, \
216 SCALAR_ARG_TYPE right) \
218 typedef et::BinaryVectorOp< \
219 XprT, ScalarT, _OpT_ <typename XprT::value_type,ScalarT> \
221 return et::VectorXpr<ExprT>(ExprT(left.expression(),right)); \
225 /** Declare an operator taking a scalar and a et::VectorXpr. */
226 #define CML_SCALAR_VECXPR_BINOP(_op_, _OpT_) \
227 template<typename ScalarT, class XprT> \
228 inline et::VectorXpr< \
229 et::BinaryVectorOp< \
230 ScalarT, XprT, _OpT_ <ScalarT, typename XprT::value_type> \
235 SCALAR_ARG_TYPE left, \
236 VECXPR_ARG_TYPE right) \
238 typedef et::BinaryVectorOp< \
240 _OpT_ <ScalarT, typename XprT::value_type> \
242 return et::VectorXpr<ExprT>(ExprT(left,right.expression())); \
247 // -------------------------------------------------------------------------
This page took 0.043253 seconds and 4 git commands to generate.