]> git.saurik.com Git - wxWidgets.git/blame - include/wx/private/fileback.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / private / fileback.h
CommitLineData
916af76f 1/////////////////////////////////////////////////////////////////////////////
233f5738 2// Name: wx/private/fileback.h
916af76f
MW
3// Purpose: Back an input stream with memory or a file
4// Author: Mike Wetherell
916af76f
MW
5// Copyright: (c) 2006 Mike Wetherell
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef _WX_FILEBACK_H__
10#define _WX_FILEBACK_H__
11
12#include "wx/defs.h"
13
14#if wxUSE_FILESYSTEM
15
16#include "wx/stream.h"
17
18// ----------------------------------------------------------------------------
19// Backs an input stream with memory or a file to make it seekable.
20//
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// ----------------------------------------------------------------------------
25
26class WXDLLIMPEXP_BASE wxBackingFile
27{
28public:
29 enum { DefaultBufSize = 16384 };
30
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,
9a83f860 35 const wxString& prefix = wxT("wxbf"));
916af76f
MW
36
37 wxBackingFile() : m_impl(NULL) { }
38 ~wxBackingFile();
39
40 wxBackingFile(const wxBackingFile& backer);
41 wxBackingFile& operator=(const wxBackingFile& backer);
42
43 operator bool() const { return m_impl != NULL; }
44
45private:
46 class wxBackingFileImpl *m_impl;
47 friend class wxBackedInputStream;
48};
49
50// ----------------------------------------------------------------------------
51// An input stream to read from a wxBackingFile.
52// ----------------------------------------------------------------------------
53
54class WXDLLIMPEXP_BASE wxBackedInputStream : public wxInputStream
55{
56public:
57 wxBackedInputStream(const wxBackingFile& backer);
58
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;
62
63 // Returns the length, reading the parent stream to the end if necessary.
64 wxFileOffset FindLength() const;
65
66 bool IsSeekable() const { return true; }
67
68protected:
69 size_t OnSysRead(void *buffer, size_t size);
70 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
71 wxFileOffset OnSysTell() const;
72
73private:
74 wxBackingFile m_backer;
75 wxFileOffset m_pos;
76
c0c133e1 77 wxDECLARE_NO_COPY_CLASS(wxBackedInputStream);
916af76f
MW
78};
79
80#endif // wxUSE_FILESYSTEM
81
82#endif // _WX_FILEBACK_H__