Debian Codegraph @

packages/rol/src/compatibility/teuchos/rcp/ROL_Ptr.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #pragma once
11
12 #include <memory>
13 #include <type_traits>
14
15 /* \file ROL_Ptr.hpp
16 * \brief Provides unified interface Teuchos::RCP for legacy support.
17 * ROL will be build with this implementation by default
18 * unless ROL_ENABLE_STD_SHARED_PTR:BOOL=ON
19 */
20
21 #include <cstddef>
22 #include <utility>
23
24 #include "Teuchos_RCP.hpp"
25
26 namespace ROL {
27
28 template<class T> using Ptr = Teuchos::RCP<T>;
29
30 static const Teuchos::ENull nullPtr = Teuchos::null;
31
32 }
33
34 namespace ROL {
35
36 // Special case handling until C++14 (auto type deduction) is required
37 // because template type deduction does not work for initializer_list here.
38
39 template<class T, class U>
40 inline
41 Ptr<T> makePtr( std::initializer_list<U>&& u ) {
42 return Teuchos::rcp( new T(std::forward<std::initializer_list<U>>(u)) );
43 }
44
45
46 template<class T, class... Args>
47 inline
48 Ptr<T> makePtr( Args&&... args ) {
49 return Teuchos::rcp( new T(std::forward<Args>(args)...) );
50 }
51
52 template<class T>
53 inline
54 Ptr<T> makePtrFromRef( T& obj ) {
55 return Teuchos::rcpFromRef(obj);
56 }
57
58 template<class T, class U>
59 inline
60 Ptr<T> staticPtrCast( const Ptr<U>& r ) noexcept {
61 return Teuchos::rcp_static_cast<T>(r);
62 }
63
64 template< class T, class U >
65 inline
66 Ptr<T> constPtrCast( const Ptr<U>& r ) noexcept {
67 return Teuchos::rcp_const_cast<T>(r);
68 }
69
70 template< class T, class U >
71 inline
72 Ptr<T> dynamicPtrCast( const Ptr<U>& r ) noexcept {
73 return Teuchos::rcp_dynamic_cast<T>(r);
74 }
75
76 template<class T>
77 inline
78 const T* getRawPtr( const Ptr<const T>& x ) {
79 return x.get();
80 }
81
82 template<class T>
83 inline
84 T* getRawPtr( const Ptr<T>& x ) {
85 return x.get();
86 }
87
88 template<class T>
89 inline
90 int getCount( const Ptr<T>& x ) {
91 return x.strong_count();
92 }
93
94 template<class T>
95 inline
96 bool is_nullPtr( const Ptr<T>& x ) {
97 return x.is_null();
98 }
99
100 template<typename T>
101 inline
102 Ptr<T> toPtr( const Ptr<T>& ptr ) {
103 return ptr;
104 }
105
106 template<typename T>
107 inline
108 Ptr<const T> toPtr( const Ptr<const T>& ptr ) {
109 return ptr;
110 }
111
112 template<class T>
113 struct IsSharedPtr : public std::false_type {};
114
115 template<class T>
116 struct IsSharedPtr<std::shared_ptr<T>> : public std::true_type {};
117
118 } // namespace ROL
119