]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxMemoryInputStream(wxMemoryOutputStream&) ctor (patch 1170635)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 2 Apr 2005 22:37:58 +0000 (22:37 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 2 Apr 2005 22:37:58 +0000 (22:37 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33293 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/strmmem.tex
include/wx/mstream.h
src/common/mstream.cpp
tests/streams/memstream.cpp

index 6a6388c2120e350f44c27078f91ba86bc6637b00..290f75ec69e09d0edfcb89d8e81c36f7413eb79c 100644 (file)
@@ -15,6 +15,7 @@ All:
 - Added WXK_SPECIAL keycodes for special hardware buttons.
 - Fixed bug with wxFile::Seek(-1, wxFromCurrent).
 - Added wxString/C array constructors to wxArrayString.
+- Added wxMemoryInputStream(wxMemoryOutputStream&) constructor (Stas Sergeev)
 
 All (GUI):
 
index 49dab77982437799f302bff00c5ce0a5509843eb..c3f3866aeaf03012f671531c1d712fc825066be4 100644 (file)
@@ -28,12 +28,24 @@ Initializes a new read-only memory stream which will use the specified buffer
 {\it data} of length {\it len}. The stream does not take ownership of the 
 buffer, i.e. that it will not delete in its destructor.
 
+\func{}{wxMemoryInputStream}{\param{const wxMemoryOutputStream&}{ stream}}
+
+Creates a new read-only memory stream, initilalizing it with the
+data from the given output stream \arg{stream}.
+
 \membersection{wxMemoryInputStream::\destruct{wxMemoryInputStream}}\label{wxmemoryinputstreamdtor}
 
 \func{}{\destruct{wxMemoryInputStream}}{\void}
 
 Destructor.
 
+\membersection{wxMemoryInputStream::GetInputStreamBuffer}\label{wxmemoryinputstreamgetistrmbuf}
+
+\constfunc{wxStreamBuffer *}{GetInputStreamBuffer}{\void}
+
+Returns the pointer to the stream object used as an internal buffer
+for that stream.
+
 % -----------------------------------------------------------------------------
 % wxMemoryOutputStream
 % -----------------------------------------------------------------------------
@@ -87,3 +99,9 @@ the buffer.
 CopyTo returns the number of bytes copied to the buffer. Generally it is either
 len or the size of the stream buffer.
 
+\membersection{wxMemoryOutputStream::GetOutputStreamBuffer}\label{wxmemoryoutputstreamgetostrmbuf}
+
+\constfunc{wxStreamBuffer *}{GetOutputStreamBuffer}{\void}
+
+Returns the pointer to the stream object used as an internal buffer
+for that stream.
index a679e6bb8fd81dc372c255ca706aae8ea5db8384..d1b8a6230cefdce7de1ce442074d41ab89ab6607 100644 (file)
 
 #include "wx/stream.h"
 
+class WXDLLIMPEXP_BASE wxMemoryOutputStream;
+
 class WXDLLIMPEXP_BASE wxMemoryInputStream : public wxInputStream
 {
 public:
     wxMemoryInputStream(const void *data, size_t length);
+    wxMemoryInputStream(const wxMemoryOutputStream& stream);
     virtual ~wxMemoryInputStream();
     virtual wxFileOffset GetLength() const { return m_length; }
     virtual bool Eof() const;
index 21cc9ee95c56ced529ec7f56a096ac453934afa7..bab2afe326febcfd2d7a1e3569cd72cf44da609b 100644 (file)
@@ -52,6 +52,22 @@ wxMemoryInputStream::wxMemoryInputStream(const void *data, size_t len)
     m_length = len;
 }
 
+wxMemoryInputStream::wxMemoryInputStream(const wxMemoryOutputStream& stream)
+{
+    int len = stream.GetLength();
+    if (len == wxInvalidOffset) {
+        m_i_streambuf = NULL;
+        m_lasterror = wxSTREAM_EOF;
+        return;
+    }
+    m_i_streambuf = new wxStreamBuffer(wxStreamBuffer::read);
+    m_i_streambuf->SetBufferIO(len); // create buffer
+    stream.CopyTo(m_i_streambuf->GetBufferStart(), len);
+    m_i_streambuf->SetIntPosition(0); // seek to start pos
+    m_i_streambuf->Fixed(true);
+    m_length = len;
+}
+
 wxMemoryInputStream::~wxMemoryInputStream()
 {
     delete m_i_streambuf;
index 7dee2c224e84e4f4feb5b2be15e675ee56e69a4d..6b5d2e610306bbc8594617227b8144bdcd053dd4 100644 (file)
@@ -56,10 +56,12 @@ public:
         CPPUNIT_TEST(Output_TellO);
 
         // Other test specific for Memory stream test case.
+        CPPUNIT_TEST(Ctor_InFromOut);
     CPPUNIT_TEST_SUITE_END();
 
 protected:
     // Add own test here.
+    void Ctor_InFromOut();
 
 private:
     const char *GetDataBuffer();
@@ -103,6 +105,21 @@ wxMemoryOutputStream *memStream::DoCreateOutStream()
     return pMemOutStream;
 }
 
+void memStream::Ctor_InFromOut()
+{
+    wxMemoryOutputStream *pMemOutStream = DoCreateOutStream();
+    pMemOutStream->Write(GetDataBuffer(), DATABUFFER_SIZE);
+    wxMemoryInputStream *pMemInStream = new wxMemoryInputStream(*pMemOutStream);
+    CPPUNIT_ASSERT(pMemInStream->IsOk());
+    CPPUNIT_ASSERT(pMemInStream->GetLength() == pMemOutStream->GetLength());
+    int len = pMemInStream->GetLength();
+    wxStreamBuffer *in = pMemInStream->GetInputStreamBuffer();
+    wxStreamBuffer *out = pMemOutStream->GetOutputStreamBuffer();
+    void *pIn = in->GetBufferStart();
+    void *pOut = out->GetBufferStart();
+    CPPUNIT_ASSERT(pIn != pOut);
+    CPPUNIT_ASSERT(memcmp(pIn, pOut, len) == 0);
+}
 
 // Register the stream sub suite, by using some stream helper macro.
 // Note: Don't forget to connect it to the base suite (See: bstream.cpp => StreamCase::suite())