Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
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
17template<class T>
19Teuchos::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
44template<class T>
45boost::shared_ptr<T>
46Teuchos::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
Reference-counted pointer class and non-member templated function implementations.
Smart reference counting pointer class for automatic garbage collection.
Ptr< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
T * get() const
Get the raw C++ pointer to the underlying object.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.