]>
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 RR |
20 | |
21 | #if wxUSE_STREAMS && wxUSE_FILE | |
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 | ||
29 | // ---------------------------------------------------------------------------- | |
30 | // wxFileStream using wxFile | |
31 | // ---------------------------------------------------------------------------- | |
32fc4afb | 32 | |
5fec5bb6 VZ |
33 | class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream |
34 | { | |
35 | public: | |
36 | wxFileInputStream(const wxString& ifileName); | |
37 | wxFileInputStream(wxFile& file); | |
38 | wxFileInputStream(int fd); | |
39 | ~wxFileInputStream(); | |
32fc4afb | 40 | |
5fec5bb6 | 41 | wxFileOffset GetLength() const; |
32fc4afb | 42 | |
5fec5bb6 | 43 | bool Ok() const { return m_file->IsOpened(); } |
0912690b | 44 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } |
79c3e0e1 | 45 | |
5fec5bb6 VZ |
46 | protected: |
47 | wxFileInputStream(); | |
79c3e0e1 | 48 | |
5fec5bb6 VZ |
49 | size_t OnSysRead(void *buffer, size_t size); |
50 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
51 | wxFileOffset OnSysTell() const; | |
75ed1d15 | 52 | |
5fec5bb6 VZ |
53 | protected: |
54 | wxFile *m_file; | |
55 | bool m_file_destroy; | |
22f3361e VZ |
56 | |
57 | DECLARE_NO_COPY_CLASS(wxFileInputStream) | |
79c3e0e1 GL |
58 | }; |
59 | ||
5fec5bb6 VZ |
60 | class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream |
61 | { | |
62 | public: | |
63 | wxFileOutputStream(const wxString& fileName); | |
64 | wxFileOutputStream(wxFile& file); | |
65 | wxFileOutputStream(int fd); | |
66 | virtual ~wxFileOutputStream(); | |
32fc4afb | 67 | |
5fec5bb6 VZ |
68 | void Sync(); |
69 | bool Close() { return m_file_destroy ? m_file->Close() : true; } | |
70 | wxFileOffset GetLength() const; | |
32fc4afb | 71 | |
5fec5bb6 | 72 | bool Ok() const { return m_file->IsOpened(); } |
0912690b | 73 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } |
32fc4afb | 74 | |
5fec5bb6 VZ |
75 | protected: |
76 | wxFileOutputStream(); | |
32fc4afb | 77 | |
5fec5bb6 VZ |
78 | size_t OnSysWrite(const void *buffer, size_t size); |
79 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
80 | wxFileOffset OnSysTell() const; | |
32fc4afb | 81 | |
5fec5bb6 VZ |
82 | protected: |
83 | wxFile *m_file; | |
84 | bool m_file_destroy; | |
22f3361e VZ |
85 | |
86 | DECLARE_NO_COPY_CLASS(wxFileOutputStream) | |
32fc4afb GL |
87 | }; |
88 | ||
fc7a2a60 VZ |
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) | |
84b46c35 GL |
97 | }; |
98 | ||
65045edd RR |
99 | // ---------------------------------------------------------------------------- |
100 | // wxFFileStream using wxFFile | |
101 | // ---------------------------------------------------------------------------- | |
102 | ||
5fec5bb6 VZ |
103 | class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream |
104 | { | |
105 | public: | |
106 | wxFFileInputStream(const wxString& fileName, const wxChar *mode = _T("rb")); | |
107 | wxFFileInputStream(wxFFile& file); | |
108 | wxFFileInputStream(FILE *file); | |
109 | ~wxFFileInputStream(); | |
65045edd | 110 | |
5fec5bb6 | 111 | wxFileOffset GetLength() const; |
65045edd | 112 | |
5fec5bb6 | 113 | bool Ok() const { return m_file->IsOpened(); } |
0912690b | 114 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } |
65045edd | 115 | |
5fec5bb6 VZ |
116 | protected: |
117 | wxFFileInputStream(); | |
65045edd | 118 | |
5fec5bb6 VZ |
119 | size_t OnSysRead(void *buffer, size_t size); |
120 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
121 | wxFileOffset OnSysTell() const; | |
65045edd | 122 | |
5fec5bb6 VZ |
123 | protected: |
124 | wxFFile *m_file; | |
125 | bool m_file_destroy; | |
22f3361e VZ |
126 | |
127 | DECLARE_NO_COPY_CLASS(wxFFileInputStream) | |
65045edd RR |
128 | }; |
129 | ||
5fec5bb6 VZ |
130 | class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream |
131 | { | |
132 | public: | |
133 | wxFFileOutputStream(const wxString& fileName, const wxChar *mode = _T("w+b")); | |
134 | wxFFileOutputStream(wxFFile& file); | |
135 | wxFFileOutputStream(FILE *file); | |
136 | virtual ~wxFFileOutputStream(); | |
65045edd | 137 | |
5fec5bb6 VZ |
138 | void Sync(); |
139 | bool Close() { return m_file_destroy ? m_file->Close() : true; } | |
140 | wxFileOffset GetLength() const; | |
65045edd | 141 | |
5fec5bb6 | 142 | bool Ok() const { return m_file->IsOpened(); } |
0912690b | 143 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } |
65045edd | 144 | |
5fec5bb6 VZ |
145 | protected: |
146 | wxFFileOutputStream(); | |
65045edd | 147 | |
5fec5bb6 VZ |
148 | size_t OnSysWrite(const void *buffer, size_t size); |
149 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
150 | wxFileOffset OnSysTell() const; | |
65045edd | 151 | |
5fec5bb6 VZ |
152 | protected: |
153 | wxFFile *m_file; | |
154 | bool m_file_destroy; | |
22f3361e VZ |
155 | |
156 | DECLARE_NO_COPY_CLASS(wxFFileOutputStream) | |
65045edd RR |
157 | }; |
158 | ||
fc7a2a60 VZ |
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) | |
65045edd | 167 | }; |
fc7a2a60 | 168 | |
5fec5bb6 | 169 | #endif // wxUSE_STREAMS && wxUSE_FILE |
a0250ba3 | 170 | |
5fec5bb6 | 171 | #endif // _WX_WXFSTREAM_H__ |