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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_TF_CXX_CAST_H
8 #define PXR_BASE_TF_CXX_CAST_H
9 
10 /// \file tf/cxxCast.h
11 /// C++ Cast Utilities.
12 
13 #ifndef __cplusplus
14 #error This include file can only be included in C++ programs.
15 #endif
16 
17 #include "pxr/pxr.h"
18 #include <type_traits>
19 
21 
22 template <class Src, class Dst>
23 using Tf_CopyConst =
26 
27 template <class Src, class Dst>
28 using Tf_CopyVolatile =
31 
32 template <class Src, class Dst>
34 
35 /// Return a pointer to the most-derived object.
36 ///
37 /// A \c dynamic_cast to \c void* is legal only for pointers to polymorphic
38 /// objects. This function returns the original pointer for non-polymorphic
39 /// types, and a pointer to the most-derived type of the object.
40 /// Said differently, given a pointer of static type \c B*, and given that
41 /// the object really points to an object of type \c D*, this function
42 /// returns the address of the object considered as a \c D*; however, for
43 /// non-polymorphic objects, the actual type of an object is taken to be \c B,
44 /// since one cannot prove that that the type is actually different.
45 ///
46 /// \warning This function is public, but should be used sparingly (or not all).
47 template <typename T>
48 inline typename std::enable_if<
51 {
52  return dynamic_cast<Tf_CopyCV<T, void>*>(ptr);
53 }
54 
55 template <typename T>
56 inline typename std::enable_if<
59 {
60  return static_cast<Tf_CopyCV<T, void>*>(ptr);
61 }
62 
64 
65 #endif
type
Definition: core.h:556
GLsizei const GLfloat * value
Definition: glcorearb.h:824
typename std::conditional< std::is_const< Src >::value, typename std::add_const< Dst >::type, Dst >::type Tf_CopyConst
Definition: cxxCast.h:25
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
std::enable_if< std::is_polymorphic< T >::value, Tf_CopyCV< T, void > * >::type TfCastToMostDerivedType(T *ptr)
Definition: cxxCast.h:50
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
auto ptr(T p) -> const void *
Definition: format.h:4331
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Tf_CopyConst< Src, Tf_CopyVolatile< Src, Dst >> Tf_CopyCV
Definition: cxxCast.h:33
typename std::conditional< std::is_volatile< Src >::value, typename std::add_volatile< Dst >::type, Dst >::type Tf_CopyVolatile
Definition: cxxCast.h:30