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 TF_TYPEFUNCTIONS_H
25 #define TF_TYPEFUNCTIONS_H
26 
29 
30 #include "pxr/pxr.h"
31 
32 #include <memory>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
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 
71  static void Class_Object_MUST_Not_Be_Const() { }
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 
87  static void Class_Object_MUST_Be_Passed_By_Address() { }
88  static void Class_Object_MUST_Not_Be_Const() { }
89 };
90 
91 template <class T>
92 struct TfTypeFunctions<const 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; }
102  static void Class_Object_MUST_Be_Passed_By_Address() { }
103 };
104 
113 template <class T>
115 {
116  static T* Apply(T value) {
117  return new T(value);
118  }
119 };
120 
121 template <class T>
122 struct TfCopyIfNotReference<T&>
123 {
124  static T* Apply(T& value) {
125  return &value;
126  }
127 };
128 
129 PXR_NAMESPACE_CLOSE_SCOPE
130 
131 #endif // TF_TYPEFUNCTIONS_H
TfCopyIfNotReference&lt;T&gt;::Apply(v) is used to return a pointer to the value v.
Implements assorted functions based on compile-time type information.
Definition: typeFunctions.h:54