1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: string-based streams
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_SSTREAM_H_
12 #define _WX_SSTREAM_H_
14 #include "wx/stream.h"
18 // ----------------------------------------------------------------------------
19 // wxStringInputStream is a stream reading from the given (fixed size) string
20 // ----------------------------------------------------------------------------
22 class WXDLLIMPEXP_BASE wxStringInputStream
: public wxInputStream
25 // ctor associates the stream with the given string which makes a copy of
27 wxStringInputStream(const wxString
& s
);
29 virtual wxFileOffset
GetLength() const;
30 virtual bool IsSeekable() const { return true; }
33 virtual wxFileOffset
OnSysSeek(wxFileOffset ofs
, wxSeekMode mode
);
34 virtual wxFileOffset
OnSysTell() const;
35 virtual size_t OnSysRead(void *buffer
, size_t size
);
38 // the string that was passed in the ctor
41 // the buffer we're reading from
44 // length of the buffer we're reading from
47 // position in the stream in bytes, *not* in chars
50 wxDECLARE_NO_COPY_CLASS(wxStringInputStream
);
53 // ----------------------------------------------------------------------------
54 // wxStringOutputStream writes data to the given string, expanding it as needed
55 // ----------------------------------------------------------------------------
57 class WXDLLIMPEXP_BASE wxStringOutputStream
: public wxOutputStream
60 // The stream will write data either to the provided string or to an
61 // internal string which can be retrieved using GetString()
63 // Note that the conversion object should have the life time greater than
65 wxStringOutputStream(wxString
*pString
= NULL
,
66 wxMBConv
& conv
= wxConvUTF8
)
70 #endif // wxUSE_UNICODE
72 m_str
= pString
? pString
: &m_strInternal
;
73 m_pos
= m_str
->length() / sizeof(wxChar
);
76 // get the string containing current output
77 const wxString
& GetString() const { return *m_str
; }
79 virtual bool IsSeekable() const { return true; }
82 virtual wxFileOffset
OnSysTell() const;
83 virtual size_t OnSysWrite(const void *buffer
, size_t size
);
86 // internal string, not used if caller provided his own string
87 wxString m_strInternal
;
89 // pointer given by the caller or just pointer to m_strInternal
92 // position in the stream in bytes, *not* in chars
95 // converter to use: notice that with the default UTF-8 one the input
96 // stream must contain valid UTF-8 data, use wxConvISO8859_1 to work with
97 // arbitrary 8 bit data
101 // unconverted data from the last call to OnSysWrite()
102 wxMemoryBuffer m_unconv
;
103 #endif // wxUSE_UNICODE
105 wxDECLARE_NO_COPY_CLASS(wxStringOutputStream
);
108 #endif // wxUSE_STREAMS
110 #endif // _WX_SSTREAM_H_