* wxSocket fixes

* wxStream: - new inheritance, new stream buffer, nearly the same API for the
              end user
            - updated other streams consequently
* wxGTK: some change to make it compile on GTK 1.0 and GTK 1.1
* small changes on wxThread to prepare a more reentrant lib
* wxVariant works with wxStream too now


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@829 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux
1998-10-14 17:36:50 +00:00
parent 1b19f0560f
commit 75ed1d15d0
30 changed files with 706 additions and 731 deletions

View File

@@ -23,52 +23,15 @@
#pragma hdrstop
#endif
// ----------------------------------------------------------------------------
// wxMemoryStreamBase
// ----------------------------------------------------------------------------
wxMemoryStreamBase::wxMemoryStreamBase()
{
m_buffer = NULL;
m_iolimit = 0;
m_persistent = FALSE;
m_length = 0;
}
wxMemoryStreamBase::~wxMemoryStreamBase()
{
if (!m_persistent && m_buffer)
free(m_buffer);
}
bool wxMemoryStreamBase::ChangeBufferSize(size_t new_size)
{
if (m_iolimit == 1)
return FALSE;
m_length = new_size;
if (!m_buffer)
m_buffer = (char *)malloc(m_length);
else
m_buffer = (char *)realloc(m_buffer, m_length);
return (m_buffer != NULL);
}
// ----------------------------------------------------------------------------
// wxMemoryInputStream
// ----------------------------------------------------------------------------
wxMemoryInputStream::wxMemoryInputStream(const char *data, size_t len)
: wxInputStream()
{
m_persistent = TRUE;
m_length = len;
m_buffer = (char *)data; // It's bad.
m_position_i = 0;
m_lastread = 0;
m_eof = FALSE;
m_iolimit = 1;
m_i_streambuf->SetBufferIO(0);
m_i_streambuf->SetBufferIO((char *)data, data+len);
m_i_streambuf->Fixed(TRUE);
}
wxMemoryInputStream::~wxMemoryInputStream()
@@ -77,51 +40,7 @@ wxMemoryInputStream::~wxMemoryInputStream()
char wxMemoryInputStream::Peek()
{
// wxStreamBuffer is disabled so just peek the current character.
return m_buffer[m_position_i];
}
size_t wxMemoryInputStream::DoRead(void *buffer, size_t size)
{
if (m_iolimit == 2) {
m_eof = TRUE;
return 0;
}
if (m_position_i+size > m_length)
size = m_length-m_position_i;
memcpy((void *)((unsigned long)buffer+m_position_i), m_buffer, size);
m_position_i += size;
return size;
}
off_t wxMemoryInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
{
if (m_iolimit == 2)
return 0;
switch (mode) {
case wxFromStart:
if ((size_t)pos > m_length)
return m_position_i;
return (m_position_i = pos);
case wxFromCurrent:
if ((size_t)(m_position_i+pos) > m_length)
return m_position_i;
return (m_position_i += pos);
case wxFromEnd:
if ((size_t)(m_length-pos) > m_length)
return m_position_i;
return (m_position_i = m_length-pos);
}
return m_position_i;
return m_i_streambuf->GetBufferStart()[m_i_streambuf->GetIntPosition()];
}
// ----------------------------------------------------------------------------
@@ -129,82 +48,13 @@ off_t wxMemoryInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
// ----------------------------------------------------------------------------
wxMemoryOutputStream::wxMemoryOutputStream(char *data, size_t len)
: wxOutputStream()
{
m_persistent = FALSE;
m_buffer = data;
m_length = len;
m_position_o = 0;
m_lastwrite = 0;
m_bad = FALSE;
m_iolimit = 2;
m_o_streambuf->SetBufferIO(0);
if (data)
m_o_streambuf->SetBufferIO(data, data+len);
m_o_streambuf->Fixed(TRUE);
}
wxMemoryOutputStream::~wxMemoryOutputStream()
{
Sync();
}
size_t wxMemoryOutputStream::DoWrite(const void *buffer, size_t size)
{
if (m_iolimit == 1) {
m_bad = TRUE;
return 0;
}
if (m_position_o+size > m_length)
if (!ChangeBufferSize(m_position_o+size)) {
m_bad = TRUE;
return 0;
}
memcpy(m_buffer+m_position_o, buffer, size);
m_position_o += size;
return size;
}
off_t wxMemoryOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode)
{
if (m_iolimit == 1)
return 0;
switch (mode) {
case wxFromStart:
if ((size_t)pos > m_length)
return m_position_o;
return (m_position_o = pos);
case wxFromCurrent:
if ((size_t)(m_position_o+pos) > m_length)
return m_position_o;
return (m_position_o += pos);
case wxFromEnd:
if ((size_t)(m_length-pos) > m_length)
return m_position_o;
return (m_position_o = m_length-pos);
}
return m_position_o;
}
// ----------------------------------------------------------------------------
// wxMemoryStream
// ----------------------------------------------------------------------------
wxMemoryStream::wxMemoryStream(char *data, size_t len)
: wxMemoryInputStream(NULL, 0), wxMemoryOutputStream(NULL, 0)
{
m_persistent = FALSE;
m_buffer = data;
m_length = len;
m_iolimit = 0;
}
wxMemoryStream::~wxMemoryStream()
{
}