MrSID Decode SDK for LiDAR Reference Manual  1.1.3.4427
Scoped< TYPE > Class Template Reference

Scoped is a wrapper class around Object that gives it block scoping. More...

#include <Object.h>

List of all members.

Public Member Functions

 ~Scoped (void)
 Releases the object when Scoped<> goes out of scope.
 Scoped (void)
 Create an object on the heap.
 Scoped (TYPE *object)
 Manage an existing object.
Scopedoperator= (TYPE *object)
 Assignment operator.
 Scoped (const Scoped &object)
 Copy constructor.
Scopedoperator= (const Scoped &object)
 Assignment operator.
TYPE * operator-> (void)
 Make Scoped behave like a pointer to TYPE.
TYPE & operator* (void)
 Make Scoped behave like a pointer to TYPE.
 operator TYPE *& (void)
 Make Scoped behave like a pointer to TYPE.

Detailed Description

template<typename TYPE>
class Scoped< TYPE >

Scoped is convenience class that give block scoping to reference counted Objects. Scoped<TYPE> tries to act like a TYPE *.

As a convenience class you don't have to use it. Some people find it easier to manage the reference counting themselves.

Example: Without Scoped:

 {
    FileIO *file = FileIO::create();
    try
    {
       file->init(path, mode);
       // use the file object
       if(return early)
       {
          file->release();
          return;
       }
       // use the file object some more
       file->release();
    }
    catch(...)
    {
       file->release();
       throw;
    }
 }

With Scoped:

 {
    Scoped<FileIO> file;
    file->init(path, mode);
    // use the file object
    if(return early)
       return;
    // use the file object some more
 }
Note:
be careful when using this outside of blocked scope. The = operator increments the count which can lead to memory leaks.

Definition at line 158 of file Object.h.


Constructor & Destructor Documentation

template<typename TYPE>
Scoped< TYPE >::~Scoped ( void  ) [inline]

Definition at line 162 of file Object.h.

References RELEASE().

template<typename TYPE>
Scoped< TYPE >::Scoped ( void  ) [inline]

Definition at line 165 of file Object.h.

template<typename TYPE>
Scoped< TYPE >::Scoped ( TYPE *  object) [inline]

This constructor does not reatin() object, use operator= if you want to retain the object.

Note:
Use Scoped<TYPE> object(NULL) to get an empty wrapper.

Definition at line 175 of file Object.h.

template<typename TYPE>
Scoped< TYPE >::Scoped ( const Scoped< TYPE > &  object) [inline]

Retain the object.

Definition at line 197 of file Object.h.


Member Function Documentation

template<typename TYPE>
Scoped< TYPE >::operator TYPE *& ( void  ) [inline]

(use the reference with care)

Definition at line 220 of file Object.h.

template<typename TYPE>
TYPE& Scoped< TYPE >::operator* ( void  ) [inline]

Definition at line 217 of file Object.h.

template<typename TYPE>
TYPE* Scoped< TYPE >::operator-> ( void  ) [inline]

Definition at line 215 of file Object.h.

template<typename TYPE>
Scoped& Scoped< TYPE >::operator= ( TYPE *  object) [inline]

The current object is released and the new object is retained.

Definition at line 182 of file Object.h.

References RELEASE(), and RETAIN().

template<typename TYPE>
Scoped& Scoped< TYPE >::operator= ( const Scoped< TYPE > &  object) [inline]

The current object is released and the new object is retained.

Definition at line 204 of file Object.h.

References RELEASE(), and RETAIN().


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