Generated on: Thu Mar 29 07:46:58 PDT 2012 for custom file set
// doxy/ or-tools/ src/ base/

operations_research::scoped_ptr< C > Class Template Reference

A scoped_ptr<T> is like a T*, except that the destructor of scoped_ptr<T> automatically deletes the pointer it holds (if any). More...

#include <scoped_ptr.h>

List of all members.

Public Types

typedef C element_type
 The element type.

Public Member Functions

 scoped_ptr (C *p=NULL)
 Constructor.
 ~scoped_ptr ()
 Destructor.
void reset (C *p=NULL)
 Reset.
C & operator* () const
 Accessors to get the owned object.
C * operator-> () const
C * get () const
bool operator== (C *p) const
 Comparison operators.
bool operator!= (C *p) const
void swap (scoped_ptr &p2)
 Swap two scoped pointers.
C * release ()
 Release a pointer.

Friends

scoped_ptr< C > make_scoped_ptr (C *p)
 friend class that can access copy ctor (although if it actually calls a copy ctor, there will be a problem) see below


Detailed Description

template<class C>
class operations_research::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.

The size of a scoped_ptr is small: sizeof(scoped_ptr<C>) == sizeof(C*)

Definition at line 47 of file scoped_ptr.h.


Member Typedef Documentation

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

The element type.

Definition at line 51 of file scoped_ptr.h.


Constructor & Destructor Documentation

template<class C>
operations_research::scoped_ptr< C >::scoped_ptr ( C *  p = NULL  )  [inline, explicit]

Constructor.

Defaults to intializing with NULL. There is no way to create an uninitialized scoped_ptr. The input parameter must be allocated with new.

Definition at line 56 of file scoped_ptr.h.

template<class C>
operations_research::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.

Definition at line 60 of file scoped_ptr.h.


Member Function Documentation

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

Reset.

Deletes the current owned object, if any. Then takes ownership of a new object, if given. this->reset(this->get()) works.

Definition at line 68 of file scoped_ptr.h.

template<class C>
C& operations_research::scoped_ptr< C >::operator* (  )  const [inline]

Accessors to get the owned object.

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

Definition at line 78 of file scoped_ptr.h.

template<class C>
C* operations_research::scoped_ptr< C >::operator-> (  )  const [inline]

Definition at line 82 of file scoped_ptr.h.

template<class C>
C* operations_research::scoped_ptr< C >::get (  )  const [inline]

Definition at line 86 of file scoped_ptr.h.

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

Comparison operators.

These return whether two scoped_ptr refer to the same object, not just to two different but equal objects.

Definition at line 91 of file scoped_ptr.h.

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

Definition at line 92 of file scoped_ptr.h.

template<class C>
void operations_research::scoped_ptr< C >::swap ( scoped_ptr< C > &  p2  )  [inline]

Swap two scoped pointers.

Definition at line 95 of file scoped_ptr.h.

template<class C>
C* operations_research::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.

Definition at line 106 of file scoped_ptr.h.


Friends And Related Function Documentation

template<class C>
scoped_ptr<C> make_scoped_ptr ( C *  p  )  [friend]

friend class that can access copy ctor (although if it actually calls a copy ctor, there will be a problem) see below


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