* New wxStreams (to be documented), new classes: wxBufferedStreams,
wxTextStreams git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2962 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -153,6 +153,7 @@ wx_include_HEADERS = \
|
||||
textctrl.h \
|
||||
textdlg.h \
|
||||
textfile.h \
|
||||
txtstrm.h \
|
||||
thread.h \
|
||||
time.h \
|
||||
timer.h \
|
||||
|
@@ -20,28 +20,54 @@
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
class WXDLLEXPORT wxDataInputStream: public wxFilterInputStream {
|
||||
class WXDLLEXPORT wxDataInputStream {
|
||||
public:
|
||||
wxDataInputStream(wxInputStream& s);
|
||||
virtual ~wxDataInputStream();
|
||||
~wxDataInputStream();
|
||||
|
||||
wxUint32 Read32();
|
||||
wxUint16 Read16();
|
||||
wxUint8 Read8();
|
||||
double ReadDouble();
|
||||
wxString ReadString();
|
||||
|
||||
wxDataInputStream& operator>>(wxString& s);
|
||||
wxDataInputStream& operator>>(wxInt8& c);
|
||||
wxDataInputStream& operator>>(wxInt16& i);
|
||||
wxDataInputStream& operator>>(wxInt32& i);
|
||||
wxDataInputStream& operator>>(wxUint8& c);
|
||||
wxDataInputStream& operator>>(wxUint16& i);
|
||||
wxDataInputStream& operator>>(wxUint32& i);
|
||||
wxDataInputStream& operator>>(double& i);
|
||||
wxDataInputStream& operator>>(float& f);
|
||||
protected:
|
||||
wxInputStream *m_input;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxDataOutputStream: public wxFilterOutputStream {
|
||||
class WXDLLEXPORT wxDataOutputStream {
|
||||
public:
|
||||
wxDataOutputStream(wxOutputStream& s);
|
||||
virtual ~wxDataOutputStream();
|
||||
~wxDataOutputStream();
|
||||
|
||||
void Write32(wxUint32 i);
|
||||
void Write16(wxUint16 i);
|
||||
void Write8(wxUint8 i);
|
||||
void WriteDouble(double d);
|
||||
void WriteString(const wxString& string);
|
||||
|
||||
wxDataOutputStream& operator<<(const wxChar *string);
|
||||
wxDataOutputStream& operator<<(wxString& string);
|
||||
wxDataOutputStream& operator<<(wxInt8 c);
|
||||
wxDataOutputStream& operator<<(wxInt16 i);
|
||||
wxDataOutputStream& operator<<(wxInt32 i);
|
||||
wxDataOutputStream& operator<<(wxUint8 c);
|
||||
wxDataOutputStream& operator<<(wxUint16 i);
|
||||
wxDataOutputStream& operator<<(wxUint32 i);
|
||||
wxDataOutputStream& operator<<(double f);
|
||||
wxDataOutputStream& operator<<(float f);
|
||||
|
||||
protected:
|
||||
wxOutputStream *m_output;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -83,6 +83,7 @@ class SocketWaiter: public wxThread {
|
||||
wxSocketInternal *m_internal;
|
||||
int m_fd;
|
||||
};
|
||||
#endif
|
||||
|
||||
class SocketRequester
|
||||
#if wxUSE_THREADS
|
||||
@@ -99,17 +100,17 @@ class SocketRequester
|
||||
|
||||
bool WaitFor(wxSocketBase::wxRequestNotify req, int millisec);
|
||||
|
||||
#if wxUSE_THREADS
|
||||
// Thread Entry point
|
||||
// ---
|
||||
virtual void *Entry();
|
||||
#endif
|
||||
|
||||
public:
|
||||
wxSocketBase *m_socket;
|
||||
wxSocketInternal *m_internal;
|
||||
int m_fd;
|
||||
};
|
||||
#endif
|
||||
// wxUSE_THREADS
|
||||
|
||||
class wxSocketInternal {
|
||||
public:
|
||||
@@ -134,6 +135,7 @@ class wxSocketInternal {
|
||||
void QueueRequest(SockRequest *request, bool async);
|
||||
void WaitForEnd(SockRequest *request);
|
||||
|
||||
// Used by SocketRequester
|
||||
SockRequest *WaitForReq();
|
||||
void EndRequest(SockRequest *req);
|
||||
public:
|
||||
|
@@ -34,85 +34,6 @@ typedef wxOutputStream& (*__wxOutputManip)(wxOutputStream&);
|
||||
|
||||
WXDLLEXPORT wxOutputStream& wxEndL(wxOutputStream& o_stream);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Stream buffer
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxStreamBuffer {
|
||||
public:
|
||||
typedef enum {
|
||||
read = 0, write, read_write
|
||||
} BufMode;
|
||||
|
||||
// -----------
|
||||
// ctor & dtor
|
||||
// -----------
|
||||
wxStreamBuffer(wxStreamBase& stream, BufMode mode);
|
||||
wxStreamBuffer(BufMode mode);
|
||||
wxStreamBuffer(const wxStreamBuffer& buf);
|
||||
~wxStreamBuffer();
|
||||
|
||||
// -----------
|
||||
// Filtered IO
|
||||
// -----------
|
||||
size_t Read(void *buffer, size_t size);
|
||||
size_t Read(wxStreamBuffer *buf);
|
||||
size_t Write(const void *buffer, size_t size);
|
||||
size_t Write(wxStreamBuffer *buf);
|
||||
|
||||
size_t WriteBack(const char *buffer, size_t size);
|
||||
bool WriteBack(char c);
|
||||
char GetChar();
|
||||
void PutChar(char c);
|
||||
off_t Tell() const;
|
||||
off_t Seek(off_t pos, wxSeekMode mode);
|
||||
|
||||
// --------------
|
||||
// Buffer control
|
||||
// --------------
|
||||
void ResetBuffer();
|
||||
void SetBufferIO(char *buffer_start, char *buffer_end);
|
||||
void SetBufferIO(size_t bufsize);
|
||||
char *GetBufferStart() const { return m_buffer_start; }
|
||||
char *GetBufferEnd() const { return m_buffer_end; }
|
||||
char *GetBufferPos() const { return m_buffer_pos; }
|
||||
off_t GetIntPosition() const { return m_buffer_pos-m_buffer_start; }
|
||||
void SetIntPosition(off_t pos) { m_buffer_pos = m_buffer_start+pos; }
|
||||
size_t GetLastAccess() const { return m_buffer_end-m_buffer_start; }
|
||||
|
||||
void Fixed(bool fixed) { m_fixed = fixed; }
|
||||
void Flushable(bool f) { m_flushable = f; }
|
||||
|
||||
bool FlushBuffer();
|
||||
bool FillBuffer();
|
||||
size_t GetDataLeft();
|
||||
|
||||
// --------------
|
||||
// Administration
|
||||
// --------------
|
||||
wxStreamBase *Stream() { return m_stream; }
|
||||
|
||||
protected:
|
||||
char *AllocSpaceWBack(size_t needed_size);
|
||||
size_t GetWBack(char *buf, size_t bsize);
|
||||
|
||||
void GetFromBuffer(void *buffer, size_t size);
|
||||
void PutToBuffer(const void *buffer, size_t size);
|
||||
|
||||
protected:
|
||||
char *m_buffer_start, *m_buffer_end, *m_buffer_pos;
|
||||
size_t m_buffer_size;
|
||||
|
||||
char *m_wback;
|
||||
size_t m_wbacksize, m_wbackcur;
|
||||
|
||||
bool m_fixed, m_flushable;
|
||||
|
||||
wxStreamBase *m_stream;
|
||||
BufMode m_mode;
|
||||
bool m_destroybuf, m_destroystream;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxStream: base classes
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -138,7 +59,6 @@ class WXDLLEXPORT wxStreamBase {
|
||||
virtual size_t StreamSize() const { return ~((size_t)0); }
|
||||
|
||||
protected:
|
||||
friend class wxStreamBuffer;
|
||||
|
||||
virtual size_t OnSysRead(void *buffer, size_t bufsize);
|
||||
virtual size_t OnSysWrite(const void *buffer, size_t bufsize);
|
||||
@@ -146,6 +66,8 @@ class WXDLLEXPORT wxStreamBase {
|
||||
virtual off_t OnSysTell() const;
|
||||
|
||||
protected:
|
||||
friend class wxStreamBuffer;
|
||||
|
||||
size_t m_lastcount;
|
||||
wxStreamError m_lasterror;
|
||||
};
|
||||
@@ -153,7 +75,6 @@ class WXDLLEXPORT wxStreamBase {
|
||||
class WXDLLEXPORT wxInputStream: public wxStreamBase {
|
||||
public:
|
||||
wxInputStream();
|
||||
wxInputStream(wxStreamBuffer *sbuf);
|
||||
virtual ~wxInputStream();
|
||||
|
||||
// IO functions
|
||||
@@ -161,78 +82,56 @@ class WXDLLEXPORT wxInputStream: public wxStreamBase {
|
||||
char GetC();
|
||||
virtual wxInputStream& Read(void *buffer, size_t size);
|
||||
wxInputStream& Read(wxOutputStream& stream_out);
|
||||
wxString ReadLine();
|
||||
|
||||
// Position functions
|
||||
off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
off_t TellI() const;
|
||||
virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
virtual off_t TellI() const;
|
||||
|
||||
// State functions
|
||||
wxStreamBuffer *InputStreamBuffer() { return m_i_streambuf; }
|
||||
size_t LastRead() { return wxStreamBase::m_lastcount; }
|
||||
virtual size_t LastRead() { return wxStreamBase::m_lastcount; }
|
||||
|
||||
// Ungetch
|
||||
size_t Ungetch(void *buffer, size_t size);
|
||||
bool Ungetch(char c);
|
||||
|
||||
// Operators
|
||||
wxInputStream& operator>>(wxOutputStream& out) { return Read(out); }
|
||||
wxInputStream& operator>>(wxString& line);
|
||||
wxInputStream& operator>>(char& c);
|
||||
wxInputStream& operator>>(signed short& i);
|
||||
wxInputStream& operator>>(signed int& i);
|
||||
wxInputStream& operator>>(signed long& i);
|
||||
wxInputStream& operator>>(unsigned char& c);
|
||||
wxInputStream& operator>>(unsigned short& i);
|
||||
wxInputStream& operator>>(unsigned int& i);
|
||||
wxInputStream& operator>>(unsigned long& i);
|
||||
wxInputStream& operator>>(double& i);
|
||||
wxInputStream& operator>>(float& f) { double d; operator>>((double&)d); f = (float)d; return *this; }
|
||||
#if wxUSE_SERIAL
|
||||
wxInputStream& operator>>(wxObject *& obj);
|
||||
#endif
|
||||
wxInputStream& operator>>( __wxInputManip func) { return func(*this); }
|
||||
|
||||
protected:
|
||||
bool m_i_destroybuf;
|
||||
wxStreamBuffer *m_i_streambuf;
|
||||
// Ungetch managers
|
||||
char *m_wback;
|
||||
size_t m_wbacksize;
|
||||
size_t m_wbackcur;
|
||||
|
||||
char *AllocSpaceWBack(size_t needed_size);
|
||||
size_t GetWBack(char *buf, size_t bsize);
|
||||
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxOutputStream: public wxStreamBase {
|
||||
public:
|
||||
wxOutputStream();
|
||||
wxOutputStream(wxStreamBuffer *sbuf);
|
||||
virtual ~wxOutputStream();
|
||||
|
||||
virtual wxOutputStream& Write(const void *buffer, size_t size);
|
||||
wxOutputStream& Write(wxInputStream& stream_in);
|
||||
void WriteLine(const wxString& line);
|
||||
|
||||
off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
off_t TellO() const;
|
||||
virtual off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
virtual off_t TellO() const;
|
||||
|
||||
size_t LastWrite() const { return wxStreamBase::m_lastcount; }
|
||||
wxStreamBuffer *OutputStreamBuffer() { return m_o_streambuf; }
|
||||
virtual size_t LastWrite() const { return wxStreamBase::m_lastcount; }
|
||||
|
||||
void Sync();
|
||||
virtual void Sync();
|
||||
|
||||
wxOutputStream& operator<<(wxInputStream& out) { return Write(out); }
|
||||
wxOutputStream& operator<<(const char *string);
|
||||
wxOutputStream& operator<<(wxString& string);
|
||||
wxOutputStream& operator<<(char c);
|
||||
wxOutputStream& operator<<(signed short i);
|
||||
wxOutputStream& operator<<(signed int i);
|
||||
wxOutputStream& operator<<(signed long i);
|
||||
wxOutputStream& operator<<(unsigned char c);
|
||||
wxOutputStream& operator<<(unsigned short i);
|
||||
wxOutputStream& operator<<(unsigned int i);
|
||||
wxOutputStream& operator<<(unsigned long i);
|
||||
wxOutputStream& operator<<(double f);
|
||||
wxOutputStream& operator<<(float f) { return operator<<((double)f); }
|
||||
#if wxUSE_SERIAL
|
||||
wxOutputStream& operator<<(wxObject& obj);
|
||||
#endif
|
||||
wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); }
|
||||
|
||||
protected:
|
||||
bool m_o_destroybuf;
|
||||
wxStreamBuffer *m_o_streambuf;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -267,6 +166,130 @@ class WXDLLEXPORT wxFilterOutputStream: public wxOutputStream {
|
||||
wxOutputStream *m_parent_o_stream;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Stream buffer
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxStreamBuffer {
|
||||
public:
|
||||
typedef enum {
|
||||
read = 0, write, read_write
|
||||
} BufMode;
|
||||
|
||||
// -----------
|
||||
// ctor & dtor
|
||||
// -----------
|
||||
wxStreamBuffer(wxStreamBase& stream, BufMode mode);
|
||||
wxStreamBuffer(BufMode mode);
|
||||
wxStreamBuffer(const wxStreamBuffer& buf);
|
||||
~wxStreamBuffer();
|
||||
|
||||
// -----------
|
||||
// Filtered IO
|
||||
// -----------
|
||||
size_t Read(void *buffer, size_t size);
|
||||
size_t Read(wxStreamBuffer *buf);
|
||||
size_t Write(const void *buffer, size_t size);
|
||||
size_t Write(wxStreamBuffer *buf);
|
||||
|
||||
char GetChar();
|
||||
void PutChar(char c);
|
||||
off_t Tell() const;
|
||||
off_t Seek(off_t pos, wxSeekMode mode);
|
||||
|
||||
// --------------
|
||||
// Buffer control
|
||||
// --------------
|
||||
void ResetBuffer();
|
||||
void SetBufferIO(char *buffer_start, char *buffer_end);
|
||||
void SetBufferIO(size_t bufsize);
|
||||
char *GetBufferStart() const { return m_buffer_start; }
|
||||
char *GetBufferEnd() const { return m_buffer_end; }
|
||||
char *GetBufferPos() const { return m_buffer_pos; }
|
||||
off_t GetIntPosition() const { return m_buffer_pos-m_buffer_start; }
|
||||
void SetIntPosition(off_t pos) { m_buffer_pos = m_buffer_start+pos; }
|
||||
size_t GetLastAccess() const { return m_buffer_end-m_buffer_start; }
|
||||
|
||||
void Fixed(bool fixed) { m_fixed = fixed; }
|
||||
void Flushable(bool f) { m_flushable = f; }
|
||||
|
||||
bool FlushBuffer();
|
||||
bool FillBuffer();
|
||||
size_t GetDataLeft();
|
||||
|
||||
// --------------
|
||||
// Administration
|
||||
// --------------
|
||||
wxStreamBase *Stream() { return m_stream; }
|
||||
|
||||
protected:
|
||||
void GetFromBuffer(void *buffer, size_t size);
|
||||
void PutToBuffer(const void *buffer, size_t size);
|
||||
|
||||
protected:
|
||||
char *m_buffer_start, *m_buffer_end, *m_buffer_pos;
|
||||
size_t m_buffer_size;
|
||||
|
||||
char *m_wback;
|
||||
size_t m_wbacksize, m_wbackcur;
|
||||
|
||||
bool m_fixed, m_flushable;
|
||||
|
||||
wxStreamBase *m_stream;
|
||||
BufMode m_mode;
|
||||
bool m_destroybuf, m_destroystream;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// wxBufferedStreams
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class wxBufferedInputStream: public wxFilterInputStream {
|
||||
public:
|
||||
wxBufferedInputStream(wxInputStream& stream);
|
||||
~wxBufferedInputStream();
|
||||
|
||||
wxInputStream& Read(void *buffer, size_t size);
|
||||
|
||||
// Position functions
|
||||
off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
off_t TellI() const;
|
||||
|
||||
wxStreamBuffer *InputStreamBuffer() const { return m_i_streambuf; }
|
||||
|
||||
protected:
|
||||
size_t OnSysRead(void *buffer, size_t bufsize);
|
||||
off_t OnSysSeek(off_t seek, wxSeekMode mode);
|
||||
off_t OnSysTell() const;
|
||||
|
||||
protected:
|
||||
wxStreamBuffer *m_i_streambuf;
|
||||
};
|
||||
|
||||
class wxBufferedOutputStream: public wxFilterOutputStream {
|
||||
public:
|
||||
wxBufferedOutputStream(wxOutputStream& stream);
|
||||
~wxBufferedOutputStream();
|
||||
|
||||
wxOutputStream& Write(const void *buffer, size_t size);
|
||||
|
||||
// Position functions
|
||||
off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
off_t TellO() const;
|
||||
|
||||
void Sync();
|
||||
|
||||
wxStreamBuffer *OutputStreamBuffer() const { return m_o_streambuf; }
|
||||
|
||||
protected:
|
||||
size_t OnSysWrite(const void *buffer, size_t bufsize);
|
||||
off_t OnSysSeek(off_t seek, wxSeekMode mode);
|
||||
off_t OnSysTell() const;
|
||||
|
||||
protected:
|
||||
wxStreamBuffer *m_o_streambuf;
|
||||
};
|
||||
|
||||
#endif
|
||||
// wxUSE_STREAMS
|
||||
|
||||
|
79
include/wx/txtstrm.h
Normal file
79
include/wx/txtstrm.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: txtstrm.h
|
||||
// Purpose: Text stream classes
|
||||
// Author: Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 28/06/1998
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Guilhem Lavaux
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_TXTSTREAM_H_
|
||||
#define _WX_TXTSTREAM_H_
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "txtstrm.h"
|
||||
#endif
|
||||
|
||||
#include <wx/stream.h>
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
class WXDLLEXPORT wxTextInputStream {
|
||||
public:
|
||||
wxTextInputStream(wxInputStream& s);
|
||||
~wxTextInputStream();
|
||||
|
||||
wxUint32 Read32();
|
||||
wxUint16 Read16();
|
||||
wxUint8 Read8();
|
||||
double ReadDouble();
|
||||
wxString ReadString();
|
||||
|
||||
// Operators
|
||||
wxTextInputStream& operator>>(wxString& line);
|
||||
wxTextInputStream& operator>>(wxInt8& c);
|
||||
wxTextInputStream& operator>>(wxInt16& i);
|
||||
wxTextInputStream& operator>>(wxInt32& i);
|
||||
wxTextInputStream& operator>>(wxUint8& c);
|
||||
wxTextInputStream& operator>>(wxUint16& i);
|
||||
wxTextInputStream& operator>>(wxUint32& i);
|
||||
wxTextInputStream& operator>>(double& i);
|
||||
wxTextInputStream& operator>>(float& f);
|
||||
|
||||
protected:
|
||||
wxInputStream *m_input;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxTextOutputStream {
|
||||
public:
|
||||
wxTextOutputStream(wxOutputStream& s);
|
||||
~wxTextOutputStream();
|
||||
|
||||
void Write32(wxUint32 i);
|
||||
void Write16(wxUint16 i);
|
||||
void Write8(wxUint8 i);
|
||||
void WriteDouble(double d);
|
||||
void WriteString(const wxString& string);
|
||||
|
||||
wxTextOutputStream& operator<<(const wxChar *string);
|
||||
wxTextOutputStream& operator<<(const wxString& string);
|
||||
wxTextOutputStream& operator<<(wxInt8 c);
|
||||
wxTextOutputStream& operator<<(wxInt16 c);
|
||||
wxTextOutputStream& operator<<(wxInt32 c);
|
||||
wxTextOutputStream& operator<<(wxUint8 c);
|
||||
wxTextOutputStream& operator<<(wxUint16 c);
|
||||
wxTextOutputStream& operator<<(wxUint32 c);
|
||||
wxTextOutputStream& operator<<(double f);
|
||||
wxTextOutputStream& operator<<(float f);
|
||||
|
||||
protected:
|
||||
wxOutputStream *m_output;
|
||||
};
|
||||
|
||||
#endif
|
||||
// wxUSE_STREAMS
|
||||
|
||||
#endif
|
||||
// _WX_DATSTREAM_H_
|
Reference in New Issue
Block a user