]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mstream.h
using Run of base class
[wxWidgets.git] / include / wx / mstream.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mstream.h
3 // Purpose: Memory stream classes
4 // Author: Guilhem Lavaux
5 // Modified by:
6 // Created: 11/07/98
7 // Copyright: (c) Guilhem Lavaux
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_WXMMSTREAM_H__
12 #define _WX_WXMMSTREAM_H__
13
14 #include "wx/defs.h"
15
16 #if wxUSE_STREAMS
17
18 #include "wx/stream.h"
19
20 class WXDLLIMPEXP_FWD_BASE wxMemoryOutputStream;
21
22 class WXDLLIMPEXP_BASE wxMemoryInputStream : public wxInputStream
23 {
24 public:
25 wxMemoryInputStream(const void *data, size_t length);
26 wxMemoryInputStream(const wxMemoryOutputStream& stream);
27 wxMemoryInputStream(wxInputStream& stream,
28 wxFileOffset lenFile = wxInvalidOffset)
29 {
30 InitFromStream(stream, lenFile);
31 }
32 wxMemoryInputStream(wxMemoryInputStream& stream)
33 : wxInputStream()
34 {
35 InitFromStream(stream, wxInvalidOffset);
36 }
37
38 virtual ~wxMemoryInputStream();
39 virtual wxFileOffset GetLength() const { return m_length; }
40 virtual bool IsSeekable() const { return true; }
41
42 virtual char Peek();
43 virtual bool CanRead() const;
44
45 wxStreamBuffer *GetInputStreamBuffer() const { return m_i_streambuf; }
46
47 #if WXWIN_COMPATIBILITY_2_6
48 // deprecated, compatibility only
49 wxDEPRECATED( wxStreamBuffer *InputStreamBuffer() const );
50 #endif // WXWIN_COMPATIBILITY_2_6
51
52 protected:
53 wxStreamBuffer *m_i_streambuf;
54
55 size_t OnSysRead(void *buffer, size_t nbytes);
56 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
57 wxFileOffset OnSysTell() const;
58
59 private:
60 // common part of ctors taking wxInputStream
61 void InitFromStream(wxInputStream& stream, wxFileOffset lenFile);
62
63 size_t m_length;
64
65 // copy ctor is implemented above: it copies the other stream in this one
66 DECLARE_ABSTRACT_CLASS(wxMemoryInputStream)
67 wxDECLARE_NO_ASSIGN_CLASS(wxMemoryInputStream);
68 };
69
70 class WXDLLIMPEXP_BASE wxMemoryOutputStream : public wxOutputStream
71 {
72 public:
73 // if data is !NULL it must be allocated with malloc()
74 wxMemoryOutputStream(void *data = NULL, size_t length = 0);
75 virtual ~wxMemoryOutputStream();
76 virtual wxFileOffset GetLength() const { return m_o_streambuf->GetLastAccess(); }
77 virtual bool IsSeekable() const { return true; }
78
79 size_t CopyTo(void *buffer, size_t len) const;
80
81 wxStreamBuffer *GetOutputStreamBuffer() const { return m_o_streambuf; }
82
83 #if WXWIN_COMPATIBILITY_2_6
84 // deprecated, compatibility only
85 wxDEPRECATED( wxStreamBuffer *OutputStreamBuffer() const );
86 #endif // WXWIN_COMPATIBILITY_2_6
87
88 protected:
89 wxStreamBuffer *m_o_streambuf;
90
91 protected:
92 size_t OnSysWrite(const void *buffer, size_t nbytes);
93 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
94 wxFileOffset OnSysTell() const;
95
96 DECLARE_DYNAMIC_CLASS(wxMemoryOutputStream)
97 wxDECLARE_NO_COPY_CLASS(wxMemoryOutputStream);
98 };
99
100 #if WXWIN_COMPATIBILITY_2_6
101 inline wxStreamBuffer *wxMemoryInputStream::InputStreamBuffer() const { return m_i_streambuf; }
102 inline wxStreamBuffer *wxMemoryOutputStream::OutputStreamBuffer() const { return m_o_streambuf; }
103 #endif // WXWIN_COMPATIBILITY_2_6
104
105 #endif
106 // wxUSE_STREAMS
107
108 #endif
109 // _WX_WXMMSTREAM_H__