]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wfstream.h
Minor corrections to make dist after reports
[wxWidgets.git] / include / wx / wfstream.h
CommitLineData
32fc4afb 1/////////////////////////////////////////////////////////////////////////////
5fec5bb6 2// Name: wx/wfstream.h
32fc4afb
GL
3// Purpose: File stream classes
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 11/07/98
7// RCS-ID: $Id$
8// Copyright: (c) Guilhem Lavaux
65571936 9// Licence: wxWindows licence
32fc4afb 10/////////////////////////////////////////////////////////////////////////////
0c32066b 11
34138703
JS
12#ifndef _WX_WXFSTREAM_H__
13#define _WX_WXFSTREAM_H__
32fc4afb 14
2df98b23 15#include "wx/defs.h"
ce4169a4 16
85990624 17#if wxUSE_STREAMS
ce4169a4 18
ed58dbea
RR
19#include "wx/object.h"
20#include "wx/string.h"
21#include "wx/stream.h"
22#include "wx/file.h"
65045edd
RR
23#include "wx/ffile.h"
24
85990624
RN
25#if wxUSE_FILE
26
65045edd
RR
27// ----------------------------------------------------------------------------
28// wxFileStream using wxFile
29// ----------------------------------------------------------------------------
32fc4afb 30
5fec5bb6
VZ
31class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
32{
33public:
34 wxFileInputStream(const wxString& ifileName);
35 wxFileInputStream(wxFile& file);
36 wxFileInputStream(int fd);
d3c7fc99 37 virtual ~wxFileInputStream();
32fc4afb 38
5fec5bb6 39 wxFileOffset GetLength() const;
32fc4afb 40
b7cacb43 41 bool Ok() const { return IsOk(); }
f02f4d43 42 virtual bool IsOk() const;
0912690b 43 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
79c3e0e1 44
5fec5bb6
VZ
45protected:
46 wxFileInputStream();
79c3e0e1 47
5fec5bb6
VZ
48 size_t OnSysRead(void *buffer, size_t size);
49 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
50 wxFileOffset OnSysTell() const;
75ed1d15 51
5fec5bb6
VZ
52protected:
53 wxFile *m_file;
54 bool m_file_destroy;
22f3361e
VZ
55
56 DECLARE_NO_COPY_CLASS(wxFileInputStream)
79c3e0e1
GL
57};
58
5fec5bb6
VZ
59class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
60{
61public:
62 wxFileOutputStream(const wxString& fileName);
63 wxFileOutputStream(wxFile& file);
64 wxFileOutputStream(int fd);
65 virtual ~wxFileOutputStream();
32fc4afb 66
5fec5bb6
VZ
67 void Sync();
68 bool Close() { return m_file_destroy ? m_file->Close() : true; }
69 wxFileOffset GetLength() const;
32fc4afb 70
b7cacb43 71 bool Ok() const { return IsOk(); }
f02f4d43 72 virtual bool IsOk() const;
0912690b 73 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
32fc4afb 74
5fec5bb6
VZ
75protected:
76 wxFileOutputStream();
32fc4afb 77
5fec5bb6
VZ
78 size_t OnSysWrite(const void *buffer, size_t size);
79 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
80 wxFileOffset OnSysTell() const;
32fc4afb 81
5fec5bb6
VZ
82protected:
83 wxFile *m_file;
84 bool m_file_destroy;
22f3361e
VZ
85
86 DECLARE_NO_COPY_CLASS(wxFileOutputStream)
32fc4afb
GL
87};
88
e1265174
MW
89class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
90{
91public:
92 wxTempFileOutputStream(const wxString& fileName);
93 virtual ~wxTempFileOutputStream();
94
95 bool Close() { return Commit(); }
96 virtual bool Commit() { return m_file->Commit(); }
97 virtual void Discard() { m_file->Discard(); }
98
99 wxFileOffset GetLength() const { return m_file->Length(); }
100 bool IsSeekable() const { return true; }
101
102protected:
103 size_t OnSysWrite(const void *buffer, size_t size);
104 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
105 { return m_file->Seek(pos, mode); }
106 wxFileOffset OnSysTell() const { return m_file->Tell(); }
107
108private:
109 wxTempFile *m_file;
110
111 DECLARE_NO_COPY_CLASS(wxTempFileOutputStream)
112};
113
fc7a2a60
VZ
114class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
115 public wxFileOutputStream
116{
117public:
118 wxFileStream(const wxString& fileName);
a6ac8d75 119 virtual bool IsOk() const;
fc7a2a60
VZ
120
121private:
122 DECLARE_NO_COPY_CLASS(wxFileStream)
84b46c35
GL
123};
124
85990624
RN
125#endif //wxUSE_FILE
126
127#if wxUSE_FFILE
128
65045edd
RR
129// ----------------------------------------------------------------------------
130// wxFFileStream using wxFFile
131// ----------------------------------------------------------------------------
132
5fec5bb6
VZ
133class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
134{
135public:
dc65c743 136 wxFFileInputStream(const wxString& fileName, const wxString& mode = "rb");
5fec5bb6
VZ
137 wxFFileInputStream(wxFFile& file);
138 wxFFileInputStream(FILE *file);
d3c7fc99 139 virtual ~wxFFileInputStream();
65045edd 140
5fec5bb6 141 wxFileOffset GetLength() const;
65045edd 142
b7cacb43 143 bool Ok() const { return IsOk(); }
f02f4d43 144 virtual bool IsOk() const;
0912690b 145 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
65045edd 146
5fec5bb6
VZ
147protected:
148 wxFFileInputStream();
65045edd 149
5fec5bb6
VZ
150 size_t OnSysRead(void *buffer, size_t size);
151 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
152 wxFileOffset OnSysTell() const;
65045edd 153
5fec5bb6
VZ
154protected:
155 wxFFile *m_file;
156 bool m_file_destroy;
22f3361e
VZ
157
158 DECLARE_NO_COPY_CLASS(wxFFileInputStream)
65045edd
RR
159};
160
5fec5bb6
VZ
161class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
162{
163public:
02e22828 164 wxFFileOutputStream(const wxString& fileName, const wxString& mode = "wb");
5fec5bb6
VZ
165 wxFFileOutputStream(wxFFile& file);
166 wxFFileOutputStream(FILE *file);
167 virtual ~wxFFileOutputStream();
65045edd 168
5fec5bb6
VZ
169 void Sync();
170 bool Close() { return m_file_destroy ? m_file->Close() : true; }
171 wxFileOffset GetLength() const;
65045edd 172
b7cacb43 173 bool Ok() const { return IsOk(); }
92bf6cc1 174 virtual bool IsOk() const;
0912690b 175 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
65045edd 176
5fec5bb6
VZ
177protected:
178 wxFFileOutputStream();
65045edd 179
5fec5bb6
VZ
180 size_t OnSysWrite(const void *buffer, size_t size);
181 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
182 wxFileOffset OnSysTell() const;
65045edd 183
5fec5bb6
VZ
184protected:
185 wxFFile *m_file;
186 bool m_file_destroy;
22f3361e
VZ
187
188 DECLARE_NO_COPY_CLASS(wxFFileOutputStream)
65045edd
RR
189};
190
fc7a2a60
VZ
191class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
192 public wxFFileOutputStream
193{
194public:
02e22828 195 wxFFileStream(const wxString& fileName, const wxString& mode = "w+b");
92bf6cc1 196 virtual bool IsOk() const;
fc7a2a60
VZ
197
198private:
199 DECLARE_NO_COPY_CLASS(wxFFileStream)
65045edd 200};
fc7a2a60 201
85990624
RN
202#endif //wxUSE_FFILE
203
204#endif // wxUSE_STREAMS
a0250ba3 205
5fec5bb6 206#endif // _WX_WXFSTREAM_H__