Celartem::StorageRewinder Class Reference

#include <cel_storage.h>

List of all members.

Public Member Functions

 StorageRewinder (Storage *inStorage)
 StorageRewinder ()
void setStorage (Storage *inStorage)
void rewind ()
void releaseStorage ()
 ~StorageRewinder ()


Detailed Description

StorageRewinder class memorizes the storage pointer position on the construction and rewinds the storage pointer to the position on the destruction. This class is useful when a function/method should be rewind the storage pointer to the first position although it reads and seeks the storage in it. The following code illustrates how to use this class:
            void someFunction(Storage *inStorage)
            {
                // rewinder remember the current storage pointer position
                StorageRewinder rewinder(inStorage);

                u8 someBuffer[256];
                inStorage->readBytes(someBuffer, 256);
                if(!some_validation_function(someBuffer, 256))
                {
                    // StorageRewinder automatically rewinds the storage
                    // even if you are canceling the process by some
                    // exception.
                    throw someError;
                }

                // some process...
                do_something(...);

                // StorageRewinder also works on the end of the function.
            }
See also:
Storage

Definition at line 259 of file cel_storage.h.


Constructor & Destructor Documentation

Celartem::StorageRewinder::StorageRewinder ( Storage inStorage  )  [inline]

This constructor creates the StorageRewinder on the specified storage. The instance memorizes the current storage position of the storage.

Parameters:
inStorage A storage on which the StorageRewinder is built on.

Definition at line 270 of file cel_storage.h.

Celartem::StorageRewinder::StorageRewinder (  )  [inline]

This constructor creates the StorageRewinder that does not hold any storage. This version of constructor is usually used with setStorage method.

Definition at line 281 of file cel_storage.h.

Celartem::StorageRewinder::~StorageRewinder (  )  [inline]

This method rewinds the storage to the initial position and delete the StorageRewinder instance.

Definition at line 323 of file cel_storage.h.


Member Function Documentation

void Celartem::StorageRewinder::setStorage ( Storage inStorage  )  [inline]

This method associates the specified storage instance to this StorageRewinder instance. Please note that the previous one is not to be rewound but only released.

Parameters:
inStorage A storage on which the StorageRewinder is built on.

Definition at line 293 of file cel_storage.h.

void Celartem::StorageRewinder::rewind (  )  [inline]

This method rewinds the storage to the initial position.

Definition at line 303 of file cel_storage.h.

Referenced by ~StorageRewinder().

void Celartem::StorageRewinder::releaseStorage (  )  [inline]

This method releases the storage instance that is held by this instance. Please note that this method does not rewind the storage.

Definition at line 314 of file cel_storage.h.

Referenced by setStorage().


The documentation for this class was generated from the following file:
This document is automatically generated using doxygen 1.5.4 at Fri Jun 27 18:23:21 2008.