libMesh::AutoPtr< Tp > Class Template Reference

A simple smart pointer providing strict ownership semantics. More...

#include <auto_ptr.h>

List of all members.

Public Types

typedef Tp element_type

Public Member Functions

 AutoPtr (element_type *p=0)
 An AutoPtr is usually constructed from a raw pointer.
 AutoPtr (AutoPtr &a)
 An AutoPtr can be constructed from another AutoPtr.
template<typename Tp1 >
 AutoPtr (AutoPtr< Tp1 > &a)
 An AutoPtr can be constructed from another AutoPtr.
AutoPtroperator= (AutoPtr &a)
 AutoPtr assignment operator.
template<typename Tp1 >
AutoPtroperator= (AutoPtr< Tp1 > &a)
 AutoPtr assignment operator.
 ~AutoPtr ()
element_typeoperator* () const
 Smart pointer dereferencing.
element_typeoperator-> () const
 Smart pointer dereferencing.
element_typeget () const
 Bypassing the smart pointer.
element_typerelease ()
 Bypassing the smart pointer.
void reset (element_type *p=0)
 Forcibly deletes the managed object.



 AutoPtr (AutoPtrRef< element_type > ref)
 Automatic conversions.
AutoPtroperator= (AutoPtrRef< element_type > ref)
template<typename Tp1 >
 operator AutoPtrRef< Tp1 > ()
template<typename Tp1 >
 operator AutoPtr< Tp1 > ()

Private Attributes

Tp * _ptr

Detailed Description

template<typename Tp>
class libMesh::AutoPtr< Tp >

A simple smart pointer providing strict ownership semantics.

The Standard says:

  An AutoPtr owns the object it holds a pointer to.  Copying an
  AutoPtr copies the pointer and transfers ownership to the destination.
  If more than one AutoPtr owns the same object at the same time the
  behavior of the program is undefined.
  The uses of AutoPtr include providing temporary exception-safety for
  dynamically allocated memory, passing ownership of dynamically allocated
  memory to a function, and returning dynamically allocated memory from a
  function.  AutoPtr does not meet the CopyConstructible and Assignable
  requirements for Standard Library container
  elements and thus instantiating a Standard Library container with an
  AutoPtr results in undefined behavior.
  

Quoted from [20.4.5]/3.

This class is adopted from the GCC 3.2.1 source tree and should function as a replacement for std::auto_ptr<>. Unfortunately the std::auto_ptr<> is not particularly portable since various compilers implement various revisions of the standard. Using AutoPtr<> instead of std::auto_ptr<> allows for easy portability.

Definition at line 102 of file auto_ptr.h.


Member Typedef Documentation

template<typename Tp>
typedef Tp libMesh::AutoPtr< Tp >::element_type

The pointed-to type.

Definition at line 115 of file auto_ptr.h.


Constructor & Destructor Documentation

template<typename Tp>
libMesh::AutoPtr< Tp >::AutoPtr ( element_type p = 0  )  [inline, explicit]

An AutoPtr is usually constructed from a raw pointer.

Parameters:
p A pointer (defaults to NULL).

This object now owns the object pointed to by p.

Definition at line 124 of file auto_ptr.h.

00125     : _ptr(p) {}

template<typename Tp>
libMesh::AutoPtr< Tp >::AutoPtr ( AutoPtr< Tp > &  a  )  [inline]

An AutoPtr can be constructed from another AutoPtr.

Parameters:
a Another AutoPtr of the same type.

This object now owns the object previously owned by a, which has given up ownsership.

Definition at line 134 of file auto_ptr.h.

00135     : _ptr(a.release()) {}

template<typename Tp>
template<typename Tp1 >
libMesh::AutoPtr< Tp >::AutoPtr ( AutoPtr< Tp1 > &  a  )  [inline]

An AutoPtr can be constructed from another AutoPtr.

Parameters:
a Another AutoPtr of a different but related type.

A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.

This object now owns the object previously owned by a, which has given up ownsership.

Definition at line 147 of file auto_ptr.h.

00148     : _ptr(a.release()) {}

template<typename Tp>
libMesh::AutoPtr< Tp >::~AutoPtr (  )  [inline]

When the AutoPtr goes out of scope, the object it owns is deleted. If it no longer owns anything (i.e., get() is NULL), then this has no effect.

maint

Definition at line 195 of file auto_ptr.h.

00195 { delete _ptr; }

template<typename Tp>
libMesh::AutoPtr< Tp >::AutoPtr ( AutoPtrRef< element_type ref  )  [inline]

Automatic conversions.

These operations convert an AutoPtr into and from an AutoPtrRef automatically as needed. This allows constructs such as

    AutoPtr<Derived>  func_returning_AutoPtr(.....);
    ...
    AutoPtr<Base> ptr = func_returning_AutoPtr(.....);

Definition at line 277 of file auto_ptr.h.

00278     : _ptr(ref._ptr) {}


Member Function Documentation

template<typename Tp>
element_type* libMesh::AutoPtr< Tp >::get (  )  const [inline]

Bypassing the smart pointer.

Returns:
The raw pointer being managed.

You can get a copy of the pointer that this object owns, for situations such as passing to a function which only accepts a raw pointer.

Note:
This AutoPtr still owns the memory.

Definition at line 228 of file auto_ptr.h.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::ExactSolution::_compute_error(), libMesh::Elem::SideIter::_update_side_ptr(), libMesh::NonlinearImplicitSystem::assembly(), libMesh::FEMSystem::assembly(), libMesh::DofMap::attach_matrix(), libMesh::BoundaryProjectSolution::BoundaryProjectSolution(), libMesh::System::calculate_norm(), libMesh::DofMap::clear_sparsity(), libMesh::Xdr::close(), libMesh::Xdr::comment(), libMesh::System::compare(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ContinuationSystem::continuation_solve(), libMesh::Xdr::data(), libMesh::Xdr::data_stream(), libMesh::DirichletBoundary::DirichletBoundary(), DMFunction_libMesh(), DMJacobian_libMesh(), libMesh::Xdr::do_read(), libMesh::Xdr::do_write(), libMesh::AdaptiveTimeSolver::element_residual(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::AdaptiveTimeSolver::error_order(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::AdjointResidualErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::FEAbstract::get_fe_map(), libMesh::NonlinearImplicitSystem::get_linear_solve_parameters(), libMesh::DifferentiableSystem::get_linear_solve_parameters(), libMesh::LinearImplicitSystem::get_linear_solver(), libMesh::DifferentiableSystem::get_linear_solver(), libMesh::DifferentiableSystem::get_time_solver(), libMesh::TimeSolver::init(), libMesh::AdaptiveTimeSolver::init(), libMesh::DifferentiableSystem::init_data(), libMesh::InfFE< Dim, T_radial, T_map >::inverse_map(), libMesh::Xdr::is_open(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::InfFE< Dim, T_radial, T_map >::map(), libMesh::DofMap::max_constraint_error(), libMesh::MeshBase::MeshBase(), libMesh::Xdr::open(), libMesh::PostscriptIO::plot_quadratic_elem(), libMesh::MeshBase::point_locator(), libMesh::System::project_vector(), libMesh::ProjectFEMSolution::ProjectFEMSolution(), libMesh::ProjectSolution::ProjectSolution(), libMesh::TimeSolver::reinit(), libMesh::NonlinearImplicitSystem::reinit(), libMesh::DifferentiableSystem::reinit(), libMesh::AdaptiveTimeSolver::reinit(), libMesh::HPCoarsenTest::select_refinement(), libMesh::NonlinearImplicitSystem::set_solver_parameters(), libMesh::AdaptiveTimeSolver::side_residual(), libMesh::TwostepTimeSolver::solve(), libMesh::TimeSolver::solve(), libMesh::PetscDiffSolver::solve(), libMesh::NonlinearImplicitSystem::solve(), libMesh::NewtonSolver::solve(), libMesh::ContinuationSystem::solve_tangent(), libMesh::Parallel::StandardType< Point >::StandardType(), libMesh::Parallel::StandardType< VectorValue< T > >::StandardType(), libMesh::Parallel::StandardType< TypeVector< T > >::StandardType(), libMesh::MeshBase::sub_point_locator(), and libMesh::System::write_serialized_blocked_dof_objects().

00228 { return _ptr; }

template<typename Tp>
template<typename Tp1 >
libMesh::AutoPtr< Tp >::operator AutoPtr< Tp1 > (  )  [inline]

op() for AutoPtr<Tp1>. Calls the release member.

Definition at line 308 of file auto_ptr.h.

00309   { return AutoPtr<Tp1>(this->release()); }

template<typename Tp>
template<typename Tp1 >
libMesh::AutoPtr< Tp >::operator AutoPtrRef< Tp1 > (  )  [inline]

op() for AutoPtrRef<Tp1>. Calls the release member.

Definition at line 301 of file auto_ptr.h.

00302   { return AutoPtrRef<Tp1>(this->release()); }

template<typename Tp>
element_type& libMesh::AutoPtr< Tp >::operator* (  )  const [inline]

Smart pointer dereferencing.

If this AutoPtr no longer owns anything, then this operation will crash. (For a smart pointer, "no longer owns anything" is the same as being a null pointer, and you know what happens when you dereference one of those...)

Definition at line 206 of file auto_ptr.h.

00206 { return *_ptr; }

template<typename Tp>
element_type* libMesh::AutoPtr< Tp >::operator-> (  )  const [inline]

Smart pointer dereferencing.

This returns the pointer itself, which the language then will automatically cause to be dereferenced.

Definition at line 215 of file auto_ptr.h.

00215 { return _ptr; }

template<typename Tp>
AutoPtr& libMesh::AutoPtr< Tp >::operator= ( AutoPtrRef< element_type ref  )  [inline]

op= for AutoPtr. Allows you to write:

 AutoPtr<Base> ptr = func_returning_AutoPtr(.....);

Definition at line 287 of file auto_ptr.h.

00288   {
00289     if (ref._ptr != this->get())
00290       {
00291         delete _ptr;
00292         _ptr = ref._ptr;
00293       }
00294     return *this;
00295   }

template<typename Tp>
template<typename Tp1 >
AutoPtr& libMesh::AutoPtr< Tp >::operator= ( AutoPtr< Tp1 > &  a  )  [inline]

AutoPtr assignment operator.

Parameters:
a Another AutoPtr of a different but related type.

A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.

This object now owns the object previously owned by a, which has given up ownsership. The object that this one used to own and track has been deleted.

Definition at line 177 of file auto_ptr.h.

00178   {
00179     reset(a.release());
00180     return *this;
00181   }

template<typename Tp>
AutoPtr& libMesh::AutoPtr< Tp >::operator= ( AutoPtr< Tp > &  a  )  [inline]

AutoPtr assignment operator.

Parameters:
a Another AutoPtr of the same type.

This object now owns the object previously owned by a, which has given up ownsership. The object that this one used to own and track has been deleted.

Definition at line 159 of file auto_ptr.h.

00160   {
00161     reset(a.release());
00162     return *this;
00163   }

template<typename Tp>
element_type* libMesh::AutoPtr< Tp >::release (  )  [inline]

Bypassing the smart pointer.

Returns:
The raw pointer being managed.

You can get a copy of the pointer that this object owns, for situations such as passing to a function which only accepts a raw pointer.

Note:
This AutoPtr no longer owns the memory. When this object goes out of scope, nothing will happen.

Definition at line 242 of file auto_ptr.h.

Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::UnstructuredMesh::all_second_order(), libMesh::ExactSolution::attach_exact_deriv(), libMesh::ExactErrorEstimator::attach_exact_deriv(), libMesh::ExactSolution::attach_exact_value(), libMesh::ExactErrorEstimator::attach_exact_value(), libMesh::InfFE< Dim, T_radial, T_map >::attach_quadrature_rule(), libMesh::TransientSystem< Base >::clear(), libMesh::UnstructuredMesh::copy_nodes_and_elements(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::FEMContext::FEMContext(), libMesh::InfFE< Dim, T_radial, T_map >::InfFE(), libMesh::MeshFunction::init(), libMesh::InfFE< Dim, T_radial, T_map >::init_face_shape_functions(), libMesh::AutoPtr< LinearSolver< Number > >::operator AutoPtr< Tp1 >(), libMesh::AutoPtr< LinearSolver< Number > >::operator AutoPtrRef< Tp1 >(), libMesh::AutoPtr< LinearSolver< Number > >::operator=(), libMesh::LegacyXdrIO::read_mesh(), libMesh::GmshIO::read_mesh(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::Elem::refine(), libMesh::InfFE< Dim, T_radial, T_map >::reinit(), libMesh::MemorySolutionHistory::store(), libMesh::Parallel::unpack(), libMesh::Elem::PackedElem::unpack(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), libMesh::AdaptiveTimeSolver::~AdaptiveTimeSolver(), and libMesh::TransientSystem< Base >::~TransientSystem().

00243   {
00244     element_type* tmp = _ptr;
00245     _ptr = 0;
00246     return tmp;
00247   }


Member Data Documentation


The documentation for this class was generated from the following file:

Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:06 UTC

Hosted By:
SourceForge.net Logo