]> git.saurik.com Git - wxWidgets.git/blob - include/wx/wfstream.h
OS X savvy implementation
[wxWidgets.git] / include / wx / wfstream.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 && wxUSE_FILE
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 // ----------------------------------------------------------------------------
30 // wxFileStream using wxFile
31 // ----------------------------------------------------------------------------
32
33 class WXDLLIMPEXP_BASE wxFileInputStream: public wxInputStream {
34 public:
35 wxFileInputStream(const wxString& ifileName);
36 wxFileInputStream(wxFile& file);
37 wxFileInputStream(int fd);
38 ~wxFileInputStream();
39
40 wxFileOffset GetLength() const;
41
42 bool Ok() const { return m_file->IsOpened(); }
43
44 protected:
45 wxFileInputStream();
46
47 size_t OnSysRead(void *buffer, size_t size);
48 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
49 wxFileOffset OnSysTell() const;
50
51 protected:
52 wxFile *m_file;
53 bool m_file_destroy;
54
55 DECLARE_NO_COPY_CLASS(wxFileInputStream)
56 };
57
58 class WXDLLIMPEXP_BASE wxFileOutputStream: public wxOutputStream {
59 public:
60 wxFileOutputStream(const wxString& fileName);
61 wxFileOutputStream(wxFile& file);
62 wxFileOutputStream(int fd);
63 virtual ~wxFileOutputStream();
64
65 // To solve an ambiguity on GCC
66 // inline wxOutputStream& Write(const void *buffer, size_t size)
67 // { return wxOutputStream::Write(buffer, size); }
68
69 void Sync();
70 bool Close() { return m_file_destroy ? m_file->Close() : true; }
71 wxFileOffset GetLength() const;
72
73 bool Ok() const { return m_file->IsOpened(); }
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 wxFileStream : public wxFileInputStream,
90 public wxFileOutputStream
91 {
92 public:
93 wxFileStream(const wxString& fileName);
94
95 private:
96 DECLARE_NO_COPY_CLASS(wxFileStream)
97 };
98
99 // ----------------------------------------------------------------------------
100 // wxFFileStream using wxFFile
101 // ----------------------------------------------------------------------------
102
103 class WXDLLIMPEXP_BASE wxFFileInputStream: public wxInputStream {
104 public:
105 wxFFileInputStream(const wxString& ifileName);
106 wxFFileInputStream(wxFFile& file);
107 wxFFileInputStream(FILE *file);
108 ~wxFFileInputStream();
109
110 wxFileOffset GetLength() const;
111
112 bool Ok() const { return m_file->IsOpened(); }
113
114 protected:
115 wxFFileInputStream();
116
117 size_t OnSysRead(void *buffer, size_t size);
118 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
119 wxFileOffset OnSysTell() const;
120
121 protected:
122 wxFFile *m_file;
123 bool m_file_destroy;
124
125 DECLARE_NO_COPY_CLASS(wxFFileInputStream)
126 };
127
128 class WXDLLIMPEXP_BASE wxFFileOutputStream: public wxOutputStream {
129 public:
130 wxFFileOutputStream(const wxString& fileName);
131 wxFFileOutputStream(wxFFile& file);
132 wxFFileOutputStream(FILE *file);
133 virtual ~wxFFileOutputStream();
134
135 // To solve an ambiguity on GCC
136 // inline wxOutputStream& Write(const void *buffer, size_t size)
137 // { return wxOutputStream::Write(buffer, size); }
138
139 void Sync();
140 bool Close() { return m_file_destroy ? m_file->Close() : true; }
141 wxFileOffset GetLength() const;
142
143 bool Ok() const { return m_file->IsOpened(); }
144
145 protected:
146 wxFFileOutputStream();
147
148 size_t OnSysWrite(const void *buffer, size_t size);
149 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
150 wxFileOffset OnSysTell() const;
151
152 protected:
153 wxFFile *m_file;
154 bool m_file_destroy;
155
156 DECLARE_NO_COPY_CLASS(wxFFileOutputStream)
157 };
158
159 class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
160 public wxFFileOutputStream
161 {
162 public:
163 wxFFileStream(const wxString& fileName);
164
165 private:
166 DECLARE_NO_COPY_CLASS(wxFFileStream)
167 };
168
169 #endif
170 // wxUSE_STREAMS && wxUSE_FILE
171
172 #endif
173 // _WX_WXFSTREAM_H__
174
175
176
177
178
179
180
181