This class implements an output stream which writes data either to a
user-provided or internally allocated string. Note that currently this stream
-does not support seeking.
+does not support seeking but can tell its current position.
\wxheading{Derived from}
Otherwise, an internal string is used for the data written to this stream, use
\helpref{GetString()}{wxstringoutputstreamgetstring} to get access to it.
+If \arg{str} is used, data written to the stream is appended to the current
+contents of it, i.e. the string is not cleared here. However if it is not
+empty, the positions returned by \helpref{TellO}{wxoutputstreamtello} will be
+offset by the initial string length, i.e. initial stream position will be the
+initial length of the string and not $0$.
+
\membersection{wxStringOutputStream::GetString}\label{wxstringoutputstreamgetstring}
const wxString& GetString() const { return *m_str; }
protected:
+ virtual off_t OnSysTell() const;
virtual size_t OnSysWrite(const void *buffer, size_t size);
private:
// wxStringOutputStream implementation
// ============================================================================
+// ----------------------------------------------------------------------------
+// seek/tell
+// ----------------------------------------------------------------------------
+
+off_t wxStringOutputStream::OnSysTell() const
+{
+ return wx_static_cast(off_t, m_pos);
+}
+
// ----------------------------------------------------------------------------
// actual IO
// ----------------------------------------------------------------------------
const wxChar *p = wx_static_cast(const wxChar *, buffer);
- m_str->Append(wxString(p, p + len + 1));
+ m_str->Append(wxString(p, p + len));
// return number of bytes actually written
- return len*sizeof(wxChar);
+ len *= sizeof(wxChar);
+ m_pos += len;
+
+ return len;
}
#endif // wxUSE_STREAMS