8 #ifndef PXR_BASE_VT_PY_OPERATORS_H
9 #define PXR_BASE_VT_PY_OPERATORS_H
30 static bool __add__(
bool l,
bool r) {
return l |
r; }
31 static bool __sub__(
bool l,
bool r) {
return l ^
r; }
32 static bool __mul__(
bool l,
bool r) {
return l &
r; }
33 static bool __div__(
bool l,
bool r) {
return l; }
34 static bool __mod__(
bool l,
bool r) {
return false; }
46 #define VTOPERATOR_WRAP_PYTYPE_BASE(op, method, pytype, isRightVer) \
47 template <typename T> static \
48 VtArray<T> method##pytype(VtArray<T> vec, pytype obj) { \
49 size_t length = len(obj); \
50 if (length != vec.size()) { \
51 TfPyThrowValueError("Non-conforming inputs for operator " \
53 return VtArray<T>(); \
55 VtArray<T> ret(vec.size()); \
56 for (size_t i = 0; i < length; ++i) { \
57 if (!extract<T>(obj[i]).check()) \
58 TfPyThrowValueError("Element is of incorrect type."); \
60 ret[i] = _ArrayPyOpHelp<T>:: op ( \
61 (T)extract<T>(obj[i]), vec[i]); \
64 ret[i] = _ArrayPyOpHelp<T>:: op ( \
65 vec[i], (T)extract<T>(obj[i])); \
72 #define VTOPERATOR_WRAP_PYTYPE(op, method, pytype) \
73 VTOPERATOR_WRAP_PYTYPE_BASE(op, method, pytype, false)
76 #define VTOPERATOR_WRAP_PYTYPE_R(op, method, pytype) \
77 VTOPERATOR_WRAP_PYTYPE_BASE(op, method, pytype, true)
82 #define VTOPERATOR_WRAP(lmethod,rmethod) \
83 VTOPERATOR_WRAP_PYTYPE(lmethod,lmethod,tuple) \
84 VTOPERATOR_WRAP_PYTYPE(lmethod,lmethod,list) \
85 VTOPERATOR_WRAP_PYTYPE(lmethod,rmethod,tuple) \
86 VTOPERATOR_WRAP_PYTYPE(lmethod,rmethod,list)
89 #define VTOPERATOR_WRAP_NONCOMM(lmethod,rmethod) \
90 VTOPERATOR_WRAP_PYTYPE(lmethod,lmethod,tuple) \
91 VTOPERATOR_WRAP_PYTYPE(lmethod,lmethod,list) \
92 VTOPERATOR_WRAP_PYTYPE_R(lmethod,rmethod,tuple) \
93 VTOPERATOR_WRAP_PYTYPE_R(lmethod,rmethod,list)
96 #define VTOPERATOR_WRAPDECLARE_BASE(op,method,rettype) \
98 .def(self op Type()) \
99 .def(Type() op self) \
100 .def(#method,method##tuple<rettype>) \
101 .def(#method,method##list<rettype>)
103 #define VTOPERATOR_WRAPDECLARE(op,lmethod,rmethod) \
104 VTOPERATOR_WRAPDECLARE_BASE(op,lmethod,Type) \
105 .def(#rmethod,rmethod##tuple<Type>) \
106 .def(#rmethod,rmethod##list<Type>)
110 #define VTOPERATOR_WRAP_PYTYPE_BOOL(func,pytype,op) \
111 VTOPERATOR_WRAP_PYTYPE_BOOL_BASE(func, \
112 VtArray<T> const &vec, pytype const &obj, \
113 (vec[i] op (T)extract<T>(obj[i])) ) \
114 VTOPERATOR_WRAP_PYTYPE_BOOL_BASE(func, \
115 pytype const &obj,VtArray<T> const &vec, \
116 ((T)extract<T>(obj[i]) op vec[i]) )
118 #define VTOPERATOR_WRAP_BOOL(func,op) \
119 VTOPERATOR_WRAP_PYTYPE_BOOL(func,list,op) \
120 VTOPERATOR_WRAP_PYTYPE_BOOL(func,tuple,op)
125 #endif // PXR_BASE_VT_PY_OPERATORS_H
static bool __mod__(bool l, bool r)
static bool __div__(bool l, bool r)
static T __mul__(T l, T r)
static bool __sub__(bool l, bool r)
static T __mod__(T l, T r)
static T __sub__(T l, T r)
static bool __mul__(bool l, bool r)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
static T __add__(T l, T r)
#define PXR_NAMESPACE_CLOSE_SCOPE
static T __div__(T l, T r)
static bool __add__(bool l, bool r)