]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wfstream.h
Commit FM's GTK+ native assert dialog code.
[wxWidgets.git] / include / wx / wfstream.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/wfstream.h
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXFSTREAM_H__
13 #define _WX_WXFSTREAM_H__
14
15 #include "wx/defs.h"
16
17 #if wxUSE_STREAMS
18
19 #include "wx/object.h"
20 #include "wx/string.h"
21 #include "wx/stream.h"
22 #include "wx/file.h"
23 #include "wx/ffile.h"
24
25 #if wxUSE_FILE
26
27 // ----------------------------------------------------------------------------
28 // wxFileStream using wxFile
29 // ----------------------------------------------------------------------------
30
31 class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
32 {
33 public:
34 wxFileInputStream(const wxString& ifileName);
35 wxFileInputStream(wxFile& file);
36 wxFileInputStream(int fd);
37 virtual ~wxFileInputStream();
38
39 wxFileOffset GetLength() const;
40
41 bool Ok() const { return IsOk(); }
42 virtual bool IsOk() const { return (wxStreamBase::IsOk() && m_file->IsOpened()); }
43 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
44
45 protected:
46 wxFileInputStream();
47
48 size_t OnSysRead(void *buffer, size_t size);
49 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
50 wxFileOffset OnSysTell() const;
51
52 protected:
53 wxFile *m_file;
54 bool m_file_destroy;
55
56 DECLARE_NO_COPY_CLASS(wxFileInputStream)
57 };
58
59 class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
60 {
61 public:
62 wxFileOutputStream(const wxString& fileName);
63 wxFileOutputStream(wxFile& file);
64 wxFileOutputStream(int fd);
65 virtual ~wxFileOutputStream();
66
67 void Sync();
68 bool Close() { return m_file_destroy ? m_file->Close() : true; }
69 wxFileOffset GetLength() const;
70
71 bool Ok() const { return IsOk(); }
72 virtual bool IsOk() const { return (wxStreamBase::IsOk() && m_file->IsOpened()); }
73 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
74
75 protected:
76 wxFileOutputStream();
77
78 size_t OnSysWrite(const void *buffer, size_t size);
79 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
80 wxFileOffset OnSysTell() const;
81
82 protected:
83 wxFile *m_file;
84 bool m_file_destroy;
85
86 DECLARE_NO_COPY_CLASS(wxFileOutputStream)
87 };
88
89 class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
90 {
91 public:
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
102 protected:
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
108 private:
109 wxTempFile *m_file;
110
111 DECLARE_NO_COPY_CLASS(wxTempFileOutputStream)
112 };
113
114 class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
115 public wxFileOutputStream
116 {
117 public:
118 wxFileStream(const wxString& fileName);
119
120 private:
121 DECLARE_NO_COPY_CLASS(wxFileStream)
122 };
123
124 #endif //wxUSE_FILE
125
126 #if wxUSE_FFILE
127
128 // ----------------------------------------------------------------------------
129 // wxFFileStream using wxFFile
130 // ----------------------------------------------------------------------------
131
132 class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
133 {
134 public:
135 wxFFileInputStream(const wxString& fileName, const wxChar *mode = _T("rb"));
136 wxFFileInputStream(wxFFile& file);
137 wxFFileInputStream(FILE *file);
138 virtual ~wxFFileInputStream();
139
140 wxFileOffset GetLength() const;
141
142 bool Ok() const { return IsOk(); }
143 virtual bool IsOk() const { return (wxStreamBase::IsOk() && m_file->IsOpened()); }
144 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
145
146 protected:
147 wxFFileInputStream();
148
149 size_t OnSysRead(void *buffer, size_t size);
150 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
151 wxFileOffset OnSysTell() const;
152
153 protected:
154 wxFFile *m_file;
155 bool m_file_destroy;
156
157 DECLARE_NO_COPY_CLASS(wxFFileInputStream)
158 };
159
160 class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
161 {
162 public:
163 wxFFileOutputStream(const wxString& fileName, const wxChar *mode = _T("w+b"));
164 wxFFileOutputStream(wxFFile& file);
165 wxFFileOutputStream(FILE *file);
166 virtual ~wxFFileOutputStream();
167
168 void Sync();
169 bool Close() { return m_file_destroy ? m_file->Close() : true; }
170 wxFileOffset GetLength() const;
171
172 bool Ok() const { return IsOk(); }
173 virtual bool IsOk() const { return (wxStreamBase::IsOk() && m_file->IsOpened()); }
174 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
175
176 protected:
177 wxFFileOutputStream();
178
179 size_t OnSysWrite(const void *buffer, size_t size);
180 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
181 wxFileOffset OnSysTell() const;
182
183 protected:
184 wxFFile *m_file;
185 bool m_file_destroy;
186
187 DECLARE_NO_COPY_CLASS(wxFFileOutputStream)
188 };
189
190 class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
191 public wxFFileOutputStream
192 {
193 public:
194 wxFFileStream(const wxString& fileName);
195
196 private:
197 DECLARE_NO_COPY_CLASS(wxFFileStream)
198 };
199
200 #endif //wxUSE_FFILE
201
202 #endif // wxUSE_STREAMS
203
204 #endif // _WX_WXFSTREAM_H__