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. | |
| 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:
AnAutoPtrowns the object it holds a pointer to. Copying anAutoPtrcopies the pointer and transfers ownership to the destination. If more than oneAutoPtrowns the same object at the same time the behavior of the program is undefined.
The uses ofQuoted from [20.4.5]/3.AutoPtrinclude 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.AutoPtrdoes not meet the CopyConstructible and Assignable requirements for Standard Library container elements and thus instantiating a Standard Library container with anAutoPtrresults in undefined behavior.
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
| typedef Tp AutoPtr< Tp >::element_type |
The pointed-to type.
Definition at line 116 of file auto_ptr.h.
Constructor & Destructor Documentation
| 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).
Definition at line 125 of file auto_ptr.h.
00126 : _ptr(p) {}
An AutoPtr can be constructed from another AutoPtr.
- Parameters:
-
a Another AutoPtr of the same type.
Definition at line 135 of file auto_ptr.h.
| 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.
This object now owns the object previously owned by a, which has given up ownsership.
Definition at line 148 of file auto_ptr.h.
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.
00196 { delete _ptr; }
| 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.
Member Function Documentation
| element_type* AutoPtr< Tp >::get | ( | ) | const [inline] |
Bypassing the smart pointer.
- Returns:
- The raw pointer being managed.
- Note:
- This AutoPtr still owns the memory.
Definition at line 229 of file auto_ptr.h.
Referenced by ExactSolution::_compute_error(), FEMSystem::assembly(), System::calculate_norm(), Xdr::close(), Xdr::comment(), ContinuationSystem::continuation_solve(), Xdr::data(), Xdr::data_stream(), AdaptiveTimeSolver::element_residual(), DofMap::enforce_constraints_exactly(), AdaptiveTimeSolver::error_order(), ExactErrorEstimator::estimate_error(), FEMSystem::eulerian_residual(), DifferentiableSystem::get_linear_solver(), 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(), Xdr::open(), PostscriptIO::plot_quadratic_elem(), MeshBase::point_locator(), System::project_vector(), AdaptiveTimeSolver::reinit(), HPCoarsenTest::select_refinement(), AdaptiveTimeSolver::side_residual(), TwostepTimeSolver::solve(), and ContinuationSystem::solve_tangent().
00229 { return _ptr; }
op() for AutoPtr<Tp1>. Calls the release member.
Definition at line 309 of file auto_ptr.h.
00310 { return AutoPtr<Tp1>(this->release()); }
| AutoPtr< Tp >::operator AutoPtrRef< Tp1 > | ( | ) | [inline] |
op() for AutoPtrRef<Tp1>. Calls the release member.
Definition at line 302 of file auto_ptr.h.
00303 { return AutoPtrRef<Tp1>(this->release()); }
| 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.
00207 { return *_ptr; }
| 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.
00216 { return _ptr; }
| 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.
00289 { 00290 if (ref._ptr != this->get()) 00291 { 00292 delete _ptr; 00293 _ptr = ref._ptr; 00294 } 00295 return *this; 00296 }
| AutoPtr& AutoPtr< Tp >::operator= | ( | AutoPtr< Tp1 > & | a | ) | [inline] |
AutoPtr assignment operator.
- Parameters:
-
a Another AutoPtr of a different but related 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.
AutoPtr assignment operator.
- Parameters:
-
a Another AutoPtr of the same type.
Definition at line 160 of file auto_ptr.h.
| element_type* AutoPtr< Tp >::release | ( | ) | [inline] |
Bypassing the smart pointer.
- Returns:
- The raw pointer being managed.
- 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 InfFE< Dim, T_radial, T_map >::attach_quadrature_rule(), FEMContext::FEMContext(), InfFE< Dim, T_radial, T_map >::InfFE(), InfFE< Dim, T_radial, T_map >::init_face_shape_functions(), AutoPtr< PointLocatorBase >::operator AutoPtr< Tp1 >(), AutoPtr< PointLocatorBase >::operator AutoPtrRef< Tp1 >(), AutoPtr< PointLocatorBase >::operator=(), MeshBase::point_locator(), and InfFE< Dim, T_radial, T_map >::reinit().
00244 { 00245 element_type* tmp = _ptr; 00246 _ptr = 0; 00247 return tmp; 00248 }
| void AutoPtr< Tp >::reset | ( | element_type * | p = 0 |
) | [inline] |
Forcibly deletes the managed object.
- Parameters:
-
p A pointer (defaults to NULL).
Definition at line 258 of file auto_ptr.h.
Referenced by NonlinearSolver< T >::build(), MeshBase::clear_point_locator(), Xdr::close(), Xdr::open(), AutoPtr< PointLocatorBase >::operator=(), MeshBase::point_locator(), BoundaryInfo::sync(), and TwostepTimeSolver::TwostepTimeSolver().
Member Data Documentation
The actual dumb pointer this class wraps.
Definition at line 110 of file auto_ptr.h.
Referenced by AutoPtr< PointLocatorBase >::get(), AutoPtr< PointLocatorBase >::operator*(), AutoPtr< PointLocatorBase >::operator->(), AutoPtr< PointLocatorBase >::operator=(), AutoPtr< PointLocatorBase >::release(), AutoPtr< PointLocatorBase >::reset(), and AutoPtr< PointLocatorBase >::~AutoPtr().
The documentation for this class was generated from the following file: