1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: string-based streams
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_SSTREAM_H_
13 #define _WX_SSTREAM_H_
15 #include "wx/stream.h"
19 // ----------------------------------------------------------------------------
20 // wxStringInputStream is a stream reading from the given (fixed size) string
21 // ----------------------------------------------------------------------------
23 class WXDLLIMPEXP_BASE wxStringInputStream
: public wxInputStream
26 // ctor associates the stream with the given string which makes a copy of
28 wxStringInputStream(const wxString
& s
);
29 virtual ~wxStringInputStream();
31 virtual wxFileOffset
GetLength() const;
34 virtual wxFileOffset
OnSysSeek(wxFileOffset ofs
, wxSeekMode mode
);
35 virtual wxFileOffset
OnSysTell() const;
36 virtual size_t OnSysRead(void *buffer
, size_t size
);
39 // the string that was passed in the ctor
42 // the buffer we're reading from
45 // length of the buffer we're reading from
48 // position in the stream in bytes, *not* in chars
51 DECLARE_NO_COPY_CLASS(wxStringInputStream
)
54 // ----------------------------------------------------------------------------
55 // wxStringOutputStream writes data to the given string, expanding it as needed
56 // ----------------------------------------------------------------------------
58 class WXDLLIMPEXP_BASE wxStringOutputStream
: public wxOutputStream
61 // The stream will write data either to the provided string or to an
62 // internal string which can be retrieved using GetString()
63 wxStringOutputStream(wxString
*pString
= NULL
)
64 #if wxUSE_UNICODE_WCHAR
66 #endif // wxUSE_UNICODE_WCHAR
68 m_str
= pString
? pString
: &m_strInternal
;
69 m_pos
= m_str
->length() / sizeof(wxChar
);
72 // get the string containing current output
73 const wxString
& GetString() const { return *m_str
; }
76 virtual wxFileOffset
OnSysTell() const;
77 virtual size_t OnSysWrite(const void *buffer
, size_t size
);
80 // internal string, not used if caller provided his own string
81 wxString m_strInternal
;
83 // pointer given by the caller or just pointer to m_strInternal
86 // position in the stream in bytes, *not* in chars
90 // string encoding converter (UTF8 is the standard)
96 #if wxUSE_UNICODE_WCHAR
97 // unconverted data from the last call to OnSysWrite()
98 wxMemoryBuffer m_unconv
;
99 #endif // wxUSE_UNICODE_WCHAR
101 DECLARE_NO_COPY_CLASS(wxStringOutputStream
)
104 #endif // wxUSE_STREAMS
106 #endif // _WX_SSTREAM_H_