MrSID Decode SDK for Raster Reference Manual  9.5.4.4709
lt_ioDynamicMemStream.h
Go to the documentation of this file.
00001 /* $Id$ */
00002 /* //////////////////////////////////////////////////////////////////////////
00003 //                                                                         //
00004 // This code is Copyright (c) 2004 LizardTech, Inc, 1008 Western Avenue,   //
00005 // Suite 200, Seattle, WA 98104.  Unauthorized use or distribution         //
00006 // prohibited.  Access to and use of this code is permitted only under     //
00007 // license from LizardTech, Inc.  Portions of the code are protected by    //
00008 // US and foreign patents and other filings. All Rights Reserved.          //
00009 //                                                                         //
00011 /* PUBLIC */
00012 
00013 
00014 #ifndef LT_IO_DYNAMIC_MEM_STREAM_H
00015 #define LT_IO_DYNAMIC_MEM_STREAM_H
00016 
00017 #include "lt_ioStreamInf.h"
00018 #include <stdlib.h>
00019 
00020 LT_BEGIN_NAMESPACE( LizardTech )
00021 
00022 
00023 
00033 class LTIODynamicMemStream : public LTIOStreamInf
00034 {
00035 public:
00038 #if defined(LT_OS_WINCE)
00039    typedef void* (__cdecl * Allocator)(size_t);
00040    typedef void(__cdecl *Deallocator)(void*);
00041    typedef void*(__cdecl *Reallocator)(void*,size_t);
00042 #else
00043    typedef void*(*Allocator)(size_t);
00044    typedef void(*Deallocator)(void*);
00045    typedef void*(*Reallocator)(void*,size_t);
00046 #endif
00047 
00048 
00049 public:
00050    LTIODynamicMemStream();
00051    virtual ~LTIODynamicMemStream();
00052 
00063    virtual LT_STATUS initialize( lt_uint32 size = 4096, float growthRate=2 );
00064 
00078    virtual LT_STATUS initialize( lt_uint32 size,
00079                                  Allocator allo, Deallocator deallo,
00080                                  Reallocator reallo=NULL, float growthRate=2 );
00081 
00084    virtual bool isEOF();
00085    virtual bool isOpen();
00086    virtual LT_STATUS open();
00087    virtual LT_STATUS close();
00088    virtual lt_uint32 read( lt_uint8 *pDest, lt_uint32 numBytes );
00089    virtual lt_uint32 write( const lt_uint8 *pSrc, lt_uint32 numBytes );
00090    virtual LT_STATUS seek( lt_int64 offset, LTIOSeekDir origin );
00091    virtual lt_int64 tell();
00092 
00093 
00101    Allocator getAllocator() const         {  return m_alloc; }
00102    
00106    Deallocator getDeallocator() const    {  return m_dealloc; } 
00107 
00111    Reallocator getReallocator() const    {  return m_realloc; } 
00112 
00121    const lt_uint8* getData() const  {  return m_data; }
00122 
00123    
00134    LT_STATUS detachAndClose(lt_uint8*& data);
00135 
00143    lt_uint64 size() const           {  return m_userSize; }
00144 
00147    virtual LTIOStreamInf* duplicate();
00148    virtual LT_STATUS getLastError() const;
00149    virtual const char* getID() const;
00150    virtual char *readString(int delimiter);
00151  
00152 protected:
00154    bool grow(lt_uint32 numBytes);
00155 
00157    lt_uint8*   m_data;
00158 
00160    lt_uint32   m_initialSize;
00161 
00163    lt_uint32   m_bufferSize;
00164 
00166    lt_uint32   m_userSize;
00167 
00169    lt_uint32   m_cur;
00170 
00172    bool        m_isOpen; 
00173 
00175    Allocator m_alloc;
00176 
00178    Deallocator m_dealloc;
00179 
00181    Reallocator m_realloc;
00182 
00183    void* defaultRealloc(void*,size_t);
00184 
00185    LT_STATUS m_lastError;
00186 
00187    bool m_isEOF;
00188    
00190    float m_growthRate;
00191 };
00192 
00193 
00194 LT_END_NAMESPACE( LizardTech )
00195 
00196 
00197 #endif   // LT_IO_DYNAMIC_MEM_STREAM_H