// @HEADER
// ***********************************************************************
//
// Teuchos: Common Tools Package
// Copyright (2004) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ***********************************************************************
// @HEADER
#ifndef TEUCHOS_RCP_SHAREDPTR_CONVERSIONS_DECL_HPP
#define TEUCHOS_RCP_SHAREDPTR_CONVERSIONS_DECL_HPP
#include "Teuchos_RCPDecl.hpp"
#include "boost/shared_ptr.hpp"
namespace Teuchos {
/** \defgroup Teuchos_RCPBoostSharedPtrConversions_grp Conversion utilities for going between Teuchos::RCP and boost::shared_ptr.
The smart pointer classes Teuchos::RCP and
boost::shared_ptr are easily compatible. The two templated
conversion functions Teuchos::rcp( const boost::shared_ptr & ) and
Teuchos::shared_pointer( const RCP & ) have been created
for converting back and forth.
The following code shows how to convert back and forth between these two smart
pointer types:
\ingroup teuchos_mem_mng_grp
*/
//@{
/** \brief Teuchos::RCP Deallocator class that wraps a
* boost::shared_ptr */
template
class DeallocBoostSharedPtr
{
public:
/** \brief. */
DeallocBoostSharedPtr( const boost::shared_ptr &sptr ) : sptr_(sptr) {}
/** \brief. */
typedef T ptr_t;
/** \brief. */
void free( T* ptr ) const { sptr_.reset(); }
/** \brief. */
const boost::shared_ptr& ptr() const { return sptr_; }
private:
mutable boost::shared_ptr sptr_;
DeallocBoostSharedPtr(); // Not defined and not to be called!
};
/** \brief boost::shared_ptr deleter class that wraps a
* Teuchos::RCP.
*/
template
class RCPDeleter
{
public:
/** \brief. */
RCPDeleter( const RCP &rcp ) : rcp_(rcp) {}
/** \brief. */
typedef void result_type;
/** \brief. */
typedef T * argument_type;
/** \brief. */
void operator()(T * x) const { rcp_ = null; }
/** \brief. */
const RCP& ptr() const { return rcp_; }
private:
mutable RCP rcp_;
RCPDeleter(); // Not defined and not to be called!
};
/** \brief Conversion function that takes in a boost::shared_ptr
* object and spits out a Teuchos::RCP object.
*
* If the input boost::shared_ptr already wraps a Teuchos::RCP
* object, then that Teuchos::RCP object will be copied and returned.
*
* This function is not complicated, just look at its defintion below.
*/
template
RCP rcp( const boost::shared_ptr &sptr );
/** \brief Conversion function that takes in a Teuchos::RCP
* object and spits out a boost::shared_ptr object.
*
* If the input Teuchos::RCP already wraps a
* boost::shared_ptr object, then that boost::shared_ptr
* object will be copied and returned.
*
* This function is not complicated, just look at its defintion below.
*/
template
boost::shared_ptr shared_pointer( const RCP &rcp );
//@}
} // namespace Teuchos
#endif // TEUCHOS_RCP_SHAREDPTR_CONVERSIONS_DECL_HPP