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
)
34 virtual wxFileOffset
GetLength() const { return m_str
.length(); }
37 virtual wxFileOffset
OnSysSeek(wxFileOffset ofs
, wxSeekMode mode
);
38 virtual wxFileOffset
OnSysTell() const;
39 virtual size_t OnSysRead(void *buffer
, size_t size
);
42 // the string we're reading from
45 // position in the stream in bytes, *not* in chars
49 DECLARE_NO_COPY_CLASS(wxStringInputStream
)
52 // ----------------------------------------------------------------------------
53 // wxStringOutputStream writes data to the given string, expanding it as needed
54 // ----------------------------------------------------------------------------
56 class WXDLLIMPEXP_BASE wxStringOutputStream
: public wxOutputStream
59 // The stream will write data either to the provided string or to an
60 // internal string which can be retrieved using GetString()
61 wxStringOutputStream(wxString
*pString
= NULL
)
63 m_str
= pString
? pString
: &m_strInternal
;
64 m_pos
= m_str
->length() / sizeof(wxChar
);
67 // get the string containing current output
68 const wxString
& GetString() const { return *m_str
; }
71 virtual wxFileOffset
OnSysTell() const;
72 virtual size_t OnSysWrite(const void *buffer
, size_t size
);
75 // internal string, not used if caller provided his own string
76 wxString m_strInternal
;
78 // pointer given by the caller or just pointer to m_strInternal
81 // position in the stream in bytes, *not* in chars
85 DECLARE_NO_COPY_CLASS(wxStringOutputStream
)
88 #endif // wxUSE_STREAMS
90 #endif // _WX_SSTREAM_H_