]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: include/wx/fileback.h | |
3 | // Purpose: Back an input stream with memory or a file | |
4 | // Author: Mike Wetherell | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) 2006 Mike Wetherell | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_FILEBACK_H__ | |
11 | #define _WX_FILEBACK_H__ | |
12 | ||
13 | #include "wx/defs.h" | |
14 | ||
15 | #if wxUSE_BACKINGFILE | |
16 | ||
17 | #include "wx/stream.h" | |
18 | ||
19 | // ---------------------------------------------------------------------------- | |
20 | // Backs an input stream with memory or a file to make it seekable. | |
21 | // | |
22 | // One or more wxBackedInputStreams can be used to read it's data. The data is | |
23 | // reference counted, so stays alive until the last wxBackingFile or | |
24 | // wxBackedInputStream using it is destroyed. | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
27 | class WXDLLIMPEXP_BASE wxBackingFile | |
28 | { | |
29 | public: | |
30 | enum { DefaultBufSize = 16384 }; | |
31 | ||
32 | // Takes ownership of stream. If the stream is smaller than bufsize, the | |
33 | // backing file is never created and the backing is done with memory. | |
34 | wxBackingFile(wxInputStream *stream, | |
35 | size_t bufsize = DefaultBufSize, | |
36 | const wxString& prefix = _T("wxbf")); | |
37 | ||
38 | wxBackingFile() : m_impl(NULL) { } | |
39 | ~wxBackingFile(); | |
40 | ||
41 | wxBackingFile(const wxBackingFile& backer); | |
42 | wxBackingFile& operator=(const wxBackingFile& backer); | |
43 | ||
44 | operator bool() const { return m_impl != NULL; } | |
45 | ||
46 | private: | |
47 | class wxBackingFileImpl *m_impl; | |
48 | friend class wxBackedInputStream; | |
49 | }; | |
50 | ||
51 | // ---------------------------------------------------------------------------- | |
52 | // An input stream to read from a wxBackingFile. | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | class WXDLLIMPEXP_BASE wxBackedInputStream : public wxInputStream | |
56 | { | |
57 | public: | |
58 | wxBackedInputStream(const wxBackingFile& backer); | |
59 | ||
60 | wxFileOffset GetLength() const; | |
61 | bool IsSeekable() const { return true; } | |
62 | ||
63 | protected: | |
64 | size_t OnSysRead(void *buffer, size_t size); | |
65 | wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode); | |
66 | wxFileOffset OnSysTell() const; | |
67 | ||
68 | private: | |
69 | wxBackingFile m_backer; | |
70 | wxFileOffset m_pos; | |
71 | ||
72 | DECLARE_NO_COPY_CLASS(wxBackedInputStream) | |
73 | }; | |
74 | ||
75 | #endif // wxUSE_BACKINGFILE | |
76 | ||
77 | #endif // _WX_FILEBACK_H__ |