24 #ifndef PXR_BASE_VT_OPERATORS_H
25 #define PXR_BASE_VT_OPERATORS_H
30 #include <hboost/utility/enable_if.hpp>
31 #include <hboost/type_traits/is_same.hpp>
78 #define VTOPERATOR_CPPARRAY(op) \
79 VtArray operator op (VtArray const &other) const { \
81 if ((size()!=0 && other.size()!=0) && \
82 (size() != other.size())) { \
83 TF_CODING_ERROR("Non-conforming inputs for operator %s",#op); \
87 const bool thisEmpty = size() == 0, \
88 otherEmpty = other.size() == 0; \
89 VtArray ret(thisEmpty ? other.size() : size()); \
90 ElementType zero = VtZero<ElementType>(); \
91 for (size_t i = 0, n = ret.size(); i != n; ++i) { \
92 ret[i] = (thisEmpty ? zero : (*this)[i]) op \
93 (otherEmpty ? zero : other[i]); \
98 #define VTOPERATOR_CPPARRAY_UNARY(op) \
99 VtArray operator op () const { \
100 VtArray ret(size()); \
101 for (size_t i = 0, sz = ret.size(); i != sz; ++i) { \
102 ret[i] = op (*this)[i]; \
109 #define VTOPERATOR_CPPSCALAR_TYPE(op,arraytype,scalartype,rettype) \
110 template<typename arraytype> \
112 operator op (scalartype const &scalar, \
113 VtArray<arraytype> const &vec) { \
114 VtArray<rettype> ret(vec.size()); \
115 for (size_t i = 0; i<vec.size(); ++i) { \
116 ret[i] = scalar op vec[i]; \
120 template<typename arraytype> \
122 operator op (VtArray<arraytype> const &vec, \
123 scalartype const &scalar) { \
124 VtArray<rettype> ret(vec.size()); \
125 for (size_t i = 0; i<vec.size(); ++i) { \
126 ret[i] = vec[i] op scalar; \
131 #define VTOPERATOR_CPPSCALAR(op) \
132 VTOPERATOR_CPPSCALAR_TYPE(op,ElemType,ElemType,ElemType)
137 #define VTOPERATOR_CPPSCALAR_DOUBLE(op) \
138 template<typename ElemType> \
139 typename hboost::disable_if<hboost::is_same<ElemType, double>, \
140 VtArray<ElemType> >::type \
141 operator op (double const &scalar, \
142 VtArray<ElemType> const &vec) { \
143 VtArray<ElemType> ret(vec.size()); \
144 for (size_t i = 0; i<vec.size(); ++i) { \
145 ret[i] = scalar op vec[i]; \
149 template<typename ElemType> \
150 typename hboost::disable_if<hboost::is_same<ElemType, double>, \
151 VtArray<ElemType> >::type \
152 operator op (VtArray<ElemType> const &vec, \
153 double const &scalar) { \
154 VtArray<ElemType> ret(vec.size()); \
155 for (size_t i = 0; i<vec.size(); ++i) { \
156 ret[i] = vec[i] op scalar; \
165 #endif // PXR_BASE_VT_OPERATORS_H
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE