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... | |
AutoPtr & | operator= (AutoPtr &a) |
AutoPtr assignment operator. More... | |
template<typename Tp1 > | |
AutoPtr & | operator= (AutoPtr< Tp1 > &a) |
AutoPtr assignment operator. More... | |
~AutoPtr () | |
element_type & | operator* () const |
Smart pointer dereferencing. More... | |
element_type * | operator-> () const |
Smart pointer dereferencing. More... | |
element_type * | get () const |
Bypassing the smart pointer. More... | |
element_type * | release () |
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... | |
AutoPtr & | operator= (AutoPtrRef< element_type > ref) |
bool | boolean_test () const |
template<typename Tp1 > | |
operator AutoPtrRef< Tp1 > () | |
template<typename Tp1 > | |
operator AutoPtr< Tp1 > () | |
operator bool_type () const | |
Private Attributes | |
Tp * | _ptr |
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.
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 210 of file auto_ptr.h.
typedef Tp libMesh::AutoPtr< Tp >::element_type |
The pointed-to type.
Definition at line 223 of file auto_ptr.h.
|
inlineexplicit |
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 236 of file auto_ptr.h.
|
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 ownership.
Definition at line 248 of file auto_ptr.h.
|
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 ownership.
Definition at line 263 of file auto_ptr.h.
|
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.
The C++ standard says there is supposed to be an empty throw specification here, but omitting it is standard conforming. Its presence can be detected only if _Tp::~_Tp() throws, but this is prohibited. [17.4.3.6]/2
Definition at line 311 of file auto_ptr.h.
References libMesh::AutoPtrRef< Tp1 >::_ptr, and libMesh::warned_about_auto_ptr.
|
inline |
Automatic conversions.
These operations convert an AutoPtr into and from an AutoPtrRef automatically as needed. This allows constructs such as
Definition at line 401 of file auto_ptr.h.
|
inline |
A "safe" replacement for operator bool () that behaves more like an explicit conversion operator even in C++98. This allows code like:
to work with AutoPtr.
Definition at line 433 of file auto_ptr.h.
|
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 352 of file auto_ptr.h.
References libMesh::AutoPtrRef< Tp1 >::_ptr.
|
inline |
op() for AutoPtr<Tp1>. Calls the release member.
Definition at line 449 of file auto_ptr.h.
|
inline |
op() for AutoPtrRef<Tp1>. Calls the release member.
Definition at line 442 of file auto_ptr.h.
|
inlineinherited |
Definition at line 65 of file safe_bool.h.
References libMesh::safe_bool_base::this_type_does_not_support_comparisons().
|
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 330 of file auto_ptr.h.
References libMesh::AutoPtrRef< Tp1 >::_ptr.
|
inline |
Smart pointer dereferencing.
Definition at line 339 of file auto_ptr.h.
References libMesh::AutoPtrRef< Tp1 >::_ptr.
|
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 ownership. The object that this one used to own and track has been deleted.
Definition at line 277 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::release().
|
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 ownership. The object that this one used to own and track has been deleted.
Definition at line 295 of file auto_ptr.h.
References libMesh::AutoPtr< Tp >::release().
|
inline |
op= for AutoPtr. Allows you to write:
Definition at line 412 of file auto_ptr.h.
References libMesh::AutoPtrRef< Tp1 >::_ptr.
|
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 366 of file auto_ptr.h.
References libMesh::AutoPtrRef< Tp1 >::_ptr.
Referenced by libMesh::AutoPtr< Tp >::operator=().
|
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 381 of file auto_ptr.h.
References libMesh::AutoPtrRef< Tp1 >::_ptr.
|
private |
The actual dumb pointer this class wraps.
Definition at line 217 of file auto_ptr.h.