]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wfstream.h
hacked around wxGTK wxStaticText which doesn't derive from wxStaticTextBase (argh...
[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
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
bd5e2346 16#pragma interface "wfstream.h"
0c32066b
JS
17#endif
18
2df98b23 19#include "wx/defs.h"
ce4169a4 20
85990624 21#if wxUSE_STREAMS
ce4169a4 22
ed58dbea
RR
23#include "wx/object.h"
24#include "wx/string.h"
25#include "wx/stream.h"
26#include "wx/file.h"
65045edd
RR
27#include "wx/ffile.h"
28
85990624
RN
29#if wxUSE_FILE
30
65045edd
RR
31// ----------------------------------------------------------------------------
32// wxFileStream using wxFile
33// ----------------------------------------------------------------------------
32fc4afb 34
5fec5bb6
VZ
35class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
36{
37public:
38 wxFileInputStream(const wxString& ifileName);
39 wxFileInputStream(wxFile& file);
40 wxFileInputStream(int fd);
41 ~wxFileInputStream();
32fc4afb 42
5fec5bb6 43 wxFileOffset GetLength() const;
32fc4afb 44
5fec5bb6 45 bool Ok() const { return m_file->IsOpened(); }
0912690b 46 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
79c3e0e1 47
5fec5bb6
VZ
48protected:
49 wxFileInputStream();
79c3e0e1 50
5fec5bb6
VZ
51 size_t OnSysRead(void *buffer, size_t size);
52 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
53 wxFileOffset OnSysTell() const;
75ed1d15 54
5fec5bb6
VZ
55protected:
56 wxFile *m_file;
57 bool m_file_destroy;
22f3361e
VZ
58
59 DECLARE_NO_COPY_CLASS(wxFileInputStream)
79c3e0e1
GL
60};
61
5fec5bb6
VZ
62class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
63{
64public:
65 wxFileOutputStream(const wxString& fileName);
66 wxFileOutputStream(wxFile& file);
67 wxFileOutputStream(int fd);
68 virtual ~wxFileOutputStream();
32fc4afb 69
5fec5bb6
VZ
70 void Sync();
71 bool Close() { return m_file_destroy ? m_file->Close() : true; }
72 wxFileOffset GetLength() const;
32fc4afb 73
5fec5bb6 74 bool Ok() const { return m_file->IsOpened(); }
0912690b 75 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
32fc4afb 76
5fec5bb6
VZ
77protected:
78 wxFileOutputStream();
32fc4afb 79
5fec5bb6
VZ
80 size_t OnSysWrite(const void *buffer, size_t size);
81 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
82 wxFileOffset OnSysTell() const;
32fc4afb 83
5fec5bb6
VZ
84protected:
85 wxFile *m_file;
86 bool m_file_destroy;
22f3361e
VZ
87
88 DECLARE_NO_COPY_CLASS(wxFileOutputStream)
32fc4afb
GL
89};
90
e1265174
MW
91class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
92{
93public:
94 wxTempFileOutputStream(const wxString& fileName);
95 virtual ~wxTempFileOutputStream();
96
97 bool Close() { return Commit(); }
98 virtual bool Commit() { return m_file->Commit(); }
99 virtual void Discard() { m_file->Discard(); }
100
101 wxFileOffset GetLength() const { return m_file->Length(); }
102 bool IsSeekable() const { return true; }
103
104protected:
105 size_t OnSysWrite(const void *buffer, size_t size);
106 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
107 { return m_file->Seek(pos, mode); }
108 wxFileOffset OnSysTell() const { return m_file->Tell(); }
109
110private:
111 wxTempFile *m_file;
112
113 DECLARE_NO_COPY_CLASS(wxTempFileOutputStream)
114};
115
fc7a2a60
VZ
116class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
117 public wxFileOutputStream
118{
119public:
120 wxFileStream(const wxString& fileName);
121
122private:
123 DECLARE_NO_COPY_CLASS(wxFileStream)
84b46c35
GL
124};
125
85990624
RN
126#endif //wxUSE_FILE
127
128#if wxUSE_FFILE
129
65045edd
RR
130// ----------------------------------------------------------------------------
131// wxFFileStream using wxFFile
132// ----------------------------------------------------------------------------
133
5fec5bb6
VZ
134class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
135{
136public:
137 wxFFileInputStream(const wxString& fileName, const wxChar *mode = _T("rb"));
138 wxFFileInputStream(wxFFile& file);
139 wxFFileInputStream(FILE *file);
140 ~wxFFileInputStream();
65045edd 141
5fec5bb6 142 wxFileOffset GetLength() const;
65045edd 143
5fec5bb6 144 bool Ok() const { return m_file->IsOpened(); }
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:
164 wxFFileOutputStream(const wxString& fileName, const wxChar *mode = _T("w+b"));
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
5fec5bb6 173 bool Ok() const { return m_file->IsOpened(); }
0912690b 174 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
65045edd 175
5fec5bb6
VZ
176protected:
177 wxFFileOutputStream();
65045edd 178
5fec5bb6
VZ
179 size_t OnSysWrite(const void *buffer, size_t size);
180 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
181 wxFileOffset OnSysTell() const;
65045edd 182
5fec5bb6
VZ
183protected:
184 wxFFile *m_file;
185 bool m_file_destroy;
22f3361e
VZ
186
187 DECLARE_NO_COPY_CLASS(wxFFileOutputStream)
65045edd
RR
188};
189
fc7a2a60
VZ
190class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
191 public wxFFileOutputStream
192{
193public:
194 wxFFileStream(const wxString& fileName);
195
196private:
197 DECLARE_NO_COPY_CLASS(wxFFileStream)
65045edd 198};
fc7a2a60 199
85990624
RN
200#endif //wxUSE_FFILE
201
202#endif // wxUSE_STREAMS
a0250ba3 203
5fec5bb6 204#endif // _WX_WXFSTREAM_H__