added wxMemoryInputStream(wxInputStream&, size_t) ctor (modified patch 1680108)
[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 // RCS-ID: $Id$
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXMMSTREAM_H__
13 #define _WX_WXMMSTREAM_H__
14
15 #include "wx/defs.h"
16
17 #if wxUSE_STREAMS
18
19 #include "wx/stream.h"
20
21 class WXDLLIMPEXP_BASE wxMemoryOutputStream;
22
23 class WXDLLIMPEXP_BASE wxMemoryInputStream : public wxInputStream
24 {
25 public:
26 wxMemoryInputStream(const void *data, size_t length);
27 wxMemoryInputStream(const wxMemoryOutputStream& stream);
28 wxMemoryInputStream(wxInputStream& stream,
29 wxFileOffset lenFile = wxInvalidOffset)
30 {
31 InitFromStream(stream, lenFile);
32 }
33 wxMemoryInputStream(wxMemoryInputStream& stream)
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 char Peek();
43
44 wxStreamBuffer *GetInputStreamBuffer() const { return m_i_streambuf; }
45
46 #if WXWIN_COMPATIBILITY_2_6
47 // deprecated, compatibility only
48 wxDEPRECATED( wxStreamBuffer *InputStreamBuffer() const );
49 #endif // WXWIN_COMPATIBILITY_2_6
50
51 protected:
52 wxStreamBuffer *m_i_streambuf;
53
54 size_t OnSysRead(void *buffer, size_t nbytes);
55 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
56 wxFileOffset OnSysTell() const;
57
58 private:
59 // common part of ctors taking wxInputStream
60 void InitFromStream(wxInputStream& stream, wxFileOffset lenFile);
61
62 size_t m_length;
63
64 // copy ctor is implemented above: it copies the other stream in this one
65 DECLARE_NO_ASSIGN_CLASS(wxMemoryInputStream)
66 };
67
68 class WXDLLIMPEXP_BASE wxMemoryOutputStream : public wxOutputStream
69 {
70 public:
71 // if data is !NULL it must be allocated with malloc()
72 wxMemoryOutputStream(void *data = NULL, size_t length = 0);
73 virtual ~wxMemoryOutputStream();
74 virtual wxFileOffset GetLength() const { return m_o_streambuf->GetLastAccess(); }
75 virtual bool IsSeekable() const { return true; }
76
77 size_t CopyTo(void *buffer, size_t len) const;
78
79 wxStreamBuffer *GetOutputStreamBuffer() const { return m_o_streambuf; }
80
81 #if WXWIN_COMPATIBILITY_2_6
82 // deprecated, compatibility only
83 wxDEPRECATED( wxStreamBuffer *OutputStreamBuffer() const );
84 #endif // WXWIN_COMPATIBILITY_2_6
85
86 protected:
87 wxStreamBuffer *m_o_streambuf;
88
89 protected:
90 size_t OnSysWrite(const void *buffer, size_t nbytes);
91 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
92 wxFileOffset OnSysTell() const;
93
94 DECLARE_NO_COPY_CLASS(wxMemoryOutputStream)
95 };
96
97 #if WXWIN_COMPATIBILITY_2_6
98 inline wxStreamBuffer *wxMemoryInputStream::InputStreamBuffer() const { return m_i_streambuf; }
99 inline wxStreamBuffer *wxMemoryOutputStream::OutputStreamBuffer() const { return m_o_streambuf; }
100 #endif // WXWIN_COMPATIBILITY_2_6
101
102 #endif
103 // wxUSE_STREAMS
104
105 #endif
106 // _WX_WXMMSTREAM_H__