Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_RCPStdSharedPtrConversionsDecl.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_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
17namespace Teuchos {
18
19
39template<class T>
41{
42public:
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_; }
51private:
52 mutable std::shared_ptr<T> sptr_;
53 DeallocStdSharedPtr(); // Not defined and not to be called!
54};
55
56
62template<class T>
64{
65public:
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_; }
76private:
77 mutable RCP<T> rcp_;
78 StdSharedPtrRCPDeleter(); // Not defined and not to be called!
79};
80
81
92template<class T>
93RCP<T> rcp( const std::shared_ptr<T> &sptr );
94
95
107template<class T>
108std::shared_ptr<T> get_shared_ptr( const RCP<T> &rcp );
109
110
115template<class T> inline
116bool is_null( const std::shared_ptr<T> &p )
117{
118 return p.get() == 0;
119}
120
121
126template<class T> inline
127bool 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
Reference-counted pointer class and non-member templated function implementations.
Teuchos::RCP Deallocator class that wraps a std::shared_ptr
DeallocStdSharedPtr(const std::shared_ptr< T > &sptr)
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcp(const std::shared_ptr< T > &sptr)
Conversion function that takes in a std::shared_ptr object and spits out a Teuchos::RCP object.
std::shared_ptr< T > get_shared_ptr(const RCP< T > &rcp)
Conversion function that takes in a Teuchos::RCP object and spits out a std::shared_ptr object.
T * get() const
Get the raw C++ pointer to the underlying object.
std::shared_ptr deleter class that wraps a Teuchos::RCP.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.