Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_getBaseObjVoidPtr.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_GET_BASE_OBJ_VOID_PTR_HPP
11 #define TEUCHOS_GET_BASE_OBJ_VOID_PTR_HPP
12 
13 
14 #include "TeuchosCore_ConfigDefs.hpp"
15 #include "Teuchos_ConfigDefs.hpp"
16 
17 
18 #if defined(HAVE_TEUCHOSCORE_CXX11)
19 # define HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR 1
20 # include <type_traits>
21 #elif defined(HAVE_TEUCHOSCORE_BOOST) && defined(HAVE_TEUCHOSCORE_BOOST_IS_POLYMORPHIC)
22 # define HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR 1
23 # include <boost/type_traits/is_polymorphic.hpp>
24 #endif
25 
26 
27 namespace Teuchos {
28 
29 
30 #ifdef HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR
31 
32 
33 template<bool isPolymorphic, typename T>
34 class GetBaseObjVoidPtrImpl {};
35 
36 template<typename T>
37 class GetBaseObjVoidPtrImpl<true, T> {
38 public:
39  static const void* getBaseObjVoidPtr(T *p)
40  {
41  return dynamic_cast<const void*>(p);
42  }
43 };
44 
45 
46 template<typename T>
47 class GetBaseObjVoidPtrImpl<false, T> {
48 public:
49  static const void* getBaseObjVoidPtr(T *p)
50  {
51  return static_cast<const void*>(p);
52  }
53 };
54 
55 
72 template<typename T>
73 const void* getBaseObjVoidPtr(T *p)
74 {
75 #if defined(HAVE_TEUCHOSCORE_CXX11)
76  const bool isPoly = std::is_polymorphic<T>::value;
77 #elif defined(HAVE_TEUCHOSCORE_BOOST) && defined(HAVE_TEUCHOSCORE_BOOST_IS_POLYMORPHIC)
78  const bool isPoly = boost::is_polymorphic<T>::value;
79 #endif
80  typedef GetBaseObjVoidPtrImpl<isPoly, T> GBOVPT;
81  return GBOVPT::getBaseObjVoidPtr(p);
82 }
83 
84 
85 #endif // HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR
86 
87 
88 } // end namespace Teuchos
89 
90 
91 #endif // TEUCHOS_GET_BASE_OBJ_VOID_PTR_HPP
Teuchos header file which uses auto-configuration information to include necessary C++ headers...