]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/wfstream.h
Made toolbars sticky, i.e. you need to drag them
[wxWidgets.git] / include / wx / wfstream.h
... / ...
CommitLineData
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#include "wx/defs.h"
16
17#if wxUSE_STREAMS
18
19#include "wx/object.h"
20#include "wx/string.h"
21#include "wx/stream.h"
22#include "wx/file.h"
23#include "wx/ffile.h"
24
25#if wxUSE_FILE
26
27// ----------------------------------------------------------------------------
28// wxFileStream using wxFile
29// ----------------------------------------------------------------------------
30
31class WXDLLIMPEXP_BASE wxFileInputStream : public wxInputStream
32{
33public:
34 wxFileInputStream(const wxString& ifileName);
35 wxFileInputStream(wxFile& file);
36 wxFileInputStream(int fd);
37 ~wxFileInputStream();
38
39 wxFileOffset GetLength() const;
40
41 bool Ok() const { return m_file->IsOpened(); }
42 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
43
44protected:
45 wxFileInputStream();
46
47 size_t OnSysRead(void *buffer, size_t size);
48 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
49 wxFileOffset OnSysTell() const;
50
51protected:
52 wxFile *m_file;
53 bool m_file_destroy;
54
55 DECLARE_NO_COPY_CLASS(wxFileInputStream)
56};
57
58class WXDLLIMPEXP_BASE wxFileOutputStream : public wxOutputStream
59{
60public:
61 wxFileOutputStream(const wxString& fileName);
62 wxFileOutputStream(wxFile& file);
63 wxFileOutputStream(int fd);
64 virtual ~wxFileOutputStream();
65
66 void Sync();
67 bool Close() { return m_file_destroy ? m_file->Close() : true; }
68 wxFileOffset GetLength() const;
69
70 bool Ok() const { return m_file->IsOpened(); }
71 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
72
73protected:
74 wxFileOutputStream();
75
76 size_t OnSysWrite(const void *buffer, size_t size);
77 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
78 wxFileOffset OnSysTell() const;
79
80protected:
81 wxFile *m_file;
82 bool m_file_destroy;
83
84 DECLARE_NO_COPY_CLASS(wxFileOutputStream)
85};
86
87class WXDLLIMPEXP_BASE wxTempFileOutputStream : public wxOutputStream
88{
89public:
90 wxTempFileOutputStream(const wxString& fileName);
91 virtual ~wxTempFileOutputStream();
92
93 bool Close() { return Commit(); }
94 virtual bool Commit() { return m_file->Commit(); }
95 virtual void Discard() { m_file->Discard(); }
96
97 wxFileOffset GetLength() const { return m_file->Length(); }
98 bool IsSeekable() const { return true; }
99
100protected:
101 size_t OnSysWrite(const void *buffer, size_t size);
102 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode)
103 { return m_file->Seek(pos, mode); }
104 wxFileOffset OnSysTell() const { return m_file->Tell(); }
105
106private:
107 wxTempFile *m_file;
108
109 DECLARE_NO_COPY_CLASS(wxTempFileOutputStream)
110};
111
112class WXDLLIMPEXP_BASE wxFileStream : public wxFileInputStream,
113 public wxFileOutputStream
114{
115public:
116 wxFileStream(const wxString& fileName);
117
118private:
119 DECLARE_NO_COPY_CLASS(wxFileStream)
120};
121
122#endif //wxUSE_FILE
123
124#if wxUSE_FFILE
125
126// ----------------------------------------------------------------------------
127// wxFFileStream using wxFFile
128// ----------------------------------------------------------------------------
129
130class WXDLLIMPEXP_BASE wxFFileInputStream : public wxInputStream
131{
132public:
133 wxFFileInputStream(const wxString& fileName, const wxChar *mode = _T("rb"));
134 wxFFileInputStream(wxFFile& file);
135 wxFFileInputStream(FILE *file);
136 ~wxFFileInputStream();
137
138 wxFileOffset GetLength() const;
139
140 bool Ok() const { return m_file->IsOpened(); }
141 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
142
143protected:
144 wxFFileInputStream();
145
146 size_t OnSysRead(void *buffer, size_t size);
147 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
148 wxFileOffset OnSysTell() const;
149
150protected:
151 wxFFile *m_file;
152 bool m_file_destroy;
153
154 DECLARE_NO_COPY_CLASS(wxFFileInputStream)
155};
156
157class WXDLLIMPEXP_BASE wxFFileOutputStream : public wxOutputStream
158{
159public:
160 wxFFileOutputStream(const wxString& fileName, const wxChar *mode = _T("w+b"));
161 wxFFileOutputStream(wxFFile& file);
162 wxFFileOutputStream(FILE *file);
163 virtual ~wxFFileOutputStream();
164
165 void Sync();
166 bool Close() { return m_file_destroy ? m_file->Close() : true; }
167 wxFileOffset GetLength() const;
168
169 bool Ok() const { return m_file->IsOpened(); }
170 bool IsSeekable() const { return m_file->GetKind() == wxFILE_KIND_DISK; }
171
172protected:
173 wxFFileOutputStream();
174
175 size_t OnSysWrite(const void *buffer, size_t size);
176 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
177 wxFileOffset OnSysTell() const;
178
179protected:
180 wxFFile *m_file;
181 bool m_file_destroy;
182
183 DECLARE_NO_COPY_CLASS(wxFFileOutputStream)
184};
185
186class WXDLLIMPEXP_BASE wxFFileStream : public wxFFileInputStream,
187 public wxFFileOutputStream
188{
189public:
190 wxFFileStream(const wxString& fileName);
191
192private:
193 DECLARE_NO_COPY_CLASS(wxFFileStream)
194};
195
196#endif //wxUSE_FFILE
197
198#endif // wxUSE_STREAMS
199
200#endif // _WX_WXFSTREAM_H__