ShLib.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #ifndef SHLIB_HPP
00028 #define SHLIB_HPP
00029
00030 #include <cmath>
00031 #include <cassert>
00032 #include "ShVariable.hpp"
00033 #include "ShGeneric.hpp"
00034 #include "ShAttrib.hpp"
00035
00039 #define SH_SHLIB_CONST_SCALAR_OP(operation) \
00040 template<typename T> \
00041 ShGeneric<1, T> operation(const ShGeneric<1, T>& left, T right) \
00042 { \
00043 return operation(left, ShAttrib<1, SH_CONST, T>(right)); \
00044 } \
00045 template<typename T> \
00046 ShGeneric<1, T> operation(T left, const ShGeneric<1, T>& right) \
00047 { \
00048 return operation(ShAttrib<1, SH_CONST, T>(left), right); \
00049 } \
00050 template<typename T> \
00051 ShGeneric<1, T> operation(const ShGeneric<1, T>& left, double right) \
00052 { \
00053 return operation(left, ShAttrib<1, SH_CONST, T>(right)); \
00054 } \
00055 template<typename T> \
00056 ShGeneric<1, T> operation(double left, const ShGeneric<1, T>& right) \
00057 { \
00058 return operation(ShAttrib<1, SH_CONST, T>(left), right); \
00059 }
00060
00061 #define SH_SHLIB_CONST_N_OP_RETSIZE_LEFT(operation, retsize) \
00062 template<int N, typename T> \
00063 ShGeneric<retsize, T> operation(const ShGeneric<N, T>& left, T right) \
00064 { \
00065 return operation(left, ShAttrib<1, SH_CONST, T>(right)); \
00066 } \
00067 template<int N, typename T> \
00068 ShGeneric<retsize, T> operation(const ShGeneric<N, T>& left, double right) \
00069 { \
00070 return operation(left, ShAttrib<1, SH_CONST, T>(right)); \
00071 }
00072
00073 #define SH_SHLIB_CONST_N_OP_RETSIZE_RIGHT(operation, retsize) \
00074 template<int N, typename T> \
00075 ShGeneric<retsize, T> operation(T left, const ShGeneric<N, T>& right) \
00076 { \
00077 return operation(ShAttrib<1, SH_CONST, T>(left), right); \
00078 } \
00079 template<int N, typename T> \
00080 ShGeneric<retsize, T> operation(double left, const ShGeneric<N, T>& right) \
00081 { \
00082 return operation(ShAttrib<1, SH_CONST, T>(left), right); \
00083 }
00084
00085 #define SH_SHLIB_CONST_N_OP_LEFT(operation) \
00086 SH_SHLIB_CONST_N_OP_RETSIZE_LEFT(operation, N);
00087
00088 #define SH_SHLIB_CONST_N_OP_RIGHT(operation) \
00089 SH_SHLIB_CONST_N_OP_RETSIZE_RIGHT(operation, N);
00090
00091 #define SH_SHLIB_CONST_N_OP_BOTH(operation) \
00092 SH_SHLIB_CONST_N_OP_LEFT(operation); \
00093 SH_SHLIB_CONST_N_OP_RIGHT(operation);
00094
00095 #define SH_SHLIB_CONST_N_OP_RETSIZE_BOTH(operation, retsize) \
00096 SH_SHLIB_CONST_N_OP_RETSIZE_LEFT(operation, retsize); \
00097 SH_SHLIB_CONST_N_OP_RETSIZE_RIGHT(operation, retsize);
00098
00099 #define SH_SHLIB_CONST_TRINARY_OP_011_RETSIZE(operation, retsize) \
00100 template<int N, typename T> \
00101 ShGeneric<retsize, T> operation(const ShGeneric<N, T>& a, \
00102 T b, \
00103 T c) \
00104 { \
00105 return operation(a, ShAttrib<1, SH_CONST, T>(b), ShAttrib<1, SH_CONST, T>(c)); \
00106 } \
00107 template<int N, typename T> \
00108 ShGeneric<retsize, T> operation(const ShGeneric<N, T>& a, \
00109 double b, \
00110 double c) \
00111 { \
00112 return operation(a, ShAttrib<1, SH_CONST, T>(b), ShAttrib<1, SH_CONST, T>(c)); \
00113 }
00114
00115 #define SH_SHLIB_CONST_TRINARY_OP_011(operation) \
00116 SH_SHLIB_CONST_TRINARY_OP_011_RETSIZE(operation, N);
00117
00118 #include "ShLibArith.hpp"
00119 #include "ShLibBoolean.hpp"
00120 #include "ShLibClamp.hpp"
00121 #include "ShLibGeometry.hpp"
00122 #include "ShLibMatrix.hpp"
00123 #include "ShLibMisc.hpp"
00124 #include "ShLibTrig.hpp"
00125 #include "ShLibDeriv.hpp"
00126
00127
00128
00129 #define SH_SHLIB_UNARY_RETTYPE_OPERATION(libtype, libop, librettype, libretsize) \
00130 template<int N, ShBindingType K1, typename T, bool S1> \
00131 librettype<libretsize, SH_TEMP, T, false> \
00132 libop(const libtype<N, K1, T, S1>& var) \
00133 { \
00134 ShGeneric<libretsize, T> t = libop(static_cast< ShGeneric<N, T> >(var)); \
00135 return librettype<libretsize, SH_TEMP, T, false>(t.node(), t.swizzle(), t.neg()); \
00136 }
00137
00138 #define SH_SHLIB_UNARY_OPERATION(libtype, libop, libretsize) \
00139 SH_SHLIB_UNARY_RETTYPE_OPERATION(libtype, libop, libtype, libretsize)
00140
00141 #define SH_SHLIB_BINARY_RETTYPE_OPERATION(libtype, libop, librettype, libretsize) \
00142 template<int N, ShBindingType K1, ShBindingType K2, typename T, bool S1, bool S2> \
00143 librettype<libretsize, SH_TEMP, T, false> \
00144 libop(const libtype<N, K1, T, S1>& left, const libtype<N, K2, T, S2>& right) \
00145 { \
00146 ShGeneric<libretsize, T> t = libop(static_cast< ShGeneric<N, T> >(left), \
00147 static_cast< ShGeneric<N, T> >(right)); \
00148 return librettype<libretsize, SH_TEMP, T, false>(t.node(), t.swizzle(), t.neg()); \
00149 }
00150
00151 #define SH_SHLIB_BINARY_OPERATION(libtype, libop, libretsize) \
00152 SH_SHLIB_BINARY_RETTYPE_OPERATION(libtype, libop, libtype, libretsize)
00153
00154 #define SH_SHLIB_UNEQ_BINARY_RETTYPE_OPERATION(libtype, libop, librettype, libretsize) \
00155 template<int N, int M, ShBindingType K1, ShBindingType K2, typename T, bool S1, bool S2> \
00156 librettype<libretsize, SH_TEMP, T, false> \
00157 libop(const libtype<N, K1, T, S1>& left, const libtype<M, K2, T, S2>& right) \
00158 { \
00159 ShGeneric<libretsize, T> t = libop(static_cast< ShGeneric<N, T> >(left), \
00160 static_cast< ShGeneric<M, T> >(right)); \
00161 return librettype<libretsize, SH_TEMP, T, false>(t.node(), t.swizzle(), t.neg()); \
00162 }
00163
00164 #define SH_SHLIB_UNEQ_BINARY_OPERATION(libtype, libop, libretsize) \
00165 SH_SHLIB_UNEQ_BINARY_RETTYPE_OPERATION(libtype, libop, libtype, libretsize)
00166
00167 #define SH_SHLIB_LEFT_SCALAR_RETTYPE_OPERATION(libtype, libop, librettype) \
00168 template<int M, ShBindingType K1, ShBindingType K2, typename T, bool S1, bool S2> \
00169 librettype<M, SH_TEMP, T, false> \
00170 libop(const libtype<1, K2, T, S2>& left, const libtype<M, K1, T, S1>& right) \
00171 { \
00172 ShGeneric<M, T> t = libop(static_cast< ShGeneric<1, T> >(left), \
00173 static_cast< ShGeneric<M, T> >(right)); \
00174 return librettype<M, SH_TEMP, T, false>(t.node(), t.swizzle(), t.neg()); \
00175 }
00176
00177 #define SH_SHLIB_LEFT_SCALAR_OPERATION(libtype, libop) \
00178 SH_SHLIB_LEFT_SCALAR_RETTYPE_OPERATION(libtype, libop, libtype)
00179
00180 #define SH_SHLIB_LEFT_MATRIX_RETTYPE_OPERATION(libtype, libop, librettype, libretsize) \
00181 template<int M, int N, ShBindingType K1, ShBindingType K2, typename T, bool S1> \
00182 librettype<libretsize, SH_TEMP, T, false> libop(const ShMatrix<M, N, K1, T>& a, \
00183 const libtype<N, K2, T, S1>& b) \
00184 { \
00185 ShGeneric<libretsize, T> t = libop(a, \
00186 static_cast< ShGeneric<N, T> >(b)); \
00187 return librettype<libretsize, K1, T, S1>(t.node(), t.swizzle(), t.neg()); \
00188 }
00189
00190 #define SH_SHLIB_LEFT_MATRIX_OPERATION(libtype, libop, libretsize) \
00191 SH_SHLIB_LEFT_MATRIX_RETTYPE_OPERATION(libtype, libop, libtype, libretsize)
00192
00193
00194
00195 #define SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(libtype, libop, librettype, libretsize) \
00196 template<ShBindingType K1, typename T, bool S1> \
00197 librettype<libretsize, SH_TEMP, T, false> \
00198 libop(const libtype<1, K1, T, S1>& left, T right) \
00199 { \
00200 return libop(left, ShAttrib<1, SH_CONST, T>(right)); \
00201 } \
00202 template<ShBindingType K1, typename T, bool S1> \
00203 librettype<libretsize, SH_TEMP, T, false> \
00204 libop(T left, const libtype<1, K1, T, S1>& right) \
00205 { \
00206 return libop(ShAttrib<1, SH_CONST, T>(left), right); \
00207 } \
00208 template<ShBindingType K1, typename T, bool S1> \
00209 librettype<libretsize, SH_TEMP, T, false> \
00210 libop(const libtype<1, K1, T, S1>& left, double right) \
00211 { \
00212 return libop(left, ShAttrib<1, SH_CONST, T>(right)); \
00213 } \
00214 template<ShBindingType K1, typename T, bool S1> \
00215 librettype<libretsize, SH_TEMP, T, false> \
00216 libop(double left, const libtype<1, K1, T, S1>& right) \
00217 { \
00218 return libop(ShAttrib<1, SH_CONST, T>(left), right); \
00219 }
00220
00221 #define SH_SHLIB_SPECIAL_CONST_SCALAR_OP(libtype, libop) \
00222 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(libtype, libop, libtype, 1)
00223
00224 #define SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_LEFT(libtype, libop, librettype, libretsize) \
00225 template<int N, ShBindingType K1, typename T, bool S1> \
00226 librettype<libretsize, SH_TEMP, T, false> \
00227 libop(const libtype<N, K1, T, S1>& left, T right) \
00228 { \
00229 return libop(left, ShAttrib<1, SH_CONST, T>(right)); \
00230 } \
00231 template<int N, ShBindingType K1, typename T, bool S1> \
00232 librettype<libretsize, SH_TEMP, T, false> \
00233 libop(const libtype<N, K1, T, S1>& left, double right) \
00234 { \
00235 return libop(left, ShAttrib<1, SH_CONST, T>(right)); \
00236 }
00237 #define SH_SHLIB_SPECIAL_CONST_N_OP_LEFT(libtype, libop) \
00238 SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_LEFT(libtype, libop, libtype, N)
00239
00240 #define SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_RIGHT(libtype, libop, librettype, libretsize) \
00241 template<int N, ShBindingType K1, typename T, bool S1> \
00242 librettype<libretsize, SH_TEMP, T, false> \
00243 libop(T left, const libtype<N, K1, T, S1>& right) \
00244 { \
00245 return libop(ShAttrib<1, SH_CONST, T>(left), right); \
00246 } \
00247 template<int N, ShBindingType K1, typename T, bool S1> \
00248 librettype<libretsize, SH_TEMP, T, false> \
00249 libop(double left, const libtype<N, K1, T, S1>& right) \
00250 { \
00251 return libop(ShAttrib<1, SH_CONST, T>(left), right); \
00252 }
00253 #define SH_SHLIB_SPECIAL_CONST_N_OP_RIGHT(libtype, libop) \
00254 SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_RIGHT(libtype, libop, libtype, N)
00255
00256 #define SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_BOTH(libtype, operation, librettype, libretsize) \
00257 SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_LEFT(libtype, operation, librettype, libretsize); \
00258 SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_RIGHT(libtype, operation, librettype, libretsize);
00259
00260 #define SH_SHLIB_SPECIAL_CONST_N_OP_BOTH(libtype, operation) \
00261 SH_SHLIB_SPECIAL_CONST_N_OP_LEFT(libtype, operation); \
00262 SH_SHLIB_SPECIAL_CONST_N_OP_RIGHT(libtype, operation);
00263
00264
00265
00266 #define SH_SHLIB_USUAL_OPERATIONS(type) \
00267 SH_SHLIB_USUAL_OPERATIONS_RETTYPE(type, type)
00268
00269 #define SH_SHLIB_USUAL_OPERATIONS_RETTYPE(type, rettype) \
00270 SH_SHLIB_USUAL_NON_UNIT_OPS_RETTYPE(type, rettype)\
00271 SH_SHLIB_UNARY_RETTYPE_OPERATION(type, normalize, rettype, N); \
00272 SH_SHLIB_UNARY_RETTYPE_OPERATION(type, abs, rettype, N);
00273
00274 #define SH_SHLIB_USUAL_NON_UNIT_OPS_RETTYPE(type, rettype) \
00275 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, operator+, rettype, N); \
00276 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator+, rettype, 1); \
00277 \
00278 SH_SHLIB_UNEQ_BINARY_RETTYPE_OPERATION(type, operator*, rettype, N); \
00279 SH_SHLIB_LEFT_SCALAR_RETTYPE_OPERATION(type, operator*, rettype); \
00280 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator*, rettype, 1); \
00281 SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_BOTH(type, operator*, rettype, N); \
00282 \
00283 SH_SHLIB_UNEQ_BINARY_RETTYPE_OPERATION(type, operator/, rettype, N); \
00284 SH_SHLIB_LEFT_SCALAR_RETTYPE_OPERATION(type, operator/, rettype); \
00285 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator/, rettype, 1); \
00286 SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_BOTH(type, operator/, rettype, N); \
00287 \
00288 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, pow, rettype, N); \
00289 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, pow, rettype, 1); \
00290 SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_RIGHT(type, pow, rettype, N); \
00291 \
00292 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, operator<, rettype, N); \
00293 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator<, rettype, 1); \
00294 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, operator<=, rettype, N); \
00295 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator<=, rettype, 1); \
00296 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, operator>, rettype, N); \
00297 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator>, rettype, 1); \
00298 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, operator>=, rettype, N); \
00299 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator>=, rettype, 1); \
00300 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, operator==, rettype, N); \
00301 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator==, rettype, 1); \
00302 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, operator!=, rettype, N); \
00303 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, operator!=, rettype, 1); \
00304 \
00305 SH_SHLIB_UNARY_RETTYPE_OPERATION(type, acos, rettype, N); \
00306 SH_SHLIB_UNARY_RETTYPE_OPERATION(type, asin, rettype, N); \
00307 SH_SHLIB_UNARY_RETTYPE_OPERATION(type, cos, rettype, N); \
00308 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, dot, rettype, 1); \
00309 SH_SHLIB_SPECIAL_RETTYPE_CONST_N_OP_BOTH(type, dot, rettype, 1); \
00310 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, mod, rettype, N); \
00311 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, mod, rettype, 1); \
00312 \
00313 SH_SHLIB_UNARY_RETTYPE_OPERATION(type, frac, rettype, N); \
00314 SH_SHLIB_UNARY_RETTYPE_OPERATION(type, sin, rettype, N); \
00315 SH_SHLIB_UNARY_RETTYPE_OPERATION(type, sqrt, rettype, N); \
00316 \
00317 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, min, rettype, N); \
00318 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, min, rettype, 1); \
00319 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, pos, rettype, N); \
00320 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, pos, rettype, 1); \
00321 SH_SHLIB_BINARY_RETTYPE_OPERATION(type, max, rettype, N); \
00322 SH_SHLIB_SPECIAL_RETTYPE_CONST_SCALAR_OP(type, max, rettype, 1);
00323
00324
00325 #define SH_SHLIB_USUAL_SUBTRACT(type) \
00326 SH_SHLIB_BINARY_OPERATION(type, operator-, N); \
00327 SH_SHLIB_SPECIAL_CONST_SCALAR_OP(type, operator-); \
00328
00329 #endif
Generated on Mon Oct 18 14:17:39 2004 for Sh by
1.3.7