HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
safeTypeCompare.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_SAFE_TYPE_COMPARE_H
8 #define PXR_BASE_TF_SAFE_TYPE_COMPARE_H
9 
10 /// \file tf/safeTypeCompare.h
11 /// \ingroup group_tf_RuntimeTyping
12 /// Safely compare C++ RTTI type structures.
13 
14 #include "pxr/pxr.h"
15 
16 #include <typeinfo>
17 
19 
20 /// Safely compare \c std::type_info structures.
21 ///
22 /// Returns \c true if \p t1 and \p t2 denote the same type.
23 inline bool TfSafeTypeCompare(const std::type_info& t1, const std::type_info& t2) {
24  return t1 == t2;
25 }
26 
27 /// Safely perform a dynamic cast.
28 ///
29 /// Usage should mirror regular \c dynamic_cast:
30 /// \code
31 /// Derived* d = TfSafeDynamic_cast<Derived*>(basePtr);
32 /// \endcode
33 ///
34 /// Note that this function also works with \c TfRefPtr and \c TfWeakPtr
35 /// managed objects.
36 template <typename TO, typename FROM>
37 TO
39  return dynamic_cast<TO>(ptr);
40 }
41 
43 
44 #endif // PXR_BASE_TF_SAFE_TYPE_COMPARE_H
TO TfSafeDynamic_cast(FROM *ptr)
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
PXR_NAMESPACE_OPEN_SCOPE bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)