Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_RCPBoostSharedPtrConversions.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_BOOST_SHAREDPTR_CONVERSIONS_HPP
11 #define TEUCHOS_RCP_BOOST_SHAREDPTR_CONVERSIONS_HPP
12 
14 #include "Teuchos_RCP.hpp"
15 
16 
17 template<class 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
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy.
Reference-counted pointer class and non-member templated function implementations.
bool nonnull(const ArrayRCP< T > &p)
Returns true if p.get()!=NULL.