$extrastylesheet
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 |
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 ofAutoPtrinclude 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.
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.
The following are the original copyright declarations distributed with this class:
Copyright (C) 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU ISO C++ Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with this library; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, you may use this file as part of a free software library without restriction. Specifically, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other files to produce an executable, this file does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License.
Copyright (c) 1997-1999 Silicon Graphics Computer Systems, Inc.
Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Silicon Graphics makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.
Definition at line 148 of file auto_ptr.h.
| typedef Tp libMesh::AutoPtr< Tp >::element_type |
The pointed-to type.
Definition at line 161 of file auto_ptr.h.
| libMesh::AutoPtr< Tp >::AutoPtr | ( | element_type * | p = 0 | ) | [inline, explicit] |
An AutoPtr is usually constructed from a raw pointer.
| p | A pointer (defaults to NULL). |
This object now owns the object pointed to by p.
Definition at line 170 of file auto_ptr.h.
: _ptr(p) { // Note: we can't call libmesh_deprecated() here, since global // AutoPtr variables are sometimes created before the libMesh::out // stream is ready. }
| libMesh::AutoPtr< Tp >::AutoPtr | ( | AutoPtr< Tp > & | a | ) | [inline] |
An AutoPtr can be constructed from another AutoPtr.
| 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 185 of file auto_ptr.h.
: _ptr(a.release()) { }
| libMesh::AutoPtr< Tp >::AutoPtr | ( | AutoPtr< Tp1 > & | a | ) | [inline] |
An AutoPtr can be constructed from another AutoPtr.
| 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 200 of file auto_ptr.h.
: _ptr(a.release()) { }
| 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 250 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::_ptr, libMesh::out, and libMesh::warned_about_auto_ptr.
{
if (!libMesh::warned_about_auto_ptr)
{
libMesh::warned_about_auto_ptr = true;
libMesh::out << "*** Warning, AutoPtr is deprecated and will be removed in a future library version! "
<< __FILE__ << ", line " << __LINE__ << ", compiled " << __DATE__ << " at " << __TIME__ << " ***" << std::endl;
}
delete _ptr;
}
| 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 341 of file auto_ptr.h.
: _ptr(ref._ptr) {}
| element_type* libMesh::AutoPtr< Tp >::get | ( | ) | const [inline] |
Bypassing the smart pointer.
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.
Definition at line 292 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::_ptr.
{ return _ptr; }
| libMesh::AutoPtr< Tp >::operator AutoPtr< Tp1 > | ( | ) | [inline] |
op() for AutoPtr<Tp1>. Calls the release member.
Definition at line 372 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::release().
{ return AutoPtr<Tp1>(this->release()); }
| libMesh::AutoPtr< Tp >::operator AutoPtrRef< Tp1 > | ( | ) | [inline] |
op() for AutoPtrRef<Tp1>. Calls the release member.
Definition at line 365 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::release().
{ return AutoPtrRef<Tp1>(this->release()); }
| 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 270 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::_ptr.
{ return *_ptr; }
| 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 279 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::_ptr.
{ return _ptr; }
| AutoPtr& libMesh::AutoPtr< Tp >::operator= | ( | AutoPtr< Tp > & | a | ) | [inline] |
AutoPtr assignment operator.
| 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 214 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::release(), and libMesh::AutoPtr< Tp >::reset().
{
reset(a.release());
return *this;
}
| AutoPtr& libMesh::AutoPtr< Tp >::operator= | ( | AutoPtr< Tp1 > & | a | ) | [inline] |
AutoPtr assignment operator.
| 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 232 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::release(), and libMesh::AutoPtr< Tp >::reset().
{
reset(a.release());
return *this;
}
| 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 351 of file auto_ptr.h.
References libMesh::AutoPtrRef< Tp1 >::_ptr, and libMesh::AutoPtr< Tp >::_ptr.
| element_type* libMesh::AutoPtr< Tp >::release | ( | ) | [inline] |
Bypassing the smart pointer.
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.
Definition at line 306 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::_ptr.
Referenced by libMesh::AutoPtr< Tp >::operator AutoPtr< Tp1 >(), libMesh::AutoPtr< Tp >::operator AutoPtrRef< Tp1 >(), and libMesh::AutoPtr< Tp >::operator=().
{
element_type* tmp = _ptr;
_ptr = 0;
return tmp;
}
| void libMesh::AutoPtr< Tp >::reset | ( | element_type * | p = 0 | ) | [inline] |
Forcibly deletes the managed object.
| 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 321 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::_ptr.
Referenced by libMesh::AutoPtr< Tp >::operator=().
Tp* libMesh::AutoPtr< Tp >::_ptr [private] |
The actual dumb pointer this class wraps.
Definition at line 155 of file auto_ptr.h.
Referenced by libMesh::AutoPtr< Tp >::get(), libMesh::AutoPtr< Tp >::operator*(), libMesh::AutoPtr< Tp >::operator->(), libMesh::AutoPtr< Tp >::operator=(), libMesh::AutoPtr< Tp >::release(), libMesh::AutoPtr< Tp >::reset(), and libMesh::AutoPtr< Tp >::~AutoPtr().