]> git.saurik.com Git - wxWidgets.git/blame - include/wx/stream.h
Added GetMessage to those that are undef'ed and reimplemented as
[wxWidgets.git] / include / wx / stream.h
CommitLineData
32fc4afb
GL
1/////////////////////////////////////////////////////////////////////////////
2// Name: stream.h
3// Purpose: "wxWindows stream" base classes
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 11/07/98
7// RCS-ID: $Id$
8// Copyright: (c) Guilhem Lavaux
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_WXSTREAM_H__
13#define _WX_WXSTREAM_H__
32fc4afb
GL
14
15#ifdef __GNUG__
79c3e0e1 16#pragma interface
32fc4afb
GL
17#endif
18
19#include <stdio.h>
45ea509a
VZ
20#include "wx/object.h"
21#include "wx/string.h"
1678ad78
GL
22#include "wx/filefn.h" // for off_t, wxInvalidOffset and wxSeekMode
23
75ed1d15 24class WXDLLEXPORT wxStreamBase;
1678ad78
GL
25class WXDLLEXPORT wxInputStream;
26class WXDLLEXPORT wxOutputStream;
27
28typedef wxInputStream& (*__wxInputManip)(wxInputStream&);
29typedef wxOutputStream& (*__wxOutputManip)(wxOutputStream&);
30
184b5d99 31WXDLLEXPORT wxOutputStream& wxEndL(wxOutputStream& o_stream);
1678ad78 32
f4ada568
GL
33// ---------------------------------------------------------------------------
34// Stream buffer
35// ---------------------------------------------------------------------------
36
1678ad78
GL
37class WXDLLEXPORT wxStreamBuffer {
38 public:
75ed1d15 39 typedef enum {
8ef6a930 40 read = 0, write, read_write
75ed1d15
GL
41 } BufMode;
42
43 // -----------
44 // ctor & dtor
45 // -----------
46 wxStreamBuffer(wxStreamBase& stream, BufMode mode);
84b46c35
GL
47 wxStreamBuffer(BufMode mode);
48 wxStreamBuffer(const wxStreamBuffer& buf);
1678ad78
GL
49 ~wxStreamBuffer();
50
75ed1d15
GL
51 // -----------
52 // Filtered IO
53 // -----------
8ef6a930
GL
54 size_t Read(void *buffer, size_t size);
55 size_t Read(wxStreamBuffer *buf);
56 size_t Write(const void *buffer, size_t size);
57 size_t Write(wxStreamBuffer *buf);
58
59 size_t WriteBack(const char *buffer, size_t size);
75ed1d15 60 bool WriteBack(char c);
84b46c35
GL
61 char GetChar();
62 void PutChar(char c);
75ed1d15
GL
63 off_t Tell() const;
64 off_t Seek(off_t pos, wxSeekMode mode);
65
66 // --------------
67 // Buffer control
68 // --------------
69 void ResetBuffer();
1678ad78
GL
70 void SetBufferIO(char *buffer_start, char *buffer_end);
71 void SetBufferIO(size_t bufsize);
75ed1d15
GL
72 char *GetBufferStart() const { return m_buffer_start; }
73 char *GetBufferEnd() const { return m_buffer_end; }
74 char *GetBufferPos() const { return m_buffer_pos; }
75 off_t GetIntPosition() const { return m_buffer_pos-m_buffer_start; }
76 void SetIntPosition(off_t pos) { m_buffer_pos = m_buffer_start+pos; }
77 size_t GetLastAccess() const { return m_buffer_end-m_buffer_start; }
84b46c35 78
75ed1d15 79 void Fixed(bool fixed) { m_fixed = fixed; }
84b46c35 80 void Flushable(bool f) { m_flushable = f; }
75ed1d15
GL
81
82 bool FlushBuffer();
83 bool FillBuffer();
8ef6a930
GL
84 size_t GetDataLeft();
85
86 // --------------
87 // Administration
88 // --------------
89 wxStreamBase *Stream() { return m_stream; }
75ed1d15
GL
90
91 protected:
92 char *AllocSpaceWBack(size_t needed_size);
93 size_t GetWBack(char *buf, size_t bsize);
94
95 void GetFromBuffer(void *buffer, size_t size);
96 void PutToBuffer(const void *buffer, size_t size);
1678ad78
GL
97
98 protected:
99 char *m_buffer_start, *m_buffer_end, *m_buffer_pos;
100 size_t m_buffer_size;
101
75ed1d15
GL
102 char *m_wback;
103 size_t m_wbacksize, m_wbackcur;
104
84b46c35 105 bool m_fixed, m_flushable;
75ed1d15
GL
106
107 wxStreamBase *m_stream;
108 BufMode m_mode;
8ef6a930 109 bool m_destroybuf, m_destroystream;
1678ad78 110};
eda3efe2 111
f4ada568
GL
112// ---------------------------------------------------------------------------
113// wxStream: base classes
114// ---------------------------------------------------------------------------
115
75ed1d15 116typedef enum {
926c550d
GL
117 wxStream_NOERROR = 0,
118 wxStream_EOF,
119 wxStream_WRITE_ERR,
120 wxStream_READ_ERR
75ed1d15
GL
121} wxStreamError;
122
123class WXDLLEXPORT wxStreamBase {
124 public:
125 wxStreamBase();
126 virtual ~wxStreamBase();
127
84b46c35
GL
128 wxStreamError LastError() const { return m_lasterror; }
129 virtual size_t StreamSize() const { return ~((size_t)0); }
75ed1d15
GL
130
131 protected:
132 friend class wxStreamBuffer;
133
134 virtual size_t OnSysRead(void *buffer, size_t bufsize);
135 virtual size_t OnSysWrite(const void *buffer, size_t bufsize);
136 virtual off_t OnSysSeek(off_t seek, wxSeekMode mode);
84b46c35 137 virtual off_t OnSysTell() const;
75ed1d15
GL
138
139 protected:
140 size_t m_lastcount;
141 wxStreamError m_lasterror;
142};
143
144class WXDLLEXPORT wxInputStream: public wxStreamBase {
32fc4afb
GL
145 public:
146 wxInputStream();
75ed1d15 147 wxInputStream(wxStreamBuffer *sbuf);
32fc4afb
GL
148 virtual ~wxInputStream();
149
1678ad78 150 // IO functions
75ed1d15
GL
151 virtual char Peek();
152 char GetC();
41895a05 153 virtual wxInputStream& Read(void *buffer, size_t size);
32fc4afb
GL
154 wxInputStream& Read(wxOutputStream& stream_out);
155
1678ad78 156 // Position functions
75ed1d15
GL
157 off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
158 off_t TellI() const;
32fc4afb 159
1678ad78 160 // State functions
1678ad78 161 wxStreamBuffer *InputStreamBuffer() { return m_i_streambuf; }
75ed1d15 162 size_t LastRead() { return wxStreamBase::m_lastcount; }
0cd9bfe8 163
1678ad78 164 // Operators
0cd9bfe8 165 wxInputStream& operator>>(wxOutputStream& out) { return Read(out); }
1678ad78
GL
166 wxInputStream& operator>>(wxString& line);
167 wxInputStream& operator>>(char& c);
168 wxInputStream& operator>>(short& i);
123a7fdd 169 wxInputStream& operator>>(int& i);
1678ad78 170 wxInputStream& operator>>(long& i);
75ed1d15 171 wxInputStream& operator>>(double& i);
47d67540 172#if wxUSE_SERIAL
123a7fdd 173 wxInputStream& operator>>(wxObject *& obj);
fcc6dddd 174#endif
123a7fdd 175
75ed1d15 176 wxInputStream& operator>>(float& f) { double d; operator>>((double&)d); f = (float)d; return *this; }
123a7fdd
GL
177 wxInputStream& operator>>(unsigned char& c) { return operator>>((char&)c); }
178 wxInputStream& operator>>(unsigned short& i) { return operator>>((short&)i); }
179 wxInputStream& operator>>(unsigned int& i) { return operator>>((int&)i); }
180 wxInputStream& operator>>(unsigned long& i) { return operator>>((long&)i); }
1678ad78
GL
181 wxInputStream& operator>>( __wxInputManip func) { return func(*this); }
182
183 protected:
75ed1d15 184 bool m_i_destroybuf;
1678ad78 185 wxStreamBuffer *m_i_streambuf;
32fc4afb
GL
186};
187
75ed1d15 188class WXDLLEXPORT wxOutputStream: public wxStreamBase {
32fc4afb
GL
189 public:
190 wxOutputStream();
75ed1d15 191 wxOutputStream(wxStreamBuffer *sbuf);
32fc4afb
GL
192 virtual ~wxOutputStream();
193
41895a05 194 virtual wxOutputStream& Write(const void *buffer, size_t size);
32fc4afb
GL
195 wxOutputStream& Write(wxInputStream& stream_in);
196
75ed1d15
GL
197 off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
198 off_t TellO() const;
1678ad78 199
75ed1d15 200 size_t LastWrite() const { return wxStreamBase::m_lastcount; }
1678ad78 201 wxStreamBuffer *OutputStreamBuffer() { return m_o_streambuf; }
32fc4afb 202
75ed1d15 203 void Sync();
32fc4afb 204
1678ad78
GL
205 wxOutputStream& operator<<(wxInputStream& out) { return Write(out); }
206 wxOutputStream& operator<<(const char *string);
207 wxOutputStream& operator<<(wxString& string);
208 wxOutputStream& operator<<(char c);
209 wxOutputStream& operator<<(short i);
210 wxOutputStream& operator<<(int i);
211 wxOutputStream& operator<<(long i);
212 wxOutputStream& operator<<(double f);
47d67540 213#if wxUSE_SERIAL
123a7fdd 214 wxOutputStream& operator<<(wxObject& obj);
fcc6dddd 215#endif
1678ad78
GL
216
217 wxOutputStream& operator<<(float f) { return operator<<((double)f); }
218 wxOutputStream& operator<<(unsigned char c) { return operator<<((char)c); }
219 wxOutputStream& operator<<(unsigned short i) { return operator<<((short)i); }
220 wxOutputStream& operator<<(unsigned int i) { return operator<<((int)i); }
221 wxOutputStream& operator<<(unsigned long i) { return operator<<((long)i); }
1678ad78
GL
222 wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); }
223
224 protected:
75ed1d15 225 bool m_o_destroybuf;
1678ad78 226 wxStreamBuffer *m_o_streambuf;
32fc4afb
GL
227};
228
f4ada568
GL
229// ---------------------------------------------------------------------------
230// "Filter" streams
231// ---------------------------------------------------------------------------
32fc4afb 232
75ed1d15 233class WXDLLEXPORT wxFilterInputStream: public wxInputStream {
32fc4afb 234 public:
f4ada568 235 wxFilterInputStream();
32fc4afb 236 wxFilterInputStream(wxInputStream& stream);
f4ada568 237 ~wxFilterInputStream();
32fc4afb 238
f4ada568 239 char Peek() { return m_parent_i_stream->Peek(); }
32fc4afb 240
84b46c35
GL
241 wxStreamError LastError() const { return m_parent_i_stream->LastError(); }
242 size_t StreamSize() const { return m_parent_i_stream->StreamSize(); }
243
32fc4afb
GL
244 protected:
245 wxInputStream *m_parent_i_stream;
246};
247
75ed1d15 248class WXDLLEXPORT wxFilterOutputStream: public wxOutputStream {
32fc4afb 249 public:
f4ada568 250 wxFilterOutputStream();
32fc4afb 251 wxFilterOutputStream(wxOutputStream& stream);
75ed1d15 252 ~wxFilterOutputStream();
1678ad78 253
84b46c35
GL
254 wxStreamError LastError() const { return m_parent_o_stream->LastError(); }
255 size_t StreamSize() const { return m_parent_o_stream->StreamSize(); }
256
32fc4afb
GL
257 protected:
258 wxOutputStream *m_parent_o_stream;
259};
260
261#endif