]> git.saurik.com Git - wxWidgets.git/blame - include/wx/stream.h
More wxMotif work, OGL enhancements, USE_ macro corrections, object.cpp delete
[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
24class WXDLLEXPORT wxInputStream;
25class WXDLLEXPORT wxOutputStream;
26
27typedef wxInputStream& (*__wxInputManip)(wxInputStream&);
28typedef wxOutputStream& (*__wxOutputManip)(wxOutputStream&);
29
30wxOutputStream& WXDLLEXPORT wxEndL(wxOutputStream& o_stream);
31
0c32066b
JS
32// Disable warnings such as
33// 'wxFilterStream' : inherits 'wxFilterInputStream::Peek' via dominance
34
35#ifdef _MSC_VER
36#pragma warning(disable:4250)
37#endif
38
f4ada568
GL
39// ---------------------------------------------------------------------------
40// Stream buffer
41// ---------------------------------------------------------------------------
42
1678ad78
GL
43class WXDLLEXPORT wxStreamBuffer {
44 public:
45 wxStreamBuffer(wxInputStream& stream);
46 wxStreamBuffer(wxOutputStream& stream);
47 ~wxStreamBuffer();
48
49 void Read(void *buffer, size_t size);
50 void Write(const void *buffer, size_t size);
51 void WriteBack(char c);
52
53 void SetBufferIO(char *buffer_start, char *buffer_end);
54 void SetBufferIO(size_t bufsize);
55 void ResetBuffer();
56
57 void SetBufferPosition(char *buffer_position)
58 { m_buffer_pos = buffer_position; }
59 void SetIntPosition(size_t pos)
60 { m_buffer_pos = m_buffer_start + pos; }
61 char *GetBufferPosition() const { return m_buffer_pos; }
62 size_t GetIntPosition() const { return m_buffer_pos - m_buffer_start; }
63
64 char *GetBufferStart() const { return m_buffer_start; }
65 char *GetBufferEnd() const { return m_buffer_end; }
66 size_t GetBufferSize() const { return m_buffer_size; }
67 size_t GetLastAccess() const { return m_buffer_end - m_buffer_start; }
68
69 protected:
70 char *m_buffer_start, *m_buffer_end, *m_buffer_pos;
71 size_t m_buffer_size;
72
73 wxInputStream *m_istream;
74 wxOutputStream *m_ostream;
75};
eda3efe2 76
f4ada568
GL
77// ---------------------------------------------------------------------------
78// wxStream: base classes
79// ---------------------------------------------------------------------------
80
1678ad78 81class WXDLLEXPORT wxInputStream {
32fc4afb
GL
82 public:
83 wxInputStream();
84 virtual ~wxInputStream();
85
1678ad78 86 // IO functions
f4ada568 87 virtual char Peek() { return 0; }
1678ad78
GL
88 virtual char GetC();
89 virtual wxInputStream& Read(void *buffer, size_t size);
32fc4afb
GL
90 wxInputStream& Read(wxOutputStream& stream_out);
91
1678ad78 92 // Position functions
7a4b9130
GL
93 virtual off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
94 virtual off_t TellI() const;
32fc4afb 95
1678ad78
GL
96 // State functions
97 bool Eof() const { return m_eof; }
98 size_t LastRead() { return m_lastread; }
99 wxStreamBuffer *InputStreamBuffer() { return m_i_streambuf; }
0cd9bfe8 100
1678ad78 101 // Operators
0cd9bfe8 102 wxInputStream& operator>>(wxOutputStream& out) { return Read(out); }
1678ad78
GL
103 wxInputStream& operator>>(wxString& line);
104 wxInputStream& operator>>(char& c);
105 wxInputStream& operator>>(short& i);
123a7fdd 106 wxInputStream& operator>>(int& i);
1678ad78
GL
107 wxInputStream& operator>>(long& i);
108 wxInputStream& operator>>(float& i);
47d67540 109#if wxUSE_SERIAL
123a7fdd 110 wxInputStream& operator>>(wxObject *& obj);
fcc6dddd 111#endif
123a7fdd
GL
112
113 wxInputStream& operator>>(unsigned char& c) { return operator>>((char&)c); }
114 wxInputStream& operator>>(unsigned short& i) { return operator>>((short&)i); }
115 wxInputStream& operator>>(unsigned int& i) { return operator>>((int&)i); }
116 wxInputStream& operator>>(unsigned long& i) { return operator>>((long&)i); }
1678ad78
GL
117 wxInputStream& operator>>( __wxInputManip func) { return func(*this); }
118
119 protected:
120 friend class wxStreamBuffer;
121 friend class wxFilterInputStream;
122
123 wxInputStream(wxStreamBuffer *buffer);
124
e22036dc
RR
125 virtual size_t DoRead(void *WXUNUSED(buffer), size_t WXUNUSED(size) )
126 { return 0; }
127 virtual off_t DoSeekInput( off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
f4ada568
GL
128 { return wxInvalidOffset; }
129 virtual off_t DoTellInput() const
130 { return wxInvalidOffset; }
1678ad78
GL
131
132 protected:
133 bool m_eof, m_i_destroybuf;
134 size_t m_lastread;
135 wxStreamBuffer *m_i_streambuf;
32fc4afb
GL
136};
137
1678ad78 138class WXDLLEXPORT wxOutputStream {
32fc4afb
GL
139 public:
140 wxOutputStream();
141 virtual ~wxOutputStream();
142
1678ad78 143 virtual wxOutputStream& Write(const void *buffer, size_t size);
32fc4afb
GL
144 wxOutputStream& Write(wxInputStream& stream_in);
145
1678ad78
GL
146 virtual off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
147 virtual off_t TellO() const;
148
149 virtual bool Bad() const { return m_bad; }
150 virtual size_t LastWrite() const { return m_lastwrite; }
151 wxStreamBuffer *OutputStreamBuffer() { return m_o_streambuf; }
32fc4afb 152
1678ad78 153 virtual void Sync();
32fc4afb 154
1678ad78
GL
155 wxOutputStream& operator<<(wxInputStream& out) { return Write(out); }
156 wxOutputStream& operator<<(const char *string);
157 wxOutputStream& operator<<(wxString& string);
158 wxOutputStream& operator<<(char c);
159 wxOutputStream& operator<<(short i);
160 wxOutputStream& operator<<(int i);
161 wxOutputStream& operator<<(long i);
162 wxOutputStream& operator<<(double f);
47d67540 163#if wxUSE_SERIAL
123a7fdd 164 wxOutputStream& operator<<(wxObject& obj);
fcc6dddd 165#endif
1678ad78
GL
166
167 wxOutputStream& operator<<(float f) { return operator<<((double)f); }
168 wxOutputStream& operator<<(unsigned char c) { return operator<<((char)c); }
169 wxOutputStream& operator<<(unsigned short i) { return operator<<((short)i); }
170 wxOutputStream& operator<<(unsigned int i) { return operator<<((int)i); }
171 wxOutputStream& operator<<(unsigned long i) { return operator<<((long)i); }
1678ad78
GL
172 wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); }
173
174 protected:
175 friend class wxStreamBuffer;
176 friend class wxFilterOutputStream;
177
178 wxOutputStream(wxStreamBuffer *buffer);
179
e22036dc
RR
180 virtual size_t DoWrite( const void *WXUNUSED(buffer), size_t WXUNUSED(size) )
181 { return 0; }
182 virtual off_t DoSeekOutput( off_t WXUNUSED(pos), wxSeekMode WXUNUSED(mode) )
f4ada568
GL
183 { return wxInvalidOffset; }
184 virtual off_t DoTellOutput() const
185 { return wxInvalidOffset; }
1678ad78
GL
186
187 protected:
188 bool m_bad, m_o_destroybuf;
189 size_t m_lastwrite;
190 wxStreamBuffer *m_o_streambuf;
32fc4afb
GL
191};
192
fbcb4166 193class WXDLLEXPORT wxStream: public virtual wxInputStream,
c740f496 194 public virtual wxOutputStream
f4ada568
GL
195{
196 public:
197 wxStream();
198};
199
200// ---------------------------------------------------------------------------
201// "Filter" streams
202// ---------------------------------------------------------------------------
32fc4afb 203
c740f496 204class WXDLLEXPORT wxFilterInputStream: public virtual wxInputStream {
32fc4afb 205 public:
f4ada568 206 wxFilterInputStream();
32fc4afb 207 wxFilterInputStream(wxInputStream& stream);
f4ada568 208 ~wxFilterInputStream();
32fc4afb 209
f4ada568 210 char Peek() { return m_parent_i_stream->Peek(); }
32fc4afb 211
f4ada568
GL
212 bool Eof() const { return m_parent_i_stream->Eof(); }
213 size_t LastRead() const { return m_parent_i_stream->LastRead(); }
214 off_t TellI() const { return m_parent_i_stream->TellI(); }
79c3e0e1 215
1678ad78 216 protected:
f4ada568
GL
217 size_t DoRead(void *buffer, size_t size);
218 off_t DoSeekInput(off_t pos, wxSeekMode mode);
219 off_t DoTellInput() const;
1678ad78 220
32fc4afb
GL
221 protected:
222 wxInputStream *m_parent_i_stream;
223};
224
c740f496 225class WXDLLEXPORT wxFilterOutputStream: public virtual wxOutputStream {
32fc4afb 226 public:
f4ada568 227 wxFilterOutputStream();
32fc4afb
GL
228 wxFilterOutputStream(wxOutputStream& stream);
229 virtual ~wxFilterOutputStream();
230
f4ada568
GL
231 bool Bad() const { return m_parent_o_stream->Bad(); }
232 size_t LastWrite() const { return m_parent_o_stream->LastWrite(); }
233 off_t TellO() const { return m_parent_o_stream->TellO(); }
32fc4afb 234
1678ad78 235 protected:
1678ad78
GL
236 // The forward is implicitely done by wxStreamBuffer.
237
f4ada568
GL
238 size_t DoWrite(const void *buffer, size_t size);
239 off_t DoSeekOutput(off_t pos, wxSeekMode mode);
240 off_t DoTellOutput() const;
1678ad78 241
32fc4afb
GL
242 protected:
243 wxOutputStream *m_parent_o_stream;
244};
245
f4ada568 246class WXDLLEXPORT wxFilterStream: public wxStream,
c740f496
GL
247 public virtual wxFilterInputStream,
248 public virtual wxFilterOutputStream {
f4ada568
GL
249 public:
250 wxFilterStream(wxStream& stream);
251 wxFilterStream();
252};
253
0c32066b
JS
254#ifdef _MSC_VER
255#pragma warning(default:4250)
256#endif
257
32fc4afb 258#endif