]> Dogcows Code - chaz/yoink/blob - src/Moof/cml/vector/vecop_macros.h
beginnings of scene rendering
[chaz/yoink] / src / Moof / cml / vector / vecop_macros.h
1 /* -*- C++ -*- ------------------------------------------------------------
2
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
4
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
7
8 *-----------------------------------------------------------------------*/
9 /** @file
10 * @brief Defines the various combinations of vector expressions.
11 *
12 * Create unary and binary operators with macros. The available combinations
13 * are:
14 *
15 * Unary expressions:
16 *
17 * op Vector -> Vector
18 * op VecXpr -> VecXpr
19 *
20 * Binary expressions:
21 *
22 * Vector op Vector -> Vector
23 * VecXpr op Vector -> VecXpr
24 * Vector op VecXpr -> VecXpr
25 * VecXpr op VecXpr -> VecXpr
26 *
27 * Vector op Scalar -> Vector
28 * Scalar op Vector -> Vector
29 * VecXpr op Scalar -> VecXpr
30 * Scalar op VecXpr -> VecXpr
31 *
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.
36 *
37 * @todo Should ScalarT in expressions be passed by reference or by value?
38 */
39
40 #ifndef vecop_macros_h
41 #define vecop_macros_h
42
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> > \
48 > \
49 \
50 _op_ (const vector<E,AT>& arg) \
51 { \
52 typedef et::UnaryVectorOp< \
53 vector<E,AT>, _OpT_ <E> \
54 > ExprT; \
55 return et::VectorXpr<ExprT>(ExprT(arg)); \
56 }
57
58
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> > \
64 > \
65 \
66 _op_ (VECXPR_ARG_TYPE arg) \
67 { \
68 typedef et::UnaryVectorOp< \
69 XprT, _OpT_ <typename XprT::value_type> \
70 > ExprT; \
71 return et::VectorXpr<ExprT>(ExprT(arg.expression())); \
72 }
73
74
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< \
79 et::BinaryVectorOp< \
80 vector<E1,AT1>, vector<E2,AT2>, _OpT_ <E1,E2> \
81 > \
82 > \
83 \
84 _op_ ( \
85 const vector<E1,AT1>& left, \
86 const vector<E2,AT2>& right) \
87 { \
88 typedef et::BinaryVectorOp< \
89 vector<E1,AT1>, vector<E2,AT2>, _OpT_ <E1,E2> \
90 > ExprT; \
91 return et::VectorXpr<ExprT>(ExprT(left,right)); \
92 }
93
94
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< \
99 et::BinaryVectorOp< \
100 vector<E,AT>, XprT, _OpT_ <E, typename XprT::value_type> \
101 > \
102 > \
103 \
104 _op_ ( \
105 const vector<E,AT>& left, \
106 VECXPR_ARG_TYPE right) \
107 { \
108 typedef et::BinaryVectorOp< \
109 vector<E,AT>, XprT, \
110 _OpT_ <E, typename XprT::value_type> \
111 > ExprT; \
112 return et::VectorXpr<ExprT>(ExprT(left,right.expression())); \
113 }
114
115
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> \
122 > \
123 > \
124 \
125 _op_ ( \
126 VECXPR_ARG_TYPE left, \
127 const vector<E,AT>& right) \
128 { \
129 typedef et::BinaryVectorOp< \
130 XprT, vector<E,AT>, \
131 _OpT_ <typename XprT::value_type, E> \
132 > ExprT; \
133 return et::VectorXpr<ExprT>(ExprT(left.expression(),right)); \
134 }
135
136
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< \
142 XprT1, XprT2, \
143 _OpT_ < \
144 typename XprT1::value_type, \
145 typename XprT2::value_type \
146 > \
147 > \
148 > \
149 \
150 _op_ ( \
151 VECXPR_ARG_TYPE_N(1) left, \
152 VECXPR_ARG_TYPE_N(2) right) \
153 { \
154 typedef et::BinaryVectorOp< \
155 XprT1, XprT2, \
156 _OpT_ < \
157 typename XprT1::value_type, \
158 typename XprT2::value_type> \
159 > ExprT; \
160 return et::VectorXpr<ExprT>( \
161 ExprT(left.expression(),right.expression())); \
162 }
163
164
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> \
171 > \
172 > \
173 \
174 _op_ ( \
175 const vector<E,AT>& left, \
176 SCALAR_ARG_TYPE right) \
177 { \
178 typedef et::BinaryVectorOp< \
179 vector<E,AT>, ScalarT, _OpT_ <E,ScalarT> \
180 > ExprT; \
181 return et::VectorXpr<ExprT>(ExprT(left,right)); \
182 }
183
184
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> \
191 > \
192 > \
193 \
194 _op_ ( \
195 SCALAR_ARG_TYPE left, \
196 const vector<E,AT>& right) \
197 { \
198 typedef et::BinaryVectorOp< \
199 ScalarT, vector<E,AT>, _OpT_ <ScalarT,E> \
200 > ExprT; \
201 return et::VectorXpr<ExprT>(ExprT(left,right)); \
202 }
203
204
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> \
211 > \
212 > \
213 \
214 _op_ ( \
215 VECXPR_ARG_TYPE left, \
216 SCALAR_ARG_TYPE right) \
217 { \
218 typedef et::BinaryVectorOp< \
219 XprT, ScalarT, _OpT_ <typename XprT::value_type,ScalarT> \
220 > ExprT; \
221 return et::VectorXpr<ExprT>(ExprT(left.expression(),right)); \
222 }
223
224
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> \
231 > \
232 > \
233 \
234 _op_ ( \
235 SCALAR_ARG_TYPE left, \
236 VECXPR_ARG_TYPE right) \
237 { \
238 typedef et::BinaryVectorOp< \
239 ScalarT, XprT, \
240 _OpT_ <ScalarT, typename XprT::value_type> \
241 > ExprT; \
242 return et::VectorXpr<ExprT>(ExprT(left,right.expression())); \
243 }
244
245 #endif
246
247 // -------------------------------------------------------------------------
248 // vim:ft=cpp
This page took 0.043215 seconds and 4 git commands to generate.