Poster of Linux kernelThe best gift for a Linux geek
AutoPtr

AutoPtr

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

AutoPtr -

A simple smart pointer providing strict ownership semantics.

 

SYNOPSIS


#include <auto_ptr.h>  

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.
AutoPtr & operator= (AutoPtr &a)
AutoPtr assignment operator.
template<typename Tp1 > AutoPtr & operator= (AutoPtr< Tp1 > &a)
AutoPtr assignment operator.
~AutoPtr ()

element_type & operator* () const
Smart pointer dereferencing.
element_type * operator-> () const
Smart pointer dereferencing.
element_type * get () const
Bypassing the smart pointer.
element_type * release ()
Bypassing the smart pointer.
void reset (element_type *p=0)
Forcibly deletes the managed object.



AutoPtr (AutoPtrRef< element_type > ref)
Automatic conversions.
AutoPtr & operator= (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 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 103 of file auto_ptr.h.  

Member Typedef Documentation

 

template<typename Tp> typedef Tp AutoPtr< Tp >::element_typeThe pointed-to type.

Definition at line 116 of file auto_ptr.h.  

Constructor & Destructor Documentation

 

template<typename Tp> 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 125 of file auto_ptr.h.

    : _ptr(p) {}
 

template<typename Tp> 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 135 of file auto_ptr.h.

    : _ptr(a.release()) {}
 

template<typename Tp> template<typename Tp1 > 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 148 of file auto_ptr.h.

    : _ptr(a.release()) {}
 

template<typename Tp> 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 196 of file auto_ptr.h.

{ delete _ptr; }
 

template<typename Tp> 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 278 of file auto_ptr.h.

    : _ptr(ref._ptr) {}
 

Member Function Documentation

 

template<typename Tp> element_type* 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 229 of file auto_ptr.h.

Referenced by __libmesh_petsc_diff_solver_jacobian(), __libmesh_petsc_diff_solver_residual(), ExactSolution::_compute_error(), UniformRefinementEstimator::_estimate_error(), NonlinearImplicitSystem::adjoint_solve(), FEMSystem::assembly(), System::calculate_norm(), Xdr::close(), Xdr::comment(), System::compare(), Problem_Interface::computeF(), ContinuationSystem::continuation_solve(), Xdr::data(), Xdr::data_stream(), AdaptiveTimeSolver::element_residual(), DofMap::enforce_constraints_exactly(), AdaptiveTimeSolver::error_order(), PatchRecoveryErrorEstimator::estimate_error(), JumpErrorEstimator::estimate_error(), ExactErrorEstimator::estimate_error(), FEMSystem::eulerian_residual(), TimeSolver::init(), AdaptiveTimeSolver::init(), DifferentiableSystem::init_data(), InfFE< Dim, T_radial, T_map >::inverse_map(), Xdr::is_open(), InfFE< Dim, T_radial, T_map >::map(), DofMap::max_constraint_error(), Xdr::open(), PostscriptIO::plot_quadratic_elem(), MeshBase::point_locator(), System::project_vector(), AdaptiveTimeSolver::reinit(), HPCoarsenTest::select_refinement(), AdaptiveTimeSolver::side_residual(), TwostepTimeSolver::solve(), PetscDiffSolver::solve(), and ContinuationSystem::solve_tangent().

{ return _ptr; }
 

template<typename Tp> template<typename Tp1 > AutoPtr< Tp >::operator AutoPtr< Tp1 > () [inline]op() for AutoPtr<Tp1>. Calls the release member.

Definition at line 309 of file auto_ptr.h.

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

template<typename Tp> template<typename Tp1 > AutoPtr< Tp >::operator AutoPtrRef< Tp1 > () [inline]op() for AutoPtrRef<Tp1>. Calls the release member.

Definition at line 302 of file auto_ptr.h.

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

template<typename Tp> element_type& 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 207 of file auto_ptr.h.

{ return *_ptr; }
 

template<typename Tp> element_type* 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 216 of file auto_ptr.h.

{ return _ptr; }
 

template<typename Tp> template<typename Tp1 > AutoPtr& 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 178 of file auto_ptr.h.

  {
    reset(a.release());
    return *this;
  }
 

template<typename Tp> AutoPtr& AutoPtr< Tp >::operator= (AutoPtrRef< element_type >ref) [inline]op= for AutoPtr. Allows you to write:

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


 

Definition at line 288 of file auto_ptr.h.

  {
    if (ref._ptr != this->get())
      {
        delete _ptr;
        _ptr = ref._ptr;
      }
    return *this;
  }
 

template<typename Tp> AutoPtr& 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 160 of file auto_ptr.h.

  {
    reset(a.release());
    return *this;
  }
 

template<typename Tp> element_type* 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 243 of file auto_ptr.h.

Referenced by UniformRefinementEstimator::_estimate_error(), InfFE< Dim, T_radial, T_map >::attach_quadrature_rule(), InfFE< Dim, T_radial, T_map >::Base::build_elem(), FEMContext::FEMContext(), InfFE< Dim, T_radial, T_map >::InfFE(), InfFE< Dim, T_radial, T_map >::init_face_shape_functions(), AutoPtr< LinearSolver< Number > >::operator AutoPtr< Tp1 >(), AutoPtr< LinearSolver< Number > >::operator AutoPtrRef< Tp1 >(), AutoPtr< LinearSolver< Number > >::operator=(), MeshBase::point_locator(), InfFE< Dim, T_radial, T_map >::reinit(), and AdaptiveTimeSolver::~AdaptiveTimeSolver().

  {
    element_type* tmp = _ptr;
    _ptr = 0;
    return tmp;
  }
 

template<typename Tp> void AutoPtr< Tp >::reset (element_type *p = 0) [inline]

Forcibly deletes the managed object. Parameters:

p A pointer (defaults to NULL).

This object now owns the object pointed to by p. The previous object has been deleted.

Definition at line 258 of file auto_ptr.h.

Referenced by UniformRefinementEstimator::_estimate_error(), AdaptiveTimeSolver::AdaptiveTimeSolver(), NonlinearSolver< T >::build(), MeshBase::clear_point_locator(), Xdr::close(), Xdr::open(), AutoPtr< LinearSolver< Number > >::operator=(), MeshBase::point_locator(), BoundaryInfo::sync(), and TwostepTimeSolver::TwostepTimeSolver().

  {
    if (p != _ptr)
      {
        delete _ptr;
        _ptr = p;
      }
  }
 

Member Data Documentation

 

template<typename Tp> Tp* AutoPtr< Tp >::_ptr [private]The actual dumb pointer this class wraps.

Definition at line 110 of file auto_ptr.h.

Referenced by AutoPtr< LinearSolver< Number > >::get(), AutoPtr< LinearSolver< Number > >::operator*(), AutoPtr< LinearSolver< Number > >::operator->(), AutoPtr< LinearSolver< Number > >::operator=(), AutoPtr< LinearSolver< Number > >::release(), AutoPtr< LinearSolver< Number > >::reset(), and AutoPtr< LinearSolver< Number > >::~AutoPtr().

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Types
Public Member Functions
Private Attributes
Detailed Description
template<typename Tp> class AutoPtr< Tp >
Member Typedef Documentation
template<typename Tp> typedef Tp AutoPtr< Tp >::element_typeThe pointed-to type.
Constructor & Destructor Documentation
template<typename Tp> AutoPtr< Tp >::AutoPtr (element_type *p = 0) [inline, explicit]
template<typename Tp> AutoPtr< Tp >::AutoPtr (AutoPtr< Tp > &a) [inline]
template<typename Tp> template<typename Tp1 > AutoPtr< Tp >::AutoPtr (AutoPtr< Tp1 > &a) [inline]
template<typename Tp> 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.
template<typename Tp> AutoPtr< Tp >::AutoPtr (AutoPtrRef< element_type >ref) [inline]
Member Function Documentation
template<typename Tp> element_type* AutoPtr< Tp >::get () const [inline]
template<typename Tp> template<typename Tp1 > AutoPtr< Tp >::operator AutoPtr< Tp1 > () [inline]op() for AutoPtr<Tp1>. Calls the release member.
template<typename Tp> template<typename Tp1 > AutoPtr< Tp >::operator AutoPtrRef< Tp1 > () [inline]op() for AutoPtrRef<Tp1>. Calls the release member.
template<typename Tp> element_type& AutoPtr< Tp >::operator* () const [inline]
template<typename Tp> element_type* AutoPtr< Tp >::operator-> () const [inline]
template<typename Tp> template<typename Tp1 > AutoPtr& AutoPtr< Tp >::operator= (AutoPtr< Tp1 > &a) [inline]
template<typename Tp> AutoPtr& AutoPtr< Tp >::operator= (AutoPtrRef< element_type >ref) [inline]op= for AutoPtr. Allows you to write:
template<typename Tp> AutoPtr& AutoPtr< Tp >::operator= (AutoPtr< Tp > &a) [inline]
template<typename Tp> element_type* AutoPtr< Tp >::release () [inline]
template<typename Tp> void AutoPtr< Tp >::reset (element_type *p = 0) [inline]
Member Data Documentation
template<typename Tp> Tp* AutoPtr< Tp >::_ptr [private]The actual dumb pointer this class wraps.
Author

This document was created by man2html, using the manual pages.
Time: 21:42:09 GMT, April 16, 2011