further routing into wxApp
[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_FWD_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 : wxInputStream()
35 {
36 InitFromStream(stream, wxInvalidOffset);
37 }
38
39 virtual ~wxMemoryInputStream();
40 virtual wxFileOffset GetLength() const { return m_length; }
41 virtual bool IsSeekable() const { return true; }
42
43 virtual char Peek();
44 virtual bool CanRead() const;
45
46 wxStreamBuffer *GetInputStreamBuffer() const { return m_i_streambuf; }
47
48 #if WXWIN_COMPATIBILITY_2_6
49 // deprecated, compatibility only
50 wxDEPRECATED( wxStreamBuffer *InputStreamBuffer() const );
51 #endif // WXWIN_COMPATIBILITY_2_6
52
53 protected:
54 wxStreamBuffer *m_i_streambuf;
55
56 size_t OnSysRead(void *buffer, size_t nbytes);
57 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
58 wxFileOffset OnSysTell() const;
59
60 private:
61 // common part of ctors taking wxInputStream
62 void InitFromStream(wxInputStream& stream, wxFileOffset lenFile);
63
64 size_t m_length;
65
66 // copy ctor is implemented above: it copies the other stream in this one
67 DECLARE_ABSTRACT_CLASS(wxMemoryInputStream)
68 wxDECLARE_NO_ASSIGN_CLASS(wxMemoryInputStream);
69 };
70
71 class WXDLLIMPEXP_BASE wxMemoryOutputStream : public wxOutputStream
72 {
73 public:
74 // if data is !NULL it must be allocated with malloc()
75 wxMemoryOutputStream(void *data = NULL, size_t length = 0);
76 virtual ~wxMemoryOutputStream();
77 virtual wxFileOffset GetLength() const { return m_o_streambuf->GetLastAccess(); }
78 virtual bool IsSeekable() const { return true; }
79
80 size_t CopyTo(void *buffer, size_t len) const;
81
82 wxStreamBuffer *GetOutputStreamBuffer() const { return m_o_streambuf; }
83
84 #if WXWIN_COMPATIBILITY_2_6
85 // deprecated, compatibility only
86 wxDEPRECATED( wxStreamBuffer *OutputStreamBuffer() const );
87 #endif // WXWIN_COMPATIBILITY_2_6
88
89 protected:
90 wxStreamBuffer *m_o_streambuf;
91
92 protected:
93 size_t OnSysWrite(const void *buffer, size_t nbytes);
94 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
95 wxFileOffset OnSysTell() const;
96
97 DECLARE_DYNAMIC_CLASS(wxMemoryOutputStream)
98 wxDECLARE_NO_COPY_CLASS(wxMemoryOutputStream);
99 };
100
101 #if WXWIN_COMPATIBILITY_2_6
102 inline wxStreamBuffer *wxMemoryInputStream::InputStreamBuffer() const { return m_i_streambuf; }
103 inline wxStreamBuffer *wxMemoryOutputStream::OutputStreamBuffer() const { return m_o_streambuf; }
104 #endif // WXWIN_COMPATIBILITY_2_6
105
106 #endif
107 // wxUSE_STREAMS
108
109 #endif
110 // _WX_WXMMSTREAM_H__