]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wfstream.h
d0d50a608cc129c12dfc3d5cfa1b8f50d6ba1a43
[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 wxFileStream : public wxFileInputStream,
92 public wxFileOutputStream
93 {
94 public:
95 wxFileStream(const wxString& fileName);
96
97 private:
98 DECLARE_NO_COPY_CLASS(wxFileStream)
99 };
100
101 #endif //wxUSE_FILE
102
103 #if wxUSE_FFILE
104
105 // ----------------------------------------------------------------------------
106 // wxFFileStream using wxFFile
107 // ----------------------------------------------------------------------------
108
109 class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
110 {
111 public:
112 wxFFileInputStream(const wxString& fileName, const wxChar *mode = _T("rb"));
113 wxFFileInputStream(wxFFile& file);
114 wxFFileInputStream(FILE *file);
115 ~wxFFileInputStream();
116
117 wxFileOffset GetLength() const;
118
119 bool Ok() const { return m_file->IsOpened(); }
120 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
121
122 protected:
123 wxFFileInputStream();
124
125 size_t OnSysRead(void *buffer, size_t size);
126 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
127 wxFileOffset OnSysTell() const;
128
129 protected:
130 wxFFile *m_file;
131 bool m_file_destroy;
132
133 DECLARE_NO_COPY_CLASS(wxFFileInputStream)
134 };
135
136 class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
137 {
138 public:
139 wxFFileOutputStream(const wxString& fileName, const wxChar *mode = _T("w+b"));
140 wxFFileOutputStream(wxFFile& file);
141 wxFFileOutputStream(FILE *file);
142 virtual ~wxFFileOutputStream();
143
144 void Sync();
145 bool Close() { return m_file_destroy ? m_file->Close() : true; }
146 wxFileOffset GetLength() const;
147
148 bool Ok() const { return m_file->IsOpened(); }
149 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
150
151 protected:
152 wxFFileOutputStream();
153
154 size_t OnSysWrite(const void *buffer, size_t size);
155 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
156 wxFileOffset OnSysTell() const;
157
158 protected:
159 wxFFile *m_file;
160 bool m_file_destroy;
161
162 DECLARE_NO_COPY_CLASS(wxFFileOutputStream)
163 };
164
165 class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
166 public wxFFileOutputStream
167 {
168 public:
169 wxFFileStream(const wxString& fileName);
170
171 private:
172 DECLARE_NO_COPY_CLASS(wxFFileStream)
173 };
174
175 #endif //wxUSE_FFILE
176
177 #endif // wxUSE_STREAMS
178
179 #endif // _WX_WXFSTREAM_H__