]>
Commit | Line | Data |
---|---|---|
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 |
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(); | |
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 |
48 | protected: |
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 |
55 | protected: |
56 | wxFile *m_file; | |
57 | bool m_file_destroy; | |
22f3361e VZ |
58 | |
59 | DECLARE_NO_COPY_CLASS(wxFileInputStream) | |
79c3e0e1 GL |
60 | }; |
61 | ||
5fec5bb6 VZ |
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(); | |
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 |
77 | protected: |
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 |
84 | protected: |
85 | wxFile *m_file; | |
86 | bool m_file_destroy; | |
22f3361e VZ |
87 | |
88 | DECLARE_NO_COPY_CLASS(wxFileOutputStream) | |
32fc4afb GL |
89 | }; |
90 | ||
fc7a2a60 VZ |
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) | |
84b46c35 GL |
99 | }; |
100 | ||
85990624 RN |
101 | #endif //wxUSE_FILE |
102 | ||
103 | #if wxUSE_FFILE | |
104 | ||
65045edd RR |
105 | // ---------------------------------------------------------------------------- |
106 | // wxFFileStream using wxFFile | |
107 | // ---------------------------------------------------------------------------- | |
108 | ||
5fec5bb6 VZ |
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(); | |
65045edd | 116 | |
5fec5bb6 | 117 | wxFileOffset GetLength() const; |
65045edd | 118 | |
5fec5bb6 | 119 | bool Ok() const { return m_file->IsOpened(); } |
0912690b | 120 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } |
65045edd | 121 | |
5fec5bb6 VZ |
122 | protected: |
123 | wxFFileInputStream(); | |
65045edd | 124 | |
5fec5bb6 VZ |
125 | size_t OnSysRead(void *buffer, size_t size); |
126 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
127 | wxFileOffset OnSysTell() const; | |
65045edd | 128 | |
5fec5bb6 VZ |
129 | protected: |
130 | wxFFile *m_file; | |
131 | bool m_file_destroy; | |
22f3361e VZ |
132 | |
133 | DECLARE_NO_COPY_CLASS(wxFFileInputStream) | |
65045edd RR |
134 | }; |
135 | ||
5fec5bb6 VZ |
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(); | |
65045edd | 143 | |
5fec5bb6 VZ |
144 | void Sync(); |
145 | bool Close() { return m_file_destroy ? m_file->Close() : true; } | |
146 | wxFileOffset GetLength() const; | |
65045edd | 147 | |
5fec5bb6 | 148 | bool Ok() const { return m_file->IsOpened(); } |
0912690b | 149 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } |
65045edd | 150 | |
5fec5bb6 VZ |
151 | protected: |
152 | wxFFileOutputStream(); | |
65045edd | 153 | |
5fec5bb6 VZ |
154 | size_t OnSysWrite(const void *buffer, size_t size); |
155 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
156 | wxFileOffset OnSysTell() const; | |
65045edd | 157 | |
5fec5bb6 VZ |
158 | protected: |
159 | wxFFile *m_file; | |
160 | bool m_file_destroy; | |
22f3361e VZ |
161 | |
162 | DECLARE_NO_COPY_CLASS(wxFFileOutputStream) | |
65045edd RR |
163 | }; |
164 | ||
fc7a2a60 VZ |
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) | |
65045edd | 173 | }; |
fc7a2a60 | 174 | |
85990624 RN |
175 | #endif //wxUSE_FFILE |
176 | ||
177 | #endif // wxUSE_STREAMS | |
a0250ba3 | 178 | |
5fec5bb6 | 179 | #endif // _WX_WXFSTREAM_H__ |