1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/fileback.h
3 // Purpose: Back an input stream with memory or a file
4 // Author: Mike Wetherell
6 // Copyright: (c) 2006 Mike Wetherell
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_FILEBACK_H__
11 #define _WX_FILEBACK_H__
17 #include "wx/stream.h"
19 // ----------------------------------------------------------------------------
20 // Backs an input stream with memory or a file to make it seekable.
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 // ----------------------------------------------------------------------------
27 class WXDLLIMPEXP_BASE wxBackingFile
30 enum { DefaultBufSize
= 16384 };
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"));
38 wxBackingFile() : m_impl(NULL
) { }
41 wxBackingFile(const wxBackingFile
& backer
);
42 wxBackingFile
& operator=(const wxBackingFile
& backer
);
44 operator bool() const { return m_impl
!= NULL
; }
47 class wxBackingFileImpl
*m_impl
;
48 friend class wxBackedInputStream
;
51 // ----------------------------------------------------------------------------
52 // An input stream to read from a wxBackingFile.
53 // ----------------------------------------------------------------------------
55 class WXDLLIMPEXP_BASE wxBackedInputStream
: public wxInputStream
58 wxBackedInputStream(const wxBackingFile
& backer
);
60 wxFileOffset
GetLength() const;
61 bool IsSeekable() const { return true; }
64 size_t OnSysRead(void *buffer
, size_t size
);
65 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
66 wxFileOffset
OnSysTell() const;
69 wxBackingFile m_backer
;
72 DECLARE_NO_COPY_CLASS(wxBackedInputStream
)
75 #endif // wxUSE_BACKINGFILE
77 #endif // _WX_FILEBACK_H__