]>
Commit | Line | Data |
---|---|---|
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 && 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 | { | |
35 | public: | |
36 | wxFileInputStream(const wxString& ifileName); | |
37 | wxFileInputStream(wxFile& file); | |
38 | wxFileInputStream(int fd); | |
39 | ~wxFileInputStream(); | |
40 | ||
41 | wxFileOffset GetLength() const; | |
42 | ||
43 | bool Ok() const { return m_file->IsOpened(); } | |
44 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } | |
45 | ||
46 | protected: | |
47 | wxFileInputStream(); | |
48 | ||
49 | size_t OnSysRead(void *buffer, size_t size); | |
50 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
51 | wxFileOffset OnSysTell() const; | |
52 | ||
53 | protected: | |
54 | wxFile *m_file; | |
55 | bool m_file_destroy; | |
56 | ||
57 | DECLARE_NO_COPY_CLASS(wxFileInputStream) | |
58 | }; | |
59 | ||
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(); | |
67 | ||
68 | void Sync(); | |
69 | bool Close() { return m_file_destroy ? m_file->Close() : true; } | |
70 | wxFileOffset GetLength() const; | |
71 | ||
72 | bool Ok() const { return m_file->IsOpened(); } | |
73 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } | |
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 | { | |
105 | public: | |
106 | wxFFileInputStream(const wxString& fileName, const wxChar *mode = _T("rb")); | |
107 | wxFFileInputStream(wxFFile& file); | |
108 | wxFFileInputStream(FILE *file); | |
109 | ~wxFFileInputStream(); | |
110 | ||
111 | wxFileOffset GetLength() const; | |
112 | ||
113 | bool Ok() const { return m_file->IsOpened(); } | |
114 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } | |
115 | ||
116 | protected: | |
117 | wxFFileInputStream(); | |
118 | ||
119 | size_t OnSysRead(void *buffer, size_t size); | |
120 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
121 | wxFileOffset OnSysTell() const; | |
122 | ||
123 | protected: | |
124 | wxFFile *m_file; | |
125 | bool m_file_destroy; | |
126 | ||
127 | DECLARE_NO_COPY_CLASS(wxFFileInputStream) | |
128 | }; | |
129 | ||
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(); | |
137 | ||
138 | void Sync(); | |
139 | bool Close() { return m_file_destroy ? m_file->Close() : true; } | |
140 | wxFileOffset GetLength() const; | |
141 | ||
142 | bool Ok() const { return m_file->IsOpened(); } | |
143 | bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; } | |
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 // wxUSE_STREAMS && wxUSE_FILE | |
170 | ||
171 | #endif // _WX_WXFSTREAM_H__ |