added wxStreamBuffer::Truncate() (patch 1687081)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45561 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-04-21 18:11:37 +00:00
parent 10bd1f7d3b
commit df18cc7aa1
4 changed files with 35 additions and 0 deletions

View File

@@ -81,6 +81,7 @@ All:
- Implemented wxMemoryInputStream::CanRead()
- Added wxEXEC_BLOCK flag (Hank Schultz)
- Add support for wxStream-derived classes to wxRTTI (Stas Sergeev)
- Added wxStreamBuffer::Truncate() (Stas Sergeev)
All (GUI):

View File

@@ -184,6 +184,17 @@ the beginning of the stream. Otherwise, it returns wxInvalidOffset.
Resets to the initial state variables concerning the buffer.
\membersection{wxStreamBuffer::Truncate}\label{wxstreambuffertruncate}
\func{void}{Truncate}{\void}
Truncates the buffer to the current position.
Note: Truncate() cannot be used to enlarge the buffer. This is
usually not needed since the buffer expands automatically.
\membersection{wxStreamBuffer::SetBufferIO}\label{wxstreambuffersetbufferio}
\func{void}{SetBufferIO}{\param{char*}{ buffer\_start}, \param{char*}{ buffer\_end}}

View File

@@ -434,6 +434,7 @@ public:
// Buffer control
void ResetBuffer();
void Truncate();
// NB: the buffer must always be allocated with malloc() if takeOwn is
// true as it will be deallocated by free()

View File

@@ -192,6 +192,28 @@ void wxStreamBuffer::ResetBuffer()
: m_buffer_start;
}
void wxStreamBuffer::Truncate()
{
size_t new_size = m_buffer_pos - m_buffer_start;
if ( new_size == m_buffer_size )
return;
if ( !new_size )
{
FreeBuffer();
InitBuffer();
return;
}
char *new_start = (char *)realloc(m_buffer_start, new_size);
wxCHECK_RET( new_size, _T("shrinking buffer shouldn't fail") );
m_buffer_start = new_start;
m_buffer_size = new_size;
m_buffer_end = m_buffer_start + m_buffer_size;
m_buffer_pos = m_buffer_end;
}
// fill the buffer with as much data as possible (only for read buffers)
bool wxStreamBuffer::FillBuffer()
{