No resize border on WinCE by default
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "wfstream.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_STREAMS
22
23 #include "wx/object.h"
24 #include "wx/string.h"
25 #include "wx/stream.h"
26 #include "wx/file.h"
27 #include "wx/ffile.h"
28
29 #if wxUSE_FILE
30
31 // ----------------------------------------------------------------------------
32 // wxFileStream using wxFile
33 // ----------------------------------------------------------------------------
34
35 class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
36 {
37 public:
38 wxFileInputStream(const wxString& ifileName);
39 wxFileInputStream(wxFile& file);
40 wxFileInputStream(int fd);
41 ~wxFileInputStream();
42
43 wxFileOffset GetLength() const;
44
45 bool Ok() const { return m_file->IsOpened(); }
46 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
47
48 protected:
49 wxFileInputStream();
50
51 size_t OnSysRead(void *buffer, size_t size);
52 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
53 wxFileOffset OnSysTell() const;
54
55 protected:
56 wxFile *m_file;
57 bool m_file_destroy;
58
59 DECLARE_NO_COPY_CLASS(wxFileInputStream)
60 };
61
62 class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
63 {
64 public:
65 wxFileOutputStream(const wxString& fileName);
66 wxFileOutputStream(wxFile& file);
67 wxFileOutputStream(int fd);
68 virtual ~wxFileOutputStream();
69
70 void Sync();
71 bool Close() { return m_file_destroy ? m_file->Close() : true; }
72 wxFileOffset GetLength() const;
73
74 bool Ok() const { return m_file->IsOpened(); }
75 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
76
77 protected:
78 wxFileOutputStream();
79
80 size_t OnSysWrite(const void *buffer, size_t size);
81 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
82 wxFileOffset OnSysTell() const;
83
84 protected:
85 wxFile *m_file;
86 bool m_file_destroy;
87
88 DECLARE_NO_COPY_CLASS(wxFileOutputStream)
89 };
90
91 class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
92 {
93 public:
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
104 protected:
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
110 private:
111 wxTempFile *m_file;
112
113 DECLARE_NO_COPY_CLASS(wxTempFileOutputStream)
114 };
115
116 class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
117 public wxFileOutputStream
118 {
119 public:
120 wxFileStream(const wxString& fileName);
121
122 private:
123 DECLARE_NO_COPY_CLASS(wxFileStream)
124 };
125
126 #endif //wxUSE_FILE
127
128 #if wxUSE_FFILE
129
130 // ----------------------------------------------------------------------------
131 // wxFFileStream using wxFFile
132 // ----------------------------------------------------------------------------
133
134 class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
135 {
136 public:
137 wxFFileInputStream(const wxString& fileName, const wxChar *mode = _T("rb"));
138 wxFFileInputStream(wxFFile& file);
139 wxFFileInputStream(FILE *file);
140 ~wxFFileInputStream();
141
142 wxFileOffset GetLength() const;
143
144 bool Ok() const { return m_file->IsOpened(); }
145 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
146
147 protected:
148 wxFFileInputStream();
149
150 size_t OnSysRead(void *buffer, size_t size);
151 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
152 wxFileOffset OnSysTell() const;
153
154 protected:
155 wxFFile *m_file;
156 bool m_file_destroy;
157
158 DECLARE_NO_COPY_CLASS(wxFFileInputStream)
159 };
160
161 class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
162 {
163 public:
164 wxFFileOutputStream(const wxString& fileName, const wxChar *mode = _T("w+b"));
165 wxFFileOutputStream(wxFFile& file);
166 wxFFileOutputStream(FILE *file);
167 virtual ~wxFFileOutputStream();
168
169 void Sync();
170 bool Close() { return m_file_destroy ? m_file->Close() : true; }
171 wxFileOffset GetLength() const;
172
173 bool Ok() const { return 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__