1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/private/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 // If the length of the backer's parent stream is unknown then GetLength()
61 // returns wxInvalidOffset until the parent has been read to the end.
62 wxFileOffset
GetLength() const;
64 // Returns the length, reading the parent stream to the end if necessary.
65 wxFileOffset
FindLength() const;
67 bool IsSeekable() const { return true; }
70 size_t OnSysRead(void *buffer
, size_t size
);
71 wxFileOffset
OnSysSeek(wxFileOffset pos
, wxSeekMode mode
);
72 wxFileOffset
OnSysTell() const;
75 wxBackingFile m_backer
;
78 wxDECLARE_NO_COPY_CLASS(wxBackedInputStream
);
81 #endif // wxUSE_FILESYSTEM
83 #endif // _WX_FILEBACK_H__