Pallas Solver  0.1
C++ Global Optimization Algorithms
Public Types | Public Member Functions | Friends | List of all members
pallas::scoped_ptr< C > Class Template Reference

#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)
 

Detailed Description

template<class C>
class pallas::scoped_ptr< C >

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*)

Member Typedef Documentation

template<class C>
typedef C pallas::scoped_ptr< C >::element_type

The element type

Constructor & Destructor Documentation

template<class C>
pallas::scoped_ptr< C >::~scoped_ptr ( )
inline

Destructor.

If there is a C object, delete it. We don't need to test ptr_ == NULL because C++ does that for us.

Member Function Documentation

template<class C>
bool pallas::scoped_ptr< C >::operator!= ( const C *  p) const
inline

Returns whether a scoped_ptr and a raw pointer refer to two different objects.

Here is the caller graph for this function:

template<class C>
C& pallas::scoped_ptr< C >::operator* ( ) const
inline

Accessor to get the owned object.

operator* will assert() if there is no current object.

template<class C>
C* pallas::scoped_ptr< C >::operator-> ( ) const
inline

Accessor to get the owned object.

operator-> will assert() if there is no current object.

template<class C>
bool pallas::scoped_ptr< C >::operator== ( const C *  p) const
inline

Returns whether a scoped_ptr and a raw pointer refer to the same object

Here is the caller graph for this function:

template<class C>
C* pallas::scoped_ptr< C >::release ( )
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.]

template<class C>
void pallas::scoped_ptr< C >::reset ( C *  p = NULL)
inline

Deletes the current owned object, if any.

Afterwards then takes ownership of a new object, if given. this->reset(this->get()) works.

template<class C>
void pallas::scoped_ptr< C >::swap ( scoped_ptr< C > &  p2)
inline

Swap two scoped pointers.

Here is the caller graph for this function:

Friends And Related Function Documentation

template<class C>
scoped_ptr<C> make_scoped_ptr ( C *  p)
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.


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