Teuchos - Trilinos Tools Package
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
Teuchos_RCPBoostSharedPtrConversions.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_BOOST_SHAREDPTR_CONVERSIONS_HPP
11
#define TEUCHOS_RCP_BOOST_SHAREDPTR_CONVERSIONS_HPP
12
13
#include "Teuchos_RCPBoostSharedPtrConversionsDecl.hpp"
14
#include "
Teuchos_RCP.hpp
"
15
16
17
template
<
class
T>
18
Teuchos::RCP<T>
19
Teuchos::rcp
(
const
boost::shared_ptr<T> &sptr )
20
{
21
if
(
nonnull
(sptr)) {
22
// First, see if the RCP is in the shared_ptr deleter object
23
const
RCPDeleter<T>
24
*rcpd = boost::get_deleter<RCPDeleter<T> >(sptr);
25
if
(rcpd) {
26
return
rcpd->ptr();
27
}
28
#ifdef TEUCHOS_DEBUG
29
// Second, see if the an RCP node pointing to this type already exists
30
// from being wrapped already from a prior call to this function where the
31
// add_new_RCPNode(...) function could have been called already!.
32
RCPNode* existingRCPNode = RCPNodeTracer::getExistingRCPNode(sptr.get());
33
if
(existingRCPNode) {
34
return
RCP<T>(sptr.get(), RCPNodeHandle(existingRCPNode, RCP_STRONG,
false
));
35
}
36
#endif
37
// Lastly, we just create a new RCP and RCPNode ...
38
return
rcpWithDealloc
(sptr.get(), DeallocBoostSharedPtr<T>(sptr),
true
);
39
}
40
return
null;
41
}
42
43
44
template
<
class
T>
45
boost::shared_ptr<T>
46
Teuchos::shared_pointer
(
const
RCP<T> &rcp )
47
{
48
if
(
nonnull
(rcp)) {
49
Ptr<const DeallocBoostSharedPtr<T> >
50
dbsp = get_optional_dealloc<DeallocBoostSharedPtr<T> >(
rcp
);
51
if
(
nonnull
(dbsp))
52
return
dbsp->ptr();
53
return
boost::shared_ptr<T>(
rcp
.get(), RCPDeleter<T>(rcp));
54
}
55
return
boost::shared_ptr<T>();
56
}
57
58
59
#endif
// TEUCHOS_RCP_BOOST_SHAREDPTR_CONVERSIONS_HPP
Teuchos_RCP.hpp
Reference-counted pointer class and non-member templated function implementations.
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:397
Teuchos::RCP::rcpWithDealloc
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy.
Teuchos::RCP::shared_pointer
boost::shared_ptr< T > shared_pointer(const RCP< T > &rcp)
Conversion function that takes in a Teuchos::RCP object and spits out a boost::shared_ptr object.
boost::nonnull
bool nonnull(const boost::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
Definition
Teuchos_RCPBoostSharedPtrConversionsDecl.hpp:133
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Definition
Teuchos_RCPDecl.hpp:1234
Generated by
1.17.0