]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxStringOutputStream::TellO(); fixed bugs in OnSysWrite()
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 19 Sep 2004 21:58:50 +0000 (21:58 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 19 Sep 2004 21:58:50 +0000 (21:58 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/sostream.tex
include/wx/sstream.h
src/common/sstream.cpp

index 1f64d55d16125c0b47ec5788e0fea99d49757153..aba23e7149c77bb40c5ad8984e170e93e1c52061 100644 (file)
@@ -13,7 +13,7 @@
 
 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}
 
@@ -34,6 +34,12 @@ If the provided pointer is non-\texttt{NULL}, data will be written to it.
 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}
 
index 0bc18690ed23c729a9c3205cb2a9f5ecb9881c0c..e188c1a00cd8c87d4739e59d97b6b9e69299cd04 100644 (file)
@@ -68,6 +68,7 @@ public:
     const wxString& GetString() const { return *m_str; }
 
 protected:
+    virtual off_t OnSysTell() const;
     virtual size_t OnSysWrite(const void *buffer, size_t size);
 
 private:
index de3496327e3192dad12f5297fd1c1e24a20d547b..1a87534dc31c7be7571e061c206a0556d995e0ec 100644 (file)
@@ -101,6 +101,15 @@ size_t wxStringInputStream::OnSysRead(void *buffer, size_t size)
 // wxStringOutputStream implementation
 // ============================================================================
 
+// ----------------------------------------------------------------------------
+// seek/tell
+// ----------------------------------------------------------------------------
+
+off_t wxStringOutputStream::OnSysTell() const
+{
+    return wx_static_cast(off_t, m_pos);
+}
+
 // ----------------------------------------------------------------------------
 // actual IO
 // ----------------------------------------------------------------------------
@@ -112,10 +121,13 @@ size_t wxStringOutputStream::OnSysWrite(const void *buffer, size_t size)
 
     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