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 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 PXR_BASE_TF_TYPE_FUNCTIONS_H
25 #define PXR_BASE_TF_TYPE_FUNCTIONS_H
26 
27 /// \file tf/typeFunctions.h
28 /// \ingroup group_tf_Internal
29 
30 #include "pxr/pxr.h"
31 
32 #include <memory>
33 
35 
36 /// \class TfTypeFunctions
37 /// \ingroup group_tf_Internal
38 ///
39 /// Implements assorted functions based on compile-time type information.
40 ///
41 /// TfTypeFunctions<T>::GetRawPtr(T* tPtr) returns tPtr. A smart-pointer
42 /// class, such as \c TfRefPtr, may specialize this function to have different
43 /// behavior. Note that for a non-pointer type, this returns the address of
44 /// the object, which allows one to uniformly apply the -> operator for member
45 /// function calls.
46 ///
47 /// TfTypeFunctions<T>::ConstructFromRawPtr(T* tPtr) returns tPtr.
48 /// Pointer-like objects should specialize this function so that given a raw
49 /// pointer of type T*, they return a smart pointer pointing to that object
50 /// (see refPtr.h for an example). Essentially, this is the inverse of
51 /// TfTypeFunctions<T>::GetRawPtr.
52 ///
53 template <class T, class ENABLE = void>
55 #if 0
56  static T* GetRawPtr(T& t) {
57  return &t;
58  }
59 #endif
60 
61  static const T* GetRawPtr(const T& t) {
62  return &t;
63  }
64 
65  static T& ConstructFromRawPtr(T* ptr) { return *ptr; }
66 
67  static bool IsNull(const T&) {
68  return false;
69  }
70 
72  static void Object_CANNOT_Be_a_Pointer() { }
73 };
74 
75 template <class T>
76 struct TfTypeFunctions<T*> {
77  static T* GetRawPtr(T* t) {
78  return t;
79  }
80 
81  static T* ConstructFromRawPtr(T* ptr) { return ptr; }
82 
83  static bool IsNull(T* ptr) {
84  return !ptr;
85  }
86 
89 };
90 
91 template <class T>
93  static const T* GetRawPtr(const T* t) {
94  return t;
95  }
96 
97  static bool IsNull(const T* ptr) {
98  return !ptr;
99  }
100 
101  static const T* ConstructFromRawPtr(T* ptr) { return ptr; }
103 };
104 
105 /// \class TfCopyIfNotReference
106 /// \ingroup group_tf_Internal
107 ///
108 /// \c TfCopyIfNotReference<T>::Apply(v) is used to return a pointer to the
109 /// value \p v. If \c T is a non-reference type, then the value returned
110 /// points to newly constructed dynamic space, which the caller must free.
111 /// Otherwise, the returned value is the address of \p v.
112 ///
113 template <class T>
115 {
116  static T* Apply(T value) {
117  return new T(value);
118  }
119 };
120 
121 template <class T>
123 {
124  static T* Apply(T& value) {
125  return &value;
126  }
127 };
128 
130 
131 #endif // PXR_BASE_TF_TYPE_FUNCTIONS_H
static bool IsNull(const T &)
Definition: typeFunctions.h:67
static T * ConstructFromRawPtr(T *ptr)
Definition: typeFunctions.h:81
static T * Apply(T value)
static T * Apply(T &value)
static void Class_Object_MUST_Be_Passed_By_Address()
Definition: typeFunctions.h:87
static void Object_CANNOT_Be_a_Pointer()
Definition: typeFunctions.h:72
static bool IsNull(T *ptr)
Definition: typeFunctions.h:83
static T * GetRawPtr(T *t)
Definition: typeFunctions.h:77
static const T * ConstructFromRawPtr(T *ptr)
static void Class_Object_MUST_Not_Be_Const()
Definition: typeFunctions.h:88
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
const void * ptr(const T *p)
Definition: format.h:3292
static T & ConstructFromRawPtr(T *ptr)
Definition: typeFunctions.h:65
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
static const T * GetRawPtr(const T *t)
Definition: typeFunctions.h:93
static const T * GetRawPtr(const T &t)
Definition: typeFunctions.h:61
#define const
Definition: zconf.h:214
static void Class_Object_MUST_Not_Be_Const()
Definition: typeFunctions.h:71
static bool IsNull(const T *ptr)
Definition: typeFunctions.h:97
GLsizei const GLfloat * value
Definition: glew.h:1849
GLdouble GLdouble t
Definition: glew.h:1398
static void Class_Object_MUST_Be_Passed_By_Address()