]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fileback.h
Added GetTempDir
[wxWidgets.git] / include / wx / fileback.h
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 // ----------------------------------------------------------------------------
18 // Backs an input stream with memory or a file to make it seekable.
19 //
20 // One or more wxBackedInputStreams can be used to read it's data. The data is
21 // reference counted, so stays alive until the last wxBackingFile or
22 // wxBackedInputStream using it is destroyed.
23 // ----------------------------------------------------------------------------
24
25 class WXDLLIMPEXP_BASE wxBackingFile
26 {
27 public:
28 enum { DefaultBufSize = 16384 };
29
30 // Takes ownership of stream. If the stream is smaller than bufsize, the
31 // backing file is never created and the backing is done with memory.
32 wxBackingFile(wxInputStream *stream,
33 size_t bufsize = DefaultBufSize,
34 const wxString& prefix = _T("wxbf"));
35
36 wxBackingFile() : m_impl(NULL) { }
37 ~wxBackingFile();
38
39 wxBackingFile(const wxBackingFile& backer);
40 wxBackingFile& operator=(const wxBackingFile& backer);
41
42 operator bool() const { return m_impl != NULL; }
43
44 private:
45 class wxBackingFileImpl *m_impl;
46 friend class wxBackedInputStream;
47 };
48
49 // ----------------------------------------------------------------------------
50 // An input stream to read from a wxBackingFile.
51 // ----------------------------------------------------------------------------
52
53 class WXDLLIMPEXP_BASE wxBackedInputStream : public wxInputStream
54 {
55 public:
56 wxBackedInputStream(const wxBackingFile& backer);
57
58 wxFileOffset GetLength() const;
59 bool IsSeekable() const { return true; }
60
61 protected:
62 size_t OnSysRead(void *buffer, size_t size);
63 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
64 wxFileOffset OnSysTell() const;
65
66 private:
67 wxBackingFile m_backer;
68 wxFileOffset m_pos;
69
70 DECLARE_NO_COPY_CLASS(wxBackedInputStream)
71 };
72
73 #endif // wxUSE_BACKINGFILE
74
75 #endif // _WX_FILEBACK_H__