All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
internalTraits.h
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef VTKATANA_INTERNALTRAITS_H
25 #define VTKATANA_INTERNALTRAITS_H
26 
27 #include "pxr/pxr.h"
28 #include "vtKatana/traits.h"
29 
30 PXR_NAMESPACE_OPEN_SCOPE
31 
34 template <typename T, typename = void>
37  static const size_t value = 1;
38 };
39 
41 template <typename T>
43  T, typename std::enable_if<std::is_arithmetic<T>::value>::type> {
44  static const size_t value = 1;
45 };
46 
48 template <>
50  static const size_t value = 1;
51 };
52 
54 template <typename T>
56  T, typename std::enable_if<GfIsGfVec<T>::value>::type> {
57  static const size_t value = T::dimension;
58 };
59 
63 template <typename T>
65  T, typename std::enable_if<GfIsGfMatrix<T>::value>::type> {
66  static const size_t value = T::numRows * T::numColumns;
67 };
68 
76 template <typename T>
78  typedef void type;
79 };
80 
81 template <>
83  typedef GfVec2f type;
84 };
85 
86 template <>
88  typedef GfVec3f type;
89 };
90 
91 template <>
93  typedef GfVec4f type;
94 };
95 
98 template <typename T>
100  : public std::integral_constant<
101  bool,
102  VtKatana_IsNumeric<T>::value &&
103  std::is_same<
104  typename VtKatana_GetNumericScalarType<T>::type,
105  typename VtKatana_GetKatanaAttrValueType<T>::type>::value> {};
106 
109 template <typename T>
111  : public std::integral_constant<
112  bool, VtKatana_IsNumeric<T>::value &&
113  VtKatana_GetNumericTupleSize<T>::value == 1> {};
114 
116 template <typename T>
118  : public std::integral_constant<bool,
119  VtKatana_IsNumeric<T>::value &&
120  !VtKatana_IsNumericScalar<T>::value> {};
121 
123 template <typename T>
125  : public std::integral_constant<bool,
126  VtKatana_IsNumericCastable<T>::value &&
127  VtKatana_IsNumericScalar<T>::value> {};
128 
130 template <typename T>
132  : public std::integral_constant<bool,
133  VtKatana_IsNumericCastable<T>::value &&
134  VtKatana_IsNumericTuple<T>::value> {};
135 
138 template <typename T>
140  : public std::integral_constant<bool,
141  VtKatana_IsNumeric<T>::value &&
142  !VtKatana_IsNumericCastable<T>::value> {
143 };
144 
146 template <typename T>
148  : public std::integral_constant<bool,
149  VtKatana_IsNumericCopyRequired<T>::value &&
150  VtKatana_IsNumericScalar<T>::value> {};
151 
153 template <typename T>
155  : public std::integral_constant<bool,
156  VtKatana_IsNumericCopyRequired<T>::value &&
157  VtKatana_IsNumericTuple<T>::value> {};
158 
165 template <typename T, typename = typename std::enable_if<
167 const char* VtKatana_GetText(const T&);
168 
170 template <>
171 const char* VtKatana_GetText<std::string>(const std::string& string);
172 
174 template <>
175 const char* VtKatana_GetText<TfToken>(const TfToken& token);
176 
179 template <>
180 const char* VtKatana_GetText<SdfAssetPath>(const SdfAssetPath& assetPath);
181 
183 template <>
184 const char* VtKatana_GetText<SdfPath>(const SdfPath& path);
185 
187 template <typename T>
188 typename std::enable_if<VtKatana_IsNumericScalar<T>::value, const T*>::type
189 VtKatana_GetScalarPtr(const VtArray<T>& array) {
190  return array.cdata();
191 };
192 
194 template <typename T>
195 typename std::enable_if<
197  const typename VtKatana_GetNumericScalarType<T>::type*>::type
198 VtKatana_GetScalarPtr(const VtArray<T>& array) {
199  typedef typename VtKatana_GetNumericScalarType<T>::type ScalarType;
200  TF_VERIFY(array.size() > 0);
201  return array.cdata()->data();
202 };
203 
205 template <typename T>
206 typename std::enable_if<VtKatana_IsNumericCastableScalar<T>::value,
207  const T*>::type
208 VtKatana_GetVtPtr(
209  const typename VtKatana_GetKatanaAttrType<T>::type::array_type& sample) {
210  return sample.data();
211 };
212 
214 template <typename T>
215 typename std::enable_if<VtKatana_IsNumericCastable<T>::value,
216  bool>::type
217 VtKatana_IsSampleAligned(
218  const typename VtKatana_GetKatanaAttrType<T>::type::array_type& sample){
219  auto data = sample.data();
220  return ((size_t)data) % alignof(T) == 0;
221 }
222 
227 template <typename T>
228 typename std::enable_if<VtKatana_IsNumericCastableTuple<T>::value,
229  const T*>::type
230 VtKatana_GetVtPtr(
231  const typename VtKatana_GetKatanaAttrType<T>::type::array_type& sample) {
232  TF_VERIFY(VtKatana_IsSampleAligned<T>(sample));
233  return reinterpret_cast<const T*>(sample.data());
234 };
235 
236 PXR_NAMESPACE_CLOSE_SCOPE
237 
238 #endif
Gets the &#39;tuple size&#39; of T, or number of elements a numeric type contains.
pxr_half::half GfHalf
A 16-bit floating point data type.
Definition: half.h:42
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
Basic type for a vector of 4 GfHalf components.
Definition: vec4h.h:64
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
const_pointer cdata() const
Return a const pointer to the data held by this array.
Definition: array.h:387
If true, this type always requires an intermediate copy, and cannot support the zero copy feature set...
Basic type for a vector of 2 GfHalf components.
Definition: vec2h.h:64
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:289
size_t size() const
Return the total number of elements in this array.
Definition: array.h:428
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
static const size_t value
TODO: Can we remove this so only numeric types have tuple sizes defined?
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
Contains an asset path and an optional resolved path.
Definition: assetPath.h:43
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
Every Numeric and String type can be mapped to a single Katana Attribute Type.
Definition: traits.h:151
Castable numeric types don&#39;t require intermediate copies, and allows for ZeroCopy behavior...
Basic type for a vector of 3 GfHalf components.
Definition: vec3h.h:64
If true, the element represents a matrix or vector value.
If true, the element represents a single value (ie.
This trait is highly specialized for GfHalf types.