HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxxCast.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_CXX_CAST_H
25 #define PXR_BASE_TF_CXX_CAST_H
26 
27 /// \file tf/cxxCast.h
28 /// C++ Cast Utilities.
29 
30 #ifndef __cplusplus
31 #error This include file can only be included in C++ programs.
32 #endif
33 
34 #include "pxr/pxr.h"
35 #include <type_traits>
36 
38 
39 template <class Src, class Dst>
40 using Tf_CopyConst =
43 
44 template <class Src, class Dst>
45 using Tf_CopyVolatile =
48 
49 template <class Src, class Dst>
51 
52 /// Return a pointer to the most-derived object.
53 ///
54 /// A \c dynamic_cast to \c void* is legal only for pointers to polymorphic
55 /// objects. This function returns the original pointer for non-polymorphic
56 /// types, and a pointer to the most-derived type of the object.
57 /// Said differently, given a pointer of static type \c B*, and given that
58 /// the object really points to an object of type \c D*, this function
59 /// returns the address of the object considered as a \c D*; however, for
60 /// non-polymorphic objects, the actual type of an object is taken to be \c B,
61 /// since one cannot prove that that the type is actually different.
62 ///
63 /// \warning This function is public, but should be used sparingly (or not all).
64 template <typename T>
65 inline typename std::enable_if<
68 {
69  return dynamic_cast<Tf_CopyCV<T, void>*>(ptr);
70 }
71 
72 template <typename T>
73 inline typename std::enable_if<
76 {
77  return static_cast<Tf_CopyCV<T, void>*>(ptr);
78 }
79 
81 
82 #endif
typename std::conditional< std::is_const< Src >::value, typename std::add_const< Dst >::type, Dst >::type Tf_CopyConst
Definition: cxxCast.h:42
std::enable_if< std::is_polymorphic< T >::value, Tf_CopyCV< T, void > * >::type TfCastToMostDerivedType(T *ptr)
Definition: cxxCast.h:67
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
const void * ptr(const T *p)
Definition: format.h:3292
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
Tf_CopyConst< Src, Tf_CopyVolatile< Src, Dst >> Tf_CopyCV
Definition: cxxCast.h:50
typename std::conditional< std::is_volatile< Src >::value, typename std::add_volatile< Dst >::type, Dst >::type Tf_CopyVolatile
Definition: cxxCast.h:47
GLsizei const GLfloat * value
Definition: glew.h:1849
type
Definition: core.h:528