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: mstream.h 53135 2008-04-12 02:31:04Z VZ $
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     virtual ~wxMemoryInputStream();
GetLength()29     virtual wxFileOffset GetLength() const { return m_length; }
IsSeekable()30     virtual bool IsSeekable() const { return true; }
31 
32     char Peek();
33 
GetInputStreamBuffer()34     wxStreamBuffer *GetInputStreamBuffer() const { return m_i_streambuf; }
35 
36 #if WXWIN_COMPATIBILITY_2_6
37     // deprecated, compatibility only
38     wxDEPRECATED( wxStreamBuffer *InputStreamBuffer() const );
39 #endif // WXWIN_COMPATIBILITY_2_6
40 
41 protected:
42     wxStreamBuffer *m_i_streambuf;
43 
44     size_t OnSysRead(void *buffer, size_t nbytes);
45     wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
46     wxFileOffset OnSysTell() const;
47 
48 private:
49     size_t m_length;
50 
51     DECLARE_NO_COPY_CLASS(wxMemoryInputStream)
52 };
53 
54 class WXDLLIMPEXP_BASE wxMemoryOutputStream : public wxOutputStream
55 {
56 public:
57     // if data is !NULL it must be allocated with malloc()
58     wxMemoryOutputStream(void *data = NULL, size_t length = 0);
59     virtual ~wxMemoryOutputStream();
GetLength()60     virtual wxFileOffset GetLength() const { return m_o_streambuf->GetLastAccess(); }
IsSeekable()61     virtual bool IsSeekable() const { return true; }
62 
63     size_t CopyTo(void *buffer, size_t len) const;
64 
GetOutputStreamBuffer()65     wxStreamBuffer *GetOutputStreamBuffer() const { return m_o_streambuf; }
66 
67 #if WXWIN_COMPATIBILITY_2_6
68     // deprecated, compatibility only
69     wxDEPRECATED( wxStreamBuffer *OutputStreamBuffer() const );
70 #endif // WXWIN_COMPATIBILITY_2_6
71 
72 protected:
73     wxStreamBuffer *m_o_streambuf;
74 
75 protected:
76     size_t OnSysWrite(const void *buffer, size_t nbytes);
77     wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
78     wxFileOffset OnSysTell() const;
79 
80     DECLARE_NO_COPY_CLASS(wxMemoryOutputStream)
81 };
82 
83 #if WXWIN_COMPATIBILITY_2_6
InputStreamBuffer()84     inline wxStreamBuffer *wxMemoryInputStream::InputStreamBuffer() const { return m_i_streambuf; }
OutputStreamBuffer()85     inline wxStreamBuffer *wxMemoryOutputStream::OutputStreamBuffer() const { return m_o_streambuf; }
86 #endif // WXWIN_COMPATIBILITY_2_6
87 
88 #endif
89   // wxUSE_STREAMS
90 
91 #endif
92   // _WX_WXMMSTREAM_H__
93