00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
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
00151 protected:
00153 bool grow(lt_uint32 numBytes);
00154
00156 lt_uint8* m_data;
00157
00159 lt_uint32 m_initialSize;
00160
00162 lt_uint32 m_bufferSize;
00163
00165 lt_uint32 m_userSize;
00166
00168 lt_uint32 m_cur;
00169
00171 bool m_isOpen;
00172
00174 Allocator m_alloc;
00175
00177 Deallocator m_dealloc;
00178
00180 Reallocator m_realloc;
00181
00182 void* defaultRealloc(void*,size_t);
00183
00184 LT_STATUS m_lastError;
00185
00186 bool m_isEOF;
00187
00189 float m_growthRate;
00190 };
00191
00192
00193 LT_END_NAMESPACE( LizardTech )
00194
00195
00196 #endif // LT_IO_DYNAMIC_MEM_STREAM_H