All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
traits.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 TF_TRAITS_H
25 #define TF_TRAITS_H
26 
29 
30 #include "pxr/pxr.h"
31 
32 #include <boost/utility/enable_if.hpp>
33 #include <boost/type_traits/is_base_of.hpp>
34 #include <boost/type_traits/is_const.hpp>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 class TfWeakPtrFacadeBase;
39 template <class T> class TfRefPtr;
40 
144 struct TfTraits {
145 
146  template <class T, class Enable = void>
147  struct Type {
148  typedef T UnderlyingType;
149  typedef T NoRefType;
150  typedef T& RefType;
151  typedef T* PointerType;
152  typedef const T& AvoidCopyingType;
153  typedef T& PtrOrRefType;
154 
155  static const bool isPointer = false;
156  static const bool isReference = false;
157  static const bool isConst = false;
158  };
159 
160  template <class T>
161  struct Type<const T> {
162  typedef T UnderlyingType;
163  typedef const T NoRefType;
164  typedef const T& RefType;
165  typedef const T* PointerType;
166  typedef const T& AvoidCopyingType;
167  typedef const T& PtrOrRefType;
168 
169  static const bool isPointer = false;
170  static const bool isReference = false;
171  static const bool isConst = true;
172  };
173 
174  template <class T>
175  struct Type<T*> {
176  typedef T UnderlyingType;
177  typedef T* NoRefType;
178  typedef T*& RefType;
179  typedef T** PointerType;
180  typedef T* AvoidCopyingType;
181  typedef T* PtrOrRefType;
182  static const bool isPointer = true;
183  static const bool isReference = false;
184  static const bool isConst = false;
185  };
186 
187  template <class T>
188  struct Type<const T*> {
189  typedef T UnderlyingType;
190  typedef const T* NoRefType;
191  typedef const T*& RefType;
192  typedef const T** PointerType;
193  typedef const T* AvoidCopyingType;
194  typedef const T* PtrOrRefType;
195  static const bool isPointer = true;
196  static const bool isReference = false;
197  static const bool isConst = true;
198  };
199 
200  template <class T>
201  struct Type<T[]> {
202  typedef T UnderlyingType;
203  typedef T* NoRefType;
204  typedef T** PointerType;
205  typedef T* AvoidCopyingType;
206  typedef T* PtrOrRefType;
207  static const bool isPointer = true;
208  static const bool isReference = false;
209  static const bool isConst = false;
210  };
211 
212  template <class T>
213  struct Type<const T[]> {
214  typedef T UnderlyingType;
215  typedef const T* NoRefType;
216  typedef const T** PointerType;
217  typedef const T* AvoidCopyingType;
218  typedef const T* PtrOrRefType;
219  static const bool isPointer = true;
220  static const bool isReference = false;
221  static const bool isConst = true;
222  };
223 
224  template <class T, int n>
225  struct Type<T[n]> {
226  typedef T UnderlyingType;
227  typedef T* NoRefType;
228  typedef T** PointerType;
229  typedef T* AvoidCopyingType;
230  typedef T* PtrOrRefType;
231  static const bool isPointer = true;
232  static const bool isReference = false;
233  static const bool isConst = false;
234  };
235 
236  template <class T, int n>
237  struct Type<const T[n]> {
238  typedef T UnderlyingType;
239  typedef const T* NoRefType;
240  typedef const T** PointerType;
241  typedef const T* AvoidCopyingType;
242  typedef const T* PtrOrRefType;
243  static const bool isPointer = true;
244  static const bool isReference = false;
245  static const bool isConst = true;
246  };
247 
248  template <class T>
249  struct Type<T&> {
250  typedef T UnderlyingType;
251  typedef T NoRefType;
252  typedef T& RefType;
253  typedef T* PointerType;
254  typedef T& AvoidCopyingType;
255  typedef T& PtrOrRefType;
256  static const bool isPointer = false;
257  static const bool isReference = true;
258  static const bool isConst = false;
259  };
260 
261  template <class T>
262  struct Type<const T&> {
263  typedef T UnderlyingType;
264  typedef T NoRefType;
265  typedef const T& RefType;
266  typedef const T* PointerType;
267  typedef const T& AvoidCopyingType;
268  typedef const T& PtrOrRefType;
269  static const bool isPointer = false;
270  static const bool isReference = true;
271  static const bool isConst = true;
272  };
273 
274 
275  template <template <class> class Ptr, class T>
276  struct Type<Ptr<T>,
277  typename boost::enable_if<
278  boost::is_base_of<TfWeakPtrFacadeBase, Ptr<T> >
279  >::type>
280  {
281  typedef T UnderlyingType;
282  typedef Ptr<T> NoRefType;
283  typedef Ptr<T> &RefType;
284  typedef Ptr<T>* PointerType;
285  typedef Ptr<T> AvoidCopyingType;
286  typedef Ptr<T> PtrOrRefType;
287  static const bool isPointer = true;
288  static const bool isReference = false;
289  static const bool isConst = boost::is_const<T>::value;
290  };
291 
292  template <template <class> class Ptr, class T>
293  struct Type<Ptr<T> &,
294  typename boost::enable_if<
295  boost::is_base_of<TfWeakPtrFacadeBase, Ptr<T> >
296  >::type>
297  {
298  typedef T UnderlyingType;
299  typedef Ptr<T> NoRefType;
300  typedef Ptr<T> &RefType;
301  typedef Ptr<T>* PointerType;
302  typedef Ptr<T> AvoidCopyingType;
303  typedef Ptr<T> PtrOrRefType;
304  static const bool isPointer = true;
305  static const bool isReference = false;
306  static const bool isConst = boost::is_const<T>::value;
307  };
308 
309  template <class T>
310  struct Type<TfRefPtr<T> > {
311  typedef T UnderlyingType;
312  typedef TfRefPtr<T> NoRefType;
313  typedef TfRefPtr<T>& RefType;
314  typedef TfRefPtr<T>* PointerType;
315  typedef TfRefPtr<T> AvoidCopyingType;
316  typedef TfRefPtr<T> PtrOrRefType;
317  static const bool isPointer = true;
318  static const bool isReference = false;
319  static const bool isConst = boost::is_const<T>::value;
320  };
321 
322  template <class T>
323  struct Type<const TfRefPtr<T>&> {
324  typedef T UnderlyingType;
325  typedef TfRefPtr<T> NoRefType;
326  typedef TfRefPtr<T>& RefType;
327  typedef TfRefPtr<T>* PointerType;
328  typedef TfRefPtr<T> AvoidCopyingType;
329  typedef TfRefPtr<T> PtrOrRefType;
330  static const bool isPointer = true;
331  static const bool isReference = false;
332  static const bool isConst = boost::is_const<T>::value;
333  };
334 
335  template <class T>
336  struct Type<TfRefPtr<const T> > {
337  typedef T UnderlyingType;
338  typedef TfRefPtr<const T> NoRefType;
339  typedef TfRefPtr<const T>& RefType;
340  typedef TfRefPtr<const T>* PointerType;
341  typedef TfRefPtr<const T> AvoidCopyingType;
342  typedef TfRefPtr<const T> PtrOrRefType;
343  static const bool isPointer = true;
344  static const bool isReference = false;
345  static const bool isConst = true;
346  };
347 
348  template <class T>
349  struct Type<const TfRefPtr<const T>&> {
350  typedef T UnderlyingType;
351  typedef TfRefPtr<const T> NoRefType;
352  typedef TfRefPtr<const T>& RefType;
353  typedef TfRefPtr<const T>* PointerType;
354  typedef TfRefPtr<const T> AvoidCopyingType;
355  typedef TfRefPtr<const T> PtrOrRefType;
356  static const bool isPointer = true;
357  static const bool isReference = false;
358  static const bool isConst = true;
359  };
360 };
361 
362 template <>
363 struct TfTraits::Type<void*> {
364  typedef void* UnderlyingType;
365  typedef void* NoRefType;
366  typedef void*& RefType;
367  typedef void** PointerType;
368  typedef void* AvoidCopyingType;
369  typedef void* PtrOrRefType;
370  static const bool isPointer = true;
371  static const bool isReference = false;
372  static const bool isConst = false;
373 };
374 
375 template <>
376 struct TfTraits::Type<const void*> {
377  typedef void* UnderlyingType;
378  typedef const void* NoRefType;
379  typedef const void*& RefType;
380  typedef const void** PointerType;
381  typedef const void* AvoidCopyingType;
382  typedef const void* PtrOrRefType;
383  static const bool isPointer = true;
384  static const bool isReference = false;
385  static const bool isConst = true;
386 };
387 
388 PXR_NAMESPACE_CLOSE_SCOPE
389 
390 #endif // TF_TRAITS_H
Reference-counted smart pointer utility class.
Definition: hash.h:45
Type-querying abilities.
Definition: traits.h:144