MrSID Decode SDK for Raster Reference Manual  9.0.0.3864
LTIODynamicMemStream Class Reference

holds a memory buffer of variable size More...

#include <lt_ioDynamicMemStream.h>

Inheritance diagram for LTIODynamicMemStream:
LTIOStreamInf

Public Types

Memory Allocation and Deallocation Functions
typedef void *(* Allocator )(size_t)
 
typedef void(* Deallocator )(void *)
 
typedef void *(* Reallocator )(void *, size_t)
 

Public Member Functions

 LTIODynamicMemStream ()
 
virtual ~LTIODynamicMemStream ()
 
virtual bool isEOF ()
 Test for end-of-stream. More...
 
virtual bool isOpen ()
 Test for stream openness. More...
 
virtual LT_STATUS open ()
 Opens the stream. More...
 
virtual LT_STATUS close ()
 Closes the stream. More...
 
virtual lt_uint32 read (lt_uint8 *pDest, lt_uint32 numBytes)
 Retrieve the specified number of bytes from the data source and place them in pDest. More...
 
virtual lt_uint32 write (const lt_uint8 *pSrc, lt_uint32 numBytes)
 Store the specified number of bytes in the data source. More...
 
virtual LT_STATUS seek (lt_int64 offset, LTIOSeekDir origin)
 Moves the data access position to origin + offset. More...
 
virtual lt_int64 tell ()
 Returns the current data access position as an offset from the start of the data. More...
 
virtual LTIOStreamInfduplicate ()
 Clone the stream. More...
 
virtual LT_STATUS getLastError () const
 Get status code of last error event. More...
 
virtual const char * getID () const
 Get a URI describing the stream object. More...
 
Initialization functions
virtual LT_STATUS initialize (lt_uint32 size=4096, float growthRate=2)
 Initializes the stream. More...
 
virtual LT_STATUS initialize (lt_uint32 size, Allocator allo, Deallocator deallo, Reallocator reallo=NULL, float growthRate=2)
 Initializes the stream, with custom memory management. More...
 
Memory Management
Allocator getAllocator () const
 Returns the allocator function pointer. More...
 
Deallocator getDeallocator () const
 Returns the deallocator function pointer. More...
 
Reallocator getReallocator () const
 Returns the reallocator function pointer. More...
 
const lt_uint8getData () const
 Get the underlying buffer. More...
 
LT_STATUS detachAndClose (lt_uint8 *&data)
 Detach the underlying buffer from the stream, and closes the stream. More...
 
lt_uint64 size () const
 Returns the number of bytes which are in the stream. More...
 
- Public Member Functions inherited from LTIOStreamInf
virtual ~LTIOStreamInf ()=0
 

Protected Member Functions

bool grow (lt_uint32 numBytes)
 extend size of data buffer if required More...
 
void * defaultRealloc (void *, size_t)
 

Protected Attributes

lt_uint8m_data
 pointer to buffer More...
 
lt_uint32 m_initialSize
 initial size of buffer More...
 
lt_uint32 m_bufferSize
 size of buffer as allocated More...
 
lt_uint32 m_userSize
 size of buffer as accessible by user More...
 
lt_uint32 m_cur
 current position More...
 
bool m_isOpen
 openness More...
 
Allocator m_alloc
 allocator function More...
 
Deallocator m_dealloc
 deallocator More...
 
Reallocator m_realloc
 reallocator More...
 
LT_STATUS m_lastError
 
bool m_isEOF
 
float m_growthRate
 the factor of growth of the memory [1-2): More...
 

Detailed Description

Unlike LTIOMemStream, which uses a fixed-size buffer, this class will grow its buffer as you write past the end of it. It is most suitable for use as an internal "temp stream". The stream is initially empty.

The stream cannot hold more than 2^32 bytes of data.

Definition at line 33 of file lt_ioDynamicMemStream.h.

Member Typedef Documentation

typedef void*(* LTIODynamicMemStream::Allocator)(size_t)

Definition at line 43 of file lt_ioDynamicMemStream.h.

typedef void(* LTIODynamicMemStream::Deallocator)(void *)

Definition at line 44 of file lt_ioDynamicMemStream.h.

typedef void*(* LTIODynamicMemStream::Reallocator)(void *, size_t)

Definition at line 45 of file lt_ioDynamicMemStream.h.

Constructor & Destructor Documentation

LTIODynamicMemStream::LTIODynamicMemStream ( )
virtual LTIODynamicMemStream::~LTIODynamicMemStream ( )
virtual

Member Function Documentation

virtual LT_STATUS LTIODynamicMemStream::close ( )
virtual

Puts the stream in a state that does not allow data access. May free up resources, but only in such a way that doesn't inhibit successful future calls to open()

Return values
LT_STS_SuccessOn success, or if the stream is already closed.
LT_STS_FailureOtherwise.

Implements LTIOStreamInf.

void* LTIODynamicMemStream::defaultRealloc ( void *  ,
size_t   
)
protected
LT_STATUS LTIODynamicMemStream::detachAndClose ( lt_uint8 *&  data)

The caller is responsible for deallocating the buffer. (Note that you must use the Deallocator method, not delete[].)

Parameters
datareceives pointer to underlying buffer
Returns
LT_STS_Success upon success
virtual LTIOStreamInf* LTIODynamicMemStream::duplicate ( )
virtual

Create new stream of the same type with the same initialization parameters. The transmission of these parameters is the responsibility of the derived type. The new stream should initially return false for isOpen().

Return values
NULLthe stream could not be duplicated; valid LTIOStreamInf* otherwise.

Implements LTIOStreamInf.

Allocator LTIODynamicMemStream::getAllocator ( ) const
inline

Definition at line 101 of file lt_ioDynamicMemStream.h.

const lt_uint8* LTIODynamicMemStream::getData ( ) const
inline

The pointer is guaranteed to be good until the next call to write(), or close()

Returns
pointer to underlying buffer

Definition at line 121 of file lt_ioDynamicMemStream.h.

Deallocator LTIODynamicMemStream::getDeallocator ( ) const
inline

Definition at line 106 of file lt_ioDynamicMemStream.h.

virtual const char* LTIODynamicMemStream::getID ( ) const
virtual

This function returns a UTF-8, null-terminated string which is a URI describing the origin of the stream object – for example, "file://foo.txt" or "lt_memstream:". This string is only intended for diagnostic purposes, i.e. it may not be valid to pass it to the ctor in an attempt to reopen the stream.

Return values
urithe uri string

Implements LTIOStreamInf.

virtual LT_STATUS LTIODynamicMemStream::getLastError ( ) const
virtual

read(), write(), tell(), and duplicate() do not explicitly return status codes in the event of an error. When an error has occurred, this function returns the appropriate status code. Note calling this function after a successful I/O operation will return an undefined value.

Return values
statusthe error code

Implements LTIOStreamInf.

Reallocator LTIODynamicMemStream::getReallocator ( ) const
inline

Definition at line 111 of file lt_ioDynamicMemStream.h.

bool LTIODynamicMemStream::grow ( lt_uint32  numBytes)
protected
virtual LT_STATUS LTIODynamicMemStream::initialize ( lt_uint32  size = 4096,
float  growthRate = 2 
)
virtual
Parameters
sizeinitial size of buffer in bytes
growthRatefactor of growth Valid Values: [1-2)
virtual LT_STATUS LTIODynamicMemStream::initialize ( lt_uint32  size,
Allocator  allo,
Deallocator  deallo,
Reallocator  reallo = NULL,
float  growthRate = 2 
)
virtual

The allocator function should return NULL in the event of failure, as opposed to throwing an exception – that is, be like malloc() and not like new.

Parameters
sizeinitial size of buffer in bytes
allouser-defined memory allocator
deallouser-defined memory deallocator
reallouser-defined memory reallocator
growthRatefactor of growth Valid Values: [1-2)
virtual bool LTIODynamicMemStream::isEOF ( )
virtual

Returns true after the first read operation that attempts to read past the end of the stream. It returns false if the current position is not end of stream.

Return values
trueend of stream
falseotherwise

Implements LTIOStreamInf.

virtual bool LTIODynamicMemStream::isOpen ( )
virtual
Return values
trueThe stream is open
falseotherwise

Implements LTIOStreamInf.

virtual LT_STATUS LTIODynamicMemStream::open ( )
virtual

Opening a stream puts it in a state that allows data access based on cached initialization parameters.

Return values
LT_STS_IOStreamUninitializedThe stream has not been initialized with enough information to open the stream
LT_STS_IOStreamInvalidStateThe stream is already open
LT_STS_SuccessOn success.
LT_STS_FailureFailure.
otherImplementations may return other codes

Implements LTIOStreamInf.

virtual lt_uint32 LTIODynamicMemStream::read ( lt_uint8 pDest,
lt_uint32  numBytes 
)
virtual
Parameters
pDestbuffer in which to store read data
numBytesnumber of bytes to read from stream
Return values
numBytesThe number of bytes actually read

Implements LTIOStreamInf.

virtual LT_STATUS LTIODynamicMemStream::seek ( lt_int64  offset,
LTIOSeekDir  origin 
)
virtual
Parameters
offsetnumber of bytes from origin at which to the next read or write will take place
originplace in stream from which to seek
Return values
LT_STS_IOStreamUnsupportedThe stream is not seekable
LT_STS_IOStreamInvalidArgsThe offset and origin do not specify a valid location in the stream
LT_STS_SuccessOn success
LT_STS_FailureOtherwise
otherImplementations may return other codes

Implements LTIOStreamInf.

lt_uint64 LTIODynamicMemStream::size ( ) const
inline

This may be smaller than the amount actually allocated.

Returns
size (in bytes) of stream

Definition at line 143 of file lt_ioDynamicMemStream.h.

virtual lt_int64 LTIODynamicMemStream::tell ( )
virtual
Return values
postionNumber of bytes from the start of the data
-1On error.
otherImplementations may return other codes

Implements LTIOStreamInf.

virtual lt_uint32 LTIODynamicMemStream::write ( const lt_uint8 pSrc,
lt_uint32  numBytes 
)
virtual
Parameters
pSrcbuffer from which to store data
numBytesnumber of bytes to write to stream
Return values
numBytesnumber of bytes actually written

Implements LTIOStreamInf.

Member Data Documentation

Allocator LTIODynamicMemStream::m_alloc
protected

Definition at line 174 of file lt_ioDynamicMemStream.h.

lt_uint32 LTIODynamicMemStream::m_bufferSize
protected

Definition at line 162 of file lt_ioDynamicMemStream.h.

lt_uint32 LTIODynamicMemStream::m_cur
protected

Definition at line 168 of file lt_ioDynamicMemStream.h.

lt_uint8* LTIODynamicMemStream::m_data
protected

Definition at line 156 of file lt_ioDynamicMemStream.h.

Deallocator LTIODynamicMemStream::m_dealloc
protected

Definition at line 177 of file lt_ioDynamicMemStream.h.

float LTIODynamicMemStream::m_growthRate
protected

Definition at line 189 of file lt_ioDynamicMemStream.h.

lt_uint32 LTIODynamicMemStream::m_initialSize
protected

Definition at line 159 of file lt_ioDynamicMemStream.h.

bool LTIODynamicMemStream::m_isEOF
protected

Definition at line 186 of file lt_ioDynamicMemStream.h.

bool LTIODynamicMemStream::m_isOpen
protected

Definition at line 171 of file lt_ioDynamicMemStream.h.

LT_STATUS LTIODynamicMemStream::m_lastError
protected

Definition at line 184 of file lt_ioDynamicMemStream.h.

Reallocator LTIODynamicMemStream::m_realloc
protected

Definition at line 180 of file lt_ioDynamicMemStream.h.

lt_uint32 LTIODynamicMemStream::m_userSize
protected

Definition at line 165 of file lt_ioDynamicMemStream.h.


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

LizardTech