HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
typeFunctions.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_TF_TYPE_FUNCTIONS_H
8 #define PXR_BASE_TF_TYPE_FUNCTIONS_H
9 
10 /// \file tf/typeFunctions.h
11 /// \ingroup group_tf_Internal
12 
13 #include "pxr/pxr.h"
14 
15 #include <memory>
16 
18 
19 /// \class TfTypeFunctions
20 /// \ingroup group_tf_Internal
21 ///
22 /// Implements assorted functions based on compile-time type information.
23 ///
24 /// TfTypeFunctions<T>::GetRawPtr(T* tPtr) returns tPtr. A smart-pointer
25 /// class, such as \c TfRefPtr, may specialize this function to have different
26 /// behavior. Note that for a non-pointer type, this returns the address of
27 /// the object, which allows one to uniformly apply the -> operator for member
28 /// function calls.
29 ///
30 /// TfTypeFunctions<T>::ConstructFromRawPtr(T* tPtr) returns tPtr.
31 /// Pointer-like objects should specialize this function so that given a raw
32 /// pointer of type T*, they return a smart pointer pointing to that object
33 /// (see refPtr.h for an example). Essentially, this is the inverse of
34 /// TfTypeFunctions<T>::GetRawPtr.
35 ///
36 template <class T, class ENABLE = void>
38 #if 0
39  static T* GetRawPtr(T& t) {
40  return &t;
41  }
42 #endif
43 
44  static const T* GetRawPtr(const T& t) {
45  return &t;
46  }
47 
48  static T& ConstructFromRawPtr(T* ptr) { return *ptr; }
49 
50  static bool IsNull(const T&) {
51  return false;
52  }
53 
55  static void Object_CANNOT_Be_a_Pointer() { }
56 };
57 
58 template <class T>
59 struct TfTypeFunctions<T*> {
60  static T* GetRawPtr(T* t) {
61  return t;
62  }
63 
64  static T* ConstructFromRawPtr(T* ptr) { return ptr; }
65 
66  static bool IsNull(T* ptr) {
67  return !ptr;
68  }
69 
72 };
73 
74 template <class T>
75 struct TfTypeFunctions<const T*> {
76  static const T* GetRawPtr(const T* t) {
77  return t;
78  }
79 
80  static bool IsNull(const T* ptr) {
81  return !ptr;
82  }
83 
84  static const T* ConstructFromRawPtr(T* ptr) { return ptr; }
86 };
87 
89 
90 #endif // PXR_BASE_TF_TYPE_FUNCTIONS_H
static bool IsNull(const T &)
Definition: typeFunctions.h:50
static T * ConstructFromRawPtr(T *ptr)
Definition: typeFunctions.h:64
static void Class_Object_MUST_Be_Passed_By_Address()
Definition: typeFunctions.h:70
static void Object_CANNOT_Be_a_Pointer()
Definition: typeFunctions.h:55
static bool IsNull(T *ptr)
Definition: typeFunctions.h:66
static T * GetRawPtr(T *t)
Definition: typeFunctions.h:60
static const T * ConstructFromRawPtr(T *ptr)
Definition: typeFunctions.h:84
static void Class_Object_MUST_Not_Be_Const()
Definition: typeFunctions.h:71
GLdouble t
Definition: glad.h:2397
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static T & ConstructFromRawPtr(T *ptr)
Definition: typeFunctions.h:48
auto ptr(T p) -> const void *
Definition: format.h:4331
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static const T * GetRawPtr(const T *t)
Definition: typeFunctions.h:76
static const T * GetRawPtr(const T &t)
Definition: typeFunctions.h:44
static void Class_Object_MUST_Not_Be_Const()
Definition: typeFunctions.h:54
static bool IsNull(const T *ptr)
Definition: typeFunctions.h:80
static void Class_Object_MUST_Be_Passed_By_Address()
Definition: typeFunctions.h:85