1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/fileback.h
3 // Purpose: Back an input stream with memory or a file
4 // Author: Mike Wetherell
5 // Copyright: (c) 2006 Mike Wetherell
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 #ifndef _WX_FILEBACK_H__
10 #define _WX_FILEBACK_H__
16 #include "wx/stream.h"
18 // ----------------------------------------------------------------------------
19 // Backs an input stream with memory or a file to make it seekable.
21 // One or more wxBackedInputStreams can be used to read it's data. The data is
22 // reference counted, so stays alive until the last wxBackingFile or
23 // wxBackedInputStream using it is destroyed.
24 // ----------------------------------------------------------------------------
26 class WXDLLIMPEXP_BASE wxBackingFile
29 enum { DefaultBufSize
= 16384 };
31 // Takes ownership of stream. If the stream is smaller than bufsize, the
32 // backing file is never created and the backing is done with memory.
33 wxBackingFile(wxInputStream
*stream
,
34 size_t bufsize
= DefaultBufSize
,
35 const wxString
& prefix
= wxT("wxbf"));
37 wxBackingFile() : m_impl(NULL
) { }
40 wxBackingFile(const wxBackingFile
& backer
);
41 wxBackingFile
& operator=(const wxBackingFile
& backer
);
43 operator bool() const { return m_impl
!= NULL
; }
46 class wxBackingFileImpl
*m_impl
;
47 friend class wxBackedInputStream
;
50 // ----------------------------------------------------------------------------
51 // An input stream to read from a wxBackingFile.
52 // ----------------------------------------------------------------------------
54 class WXDLLIMPEXP_BASE wxBackedInputStream
: public wxInputStream
57 wxBackedInputStream(const wxBackingFile
& backer
);
59 // If the length of the backer's parent stream is unknown then GetLength()
60 // returns wxInvalidOffset until the parent has been read to the end.
61 wxFileOffset
GetLength() const;
63 // Returns the length, reading the parent stream to the end if necessary.
64 wxFileOffset
FindLength() const;
66 bool IsSeekable() const { return true; }
69 size_t OnSysRead(void *buffer
, size_t size
);
70 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
71 wxFileOffset
OnSysTell() const;
74 wxBackingFile m_backer
;
77 wxDECLARE_NO_COPY_CLASS(wxBackedInputStream
);
80 #endif // wxUSE_FILESYSTEM
82 #endif // _WX_FILEBACK_H__