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 // ----------------------------------------------------------------------------
18 // Backs an input stream with memory or a file to make it seekable.
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 // ----------------------------------------------------------------------------
25 class WXDLLIMPEXP_BASE wxBackingFile
28 enum { DefaultBufSize
= 16384 };
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"));
36 wxBackingFile() : m_impl(NULL
) { }
39 wxBackingFile(const wxBackingFile
& backer
);
40 wxBackingFile
& operator=(const wxBackingFile
& backer
);
42 operator bool() const { return m_impl
!= NULL
; }
45 class wxBackingFileImpl
*m_impl
;
46 friend class wxBackedInputStream
;
49 // ----------------------------------------------------------------------------
50 // An input stream to read from a wxBackingFile.
51 // ----------------------------------------------------------------------------
53 class WXDLLIMPEXP_BASE wxBackedInputStream
: public wxInputStream
56 wxBackedInputStream(const wxBackingFile
& backer
);
58 wxFileOffset
GetLength() const;
59 bool IsSeekable() const { return true; }
62 size_t OnSysRead(void *buffer
, size_t size
);
63 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
64 wxFileOffset
OnSysTell() const;
67 wxBackingFile m_backer
;
70 DECLARE_NO_COPY_CLASS(wxBackedInputStream
)
73 #endif // wxUSE_BACKINGFILE
75 #endif // _WX_FILEBACK_H__