Pallas Solver
0.1
C++ Global Optimization Algorithms
|
#include <scoped_ptr.h>
Public Types | |
typedef C | element_type |
Public Member Functions | |
scoped_ptr (C *p=NULL) | |
Constructor. Defaults to intializing with NULL. There is no way to create an uninitialized scoped_ptr. The input parameter must be allocated with new. | |
~scoped_ptr () | |
Destructor. More... | |
void | reset (C *p=NULL) |
Deletes the current owned object, if any. More... | |
C & | operator* () const |
Accessor to get the owned object. More... | |
C * | operator-> () const |
Accessor to get the owned object. More... | |
C * | get () const |
Accessor to get the owned object. | |
bool | operator== (const C *p) const |
bool | operator!= (const C *p) const |
void | swap (scoped_ptr &p2) |
C * | release () |
Release a pointer. More... | |
Friends | |
scoped_ptr< C > | make_scoped_ptr (C *p) |
A scoped_ptr<T> is like a T*, except that the destructor of scoped_ptr<T> automatically deletes the pointer it holds (if any). That is, scoped_ptr<T> owns the T object that it points to. Like a T*, a scoped_ptr<T> may hold either NULL or a pointer to a T object. Also like T*, scoped_ptr<T> is thread-compatible, and once you dereference it, you get the threadsafety guarantees of T. The size of a scoped_ptr is small: sizeof(scoped_ptr<C>) == sizeof(C*)
typedef C pallas::scoped_ptr< C >::element_type |
The element type
|
inline |
Destructor.
If there is a C object, delete it. We don't need to test ptr_ == NULL because C++ does that for us.
|
inline |
Returns whether a scoped_ptr and a raw pointer refer to two different objects.
|
inline |
Accessor to get the owned object.
operator* will assert() if there is no current object.
|
inline |
Accessor to get the owned object.
operator-> will assert() if there is no current object.
|
inline |
Returns whether a scoped_ptr and a raw pointer refer to the same object
|
inline |
Release a pointer.
The return value is the current pointer held by this object. If this object holds a NULL pointer, the return value is NULL. After this operation, this object will hold a NULL pointer, and will not own the object any more.]
|
inline |
Deletes the current owned object, if any.
Afterwards then takes ownership of a new object, if given. this->reset(this->get()) works.
|
inline |
Swap two scoped pointers.
|
friend |
google3 friend class that can access copy ctor (although if it actually calls a copy ctor, there will be a problem).
This does nothing but to return a scoped_ptr of the type that the passed pointer is of. (This eliminates the need to specify the name of T when making a scoped_ptr that is used anonymously/temporarily.) From an access control point of view, we construct an unnamed scoped_ptr here which we return and thus copy-construct. Hence, we need to have access to scoped_ptr::scoped_ptr(scoped_ptr const &). However, it is guaranteed that we never actually call the copy constructor, which is a good thing as we would call the temporary's object destructor (and thus delete p) if we actually did copy some object, here.