libMesh::AutoPtr< Tp > Class Template Reference

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

#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. More...
 
 AutoPtr (AutoPtr &a)
 An AutoPtr can be constructed from another AutoPtr. More...
 
template<typename Tp1 >
 AutoPtr (AutoPtr< Tp1 > &a)
 An AutoPtr can be constructed from another AutoPtr. More...
 
AutoPtroperator= (AutoPtr &a)
 AutoPtr assignment operator. More...
 
template<typename Tp1 >
AutoPtroperator= (AutoPtr< Tp1 > &a)
 AutoPtr assignment operator. More...
 
 ~AutoPtr ()
 
element_typeoperator* () const
 Smart pointer dereferencing. More...
 
element_typeoperator-> () const
 Smart pointer dereferencing. More...
 
element_typeget () const
 Bypassing the smart pointer. More...
 
element_typerelease ()
 Bypassing the smart pointer. More...
 
void reset (element_type *p=0)
 Forcibly deletes the managed object. More...
 
 AutoPtr (AutoPtrRef< element_type > ref)
 Automatic conversions. More...
 
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)
inlineexplicit

An AutoPtr is usually constructed from a raw pointer.

Parameters
pA pointer (defaults to NULL).

This object now owns the object pointed to by p.

Definition at line 124 of file auto_ptr.h.

125  : _ptr(p) {}
template<typename Tp>
libMesh::AutoPtr< Tp >::AutoPtr ( AutoPtr< Tp > &  a)
inline

An AutoPtr can be constructed from another AutoPtr.

Parameters
aAnother 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.

135  : _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
aAnother 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.

148  : _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.

195 { 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.

278  : _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::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::ImplicitSystem::adjoint_qoi_parameter_sensitivity(), libMesh::DofMap::attach_matrix(), libMesh::System::calculate_norm(), libMesh::DofMap::clear_sparsity(), libMesh::Xdr::close(), libMesh::Xdr::comment(), libMesh::Xdr::data(), libMesh::Xdr::data_stream(), libMesh::Xdr::do_read(), libMesh::Xdr::do_write(), libMesh::DofMap::enforce_adjoint_constraints_exactly(), libMesh::DofMap::enforce_constraints_exactly(), libMesh::for(), libMesh::InfFE< friend_Dim, friend_T_radial, friend_T_map >::inverse_map(), libMesh::Xdr::is_open(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::InfFE< friend_Dim, friend_T_radial, friend_T_map >::map(), libMesh::Xdr::open(), libMesh::PostscriptIO::plot_quadratic_elem(), libMesh::System::project_vector(), libMesh::Parallel::StandardType< TypeVector< T > >::StandardType(), libMesh::Parallel::StandardType< VectorValue< T > >::StandardType(), libMesh::Parallel::StandardType< Point >::StandardType(), libMesh::MeshRefinement::test_level_one(), and libMesh::System::write_serialized_blocked_dof_objects().

228 { 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.

309  { 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.

302  { 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.

206 { 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.

215 { return _ptr; }
template<typename Tp>
AutoPtr& libMesh::AutoPtr< Tp >::operator= ( AutoPtr< Tp > &  a)
inline

AutoPtr assignment operator.

Parameters
aAnother 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.

160  {
161  reset(a.release());
162  return *this;
163  }
template<typename Tp>
template<typename Tp1 >
AutoPtr& libMesh::AutoPtr< Tp >::operator= ( AutoPtr< Tp1 > &  a)
inline

AutoPtr assignment operator.

Parameters
aAnother 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.

178  {
179  reset(a.release());
180  return *this;
181  }
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.

288  {
289  if (ref._ptr != this->get())
290  {
291  delete _ptr;
292  _ptr = ref._ptr;
293  }
294  return *this;
295  }
template<typename Tp>
element_type* libMesh::AutoPtr< Tp >::release ( )
inline

Member Data Documentation


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

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:08 UTC

Hosted By:
SourceForge.net Logo