Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_RCPStdSharedPtrConversionsDecl.hpp
Go to the documentation of this file.
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_RCP_STD_SHAREDPTR_CONVERSIONS_DECL_HPP
11 #define TEUCHOS_RCP_STD_SHAREDPTR_CONVERSIONS_DECL_HPP
12 
13 #include "Teuchos_RCPDecl.hpp"
14 #include <memory>
15 
16 
17 namespace Teuchos {
18 
19 
39 template<class T>
41 {
42 public:
44  DeallocStdSharedPtr( const std::shared_ptr<T> &sptr ) : sptr_(sptr) {}
46  typedef T ptr_t;
48  void free( T* ptr_in ) const { sptr_.reset(); }
50  const std::shared_ptr<T>& ptr() const { return sptr_; }
51 private:
52  mutable std::shared_ptr<T> sptr_;
53  DeallocStdSharedPtr(); // Not defined and not to be called!
54 };
55 
56 
62 template<class T>
64 {
65 public:
67  StdSharedPtrRCPDeleter( const RCP<T> &rcp ) : rcp_(rcp) {}
69  typedef void result_type;
71  typedef T * argument_type;
73  void operator()(T * x) const { rcp_ = null; }
75  const RCP<T>& ptr() const { return rcp_; }
76 private:
77  mutable RCP<T> rcp_;
78  StdSharedPtrRCPDeleter(); // Not defined and not to be called!
79 };
80 
81 
92 template<class T>
93 RCP<T> rcp( const std::shared_ptr<T> &sptr );
94 
95 
107 template<class T>
108 std::shared_ptr<T> get_shared_ptr( const RCP<T> &rcp );
109 
110 
115 template<class T> inline
116 bool is_null( const std::shared_ptr<T> &p )
117 {
118  return p.get() == 0;
119 }
120 
121 
126 template<class T> inline
127 bool nonnull( const std::shared_ptr<T> &p )
128 {
129  return p.get() != 0;
130 }
131 
132 
133 } // namespace Teuchos
134 
135 
136 
137 #endif // TEUCHOS_RCP_STD_SHAREDPTR_CONVERSIONS_DECL_HPP
std::shared_ptr deleter class that wraps a Teuchos::RCP.
DeallocStdSharedPtr(const std::shared_ptr< T > &sptr)
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
const std::shared_ptr< T > & ptr() const
Teuchos::RCP Deallocator class that wraps a std::shared_ptr
Reference-counted pointer class and non-member templated function implementations.
Smart reference counting pointer class for automatic garbage collection.