libpgf
6.11.42
PGF - Progressive Graphics File
|
Memory stream class. More...
#include <PGFstream.h>
Public Member Functions | |
CPGFMemoryStream (size_t size) THROW_ | |
CPGFMemoryStream (UINT8 *pBuffer, size_t size) THROW_ | |
void | Reinitialize (UINT8 *pBuffer, size_t size) THROW_ |
virtual | ~CPGFMemoryStream () |
virtual void | Write (int *count, void *buffer) THROW_ |
virtual void | Read (int *count, void *buffer) |
virtual void | SetPos (short posMode, INT64 posOff) THROW_ |
virtual UINT64 | GetPos () const |
virtual bool | IsValid () const |
size_t | GetSize () const |
const UINT8 * | GetBuffer () const |
UINT8 * | GetBuffer () |
UINT64 | GetEOS () const |
void | SetEOS (UINT64 length) |
Protected Attributes | |
UINT8 * | m_buffer |
UINT8 * | m_pos |
buffer start address and current buffer address | |
UINT8 * | m_eos |
end of stream (first address beyond written area) | |
size_t | m_size |
buffer size | |
bool | m_allocated |
indicates a new allocated buffer |
Memory stream class.
A PGF stream subclass for internal memory.
Definition at line 106 of file PGFstream.h.
CPGFMemoryStream::CPGFMemoryStream | ( | size_t | size | ) |
Constructor
size | Size of new allocated memory buffer |
Allocate memory block of given size
size | Memory size |
Definition at line 78 of file PGFstream.cpp.
CPGFMemoryStream::CPGFMemoryStream | ( | UINT8 * | pBuffer, |
size_t | size | ||
) |
Constructor. Use already allocated memory of given size
pBuffer | Memory location |
size | Memory size |
Use already allocated memory of given size
pBuffer | Memory location |
size | Memory size |
Definition at line 89 of file PGFstream.cpp.
virtual CPGFMemoryStream::~CPGFMemoryStream | ( | ) | [inline, virtual] |
Definition at line 126 of file PGFstream.h.
{ m_pos = 0; if (m_allocated) { // the memory buffer has been allocated inside of CPMFmemoryStream constructor delete[] m_buffer; m_buffer = 0; } }
const UINT8* CPGFMemoryStream::GetBuffer | ( | ) | const [inline] |
UINT8* CPGFMemoryStream::GetBuffer | ( | ) | [inline] |
UINT64 CPGFMemoryStream::GetEOS | ( | ) | const [inline] |
Definition at line 147 of file PGFstream.h.
virtual UINT64 CPGFMemoryStream::GetPos | ( | ) | const [inline, virtual] |
Get current stream position.
Implements CPGFStream.
Definition at line 137 of file PGFstream.h.
size_t CPGFMemoryStream::GetSize | ( | ) | const [inline] |
virtual bool CPGFMemoryStream::IsValid | ( | ) | const [inline, virtual] |
Check stream validity.
Implements CPGFStream.
Definition at line 138 of file PGFstream.h.
{ return m_buffer != 0; }
void CPGFMemoryStream::Read | ( | int * | count, |
void * | buffer | ||
) | [virtual] |
Read some bytes from this stream and stores them into a buffer.
count | A pointer to a value containing the number of bytes should be read. After this call it contains the number of read bytes. |
buffer | A memory buffer |
Implements CPGFStream.
Definition at line 148 of file PGFstream.cpp.
{ ASSERT(IsValid()); ASSERT(count); ASSERT(buffPtr); ASSERT(m_buffer + m_size >= m_eos); ASSERT(m_pos <= m_eos); if (m_pos + *count <= m_eos) { memcpy(buffPtr, m_pos, *count); m_pos += *count; } else { // end of memory block reached -> read only until end *count = (int)__max(0, m_eos - m_pos); memcpy(buffPtr, m_pos, *count); m_pos += *count; } ASSERT(m_pos <= m_eos); }
void CPGFMemoryStream::Reinitialize | ( | UINT8 * | pBuffer, |
size_t | size | ||
) |
Constructor. Use already allocated memory of given size
pBuffer | Memory location |
size | Memory size |
Use already allocated memory of given size
pBuffer | Memory location |
size | Memory size |
Definition at line 102 of file PGFstream.cpp.
void CPGFMemoryStream::SetEOS | ( | UINT64 | length | ) | [inline] |
length | Stream length (= relative position of end of stream) |
Definition at line 149 of file PGFstream.h.
void CPGFMemoryStream::SetPos | ( | short | posMode, |
INT64 | posOff | ||
) | [virtual] |
Set stream position either absolute or relative.
posMode | A position mode (FSFromStart, FSFromCurrent, FSFromEnd) |
posOff | A new stream position (absolute positioning) or a position offset (relative positioning) |
Implements CPGFStream.
Definition at line 168 of file PGFstream.cpp.
void CPGFMemoryStream::Write | ( | int * | count, |
void * | buffer | ||
) | [virtual] |
Write some bytes out of a buffer into this stream.
count | A pointer to a value containing the number of bytes should be written. After this call it contains the number of written bytes. |
buffer | A memory buffer |
Implements CPGFStream.
Definition at line 111 of file PGFstream.cpp.
{ ASSERT(count); ASSERT(buffPtr); ASSERT(IsValid()); const size_t deltaSize = 0x4000 + *count; if (m_pos + *count <= m_buffer + m_size) { memcpy(m_pos, buffPtr, *count); m_pos += *count; if (m_pos > m_eos) m_eos = m_pos; } else if (m_allocated) { // memory block is too small -> reallocate a deltaSize larger block size_t offset = m_pos - m_buffer; UINT8 *buf_tmp = (UINT8 *)realloc(m_buffer, m_size + deltaSize); if (!buf_tmp) { delete[] m_buffer; m_buffer = 0; ReturnWithError(InsufficientMemory); } else { m_buffer = buf_tmp; } m_size += deltaSize; // reposition m_pos m_pos = m_buffer + offset; // write block memcpy(m_pos, buffPtr, *count); m_pos += *count; if (m_pos > m_eos) m_eos = m_pos; } else { ReturnWithError(InsufficientMemory); } ASSERT(m_pos <= m_eos); }
bool CPGFMemoryStream::m_allocated [protected] |
indicates a new allocated buffer
Definition at line 111 of file PGFstream.h.
UINT8* CPGFMemoryStream::m_buffer [protected] |
Definition at line 108 of file PGFstream.h.
UINT8* CPGFMemoryStream::m_eos [protected] |
end of stream (first address beyond written area)
Definition at line 109 of file PGFstream.h.
UINT8 * CPGFMemoryStream::m_pos [protected] |
buffer start address and current buffer address
Definition at line 108 of file PGFstream.h.
size_t CPGFMemoryStream::m_size [protected] |
buffer size
Definition at line 110 of file PGFstream.h.