SUMMARY:  INNER | FIELD | CONSTR | METHOD | FRIEND DETAIL:  FIELD | CONSTR | METHOD | FRIEND


Platform
Template Class Scoped

NonCopyableType
   |
   +-Scoped

Implemented in:
Platform.Scoped.h

template <typename Type>
class Scoped:
private NonCopyableType

An automatic pointer. Holds a pointer to an object allocated on heap using new or new[] operators. When an automatic pointer goes out of scope (and so its destructor is invoked) the object it holds is automatically deleted using the delete or delete[] operators. An automatic pointer cannot be copied, although the ownership of the object it holds can be released (and then acquired by another automatic pointer) using the release() method.

It is adviced to, in a given scope, wrap objects allocated on heap in automatic pointers when exceptions may be thrown. Such practice ensures that no matter what program flow takes place the resources are released properly and no memory leaks occur.

If copying and reference counting are necessary consider using smart pointers instead.

See Also:
Smart
operator new, operator delete
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization

Inner Compounds, Typedefs, and Enumscollapse
typedef ElementType
          Defines the type of the object to which this automatic pointer refers.

Constructor Summarycollapse
Scoped(ElementType* object)
          Creates an automatic pointer to the specified object.
~Scoped()
          Destroys this automatic pointer and deletes the object it holds.

Method Summarycollapse
ElementType& operator*() const
          Dereferences the object held by this automatic pointer.
ElementType* operator->() const
          Dereferences an object member held by this automatic pointer.
ElementType* release()
          Releases the ownership of the object held by this automatic pointer.
ElementType* value() const
          Retrieves the object held by this automatic pointer.

 

Constructor Detail

Scoped[explicit, inline]

Scoped(ElementType* object)

Creates an automatic pointer to the specified object. The object must have been allocated on heap using new or new[] operator.

Parameters:
object - an object allocated on heap using new or new[] operator

~Scoped[inline]

~Scoped()

Destroys this automatic pointer and deletes the object it holds. The object must have been allocated on heap and is deleted using delete or delete[] operator, whichever is appropriate.

 

Method Detail

operator*[inline]

ElementType& operator*() const

Dereferences the object held by this automatic pointer.

Returns:
the reference to the value of the object held by this automatic pointer

operator->[inline]

ElementType* operator->() const

Dereferences an object member held by this automatic pointer.

Returns:
the object held by this automatic pointer

release[inline]

ElementType* release()

Releases the ownership of the object held by this automatic pointer. The returned pointer must be deleted manually or assigned to another automatic pointer.

Returns:
the object held by this automatic pointer

value[inline]

ElementType* value() const

Retrieves the object held by this automatic pointer.

Returns:
the object held by this automatic pointer


SUMMARY:  INNER | FIELD | CONSTR | METHOD | FRIEND DETAIL:  FIELD | CONSTR | METHOD | FRIEND