]>
git.saurik.com Git - wxWidgets.git/blob - src/common/mstream.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: "Memory stream" classes
4 // Author: Guilhem Lavaux
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mstream.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include <wx/stream.h>
27 #include <wx/mstream.h>
29 // ----------------------------------------------------------------------------
30 // wxMemoryInputStream
31 // ----------------------------------------------------------------------------
33 wxMemoryInputStream::wxMemoryInputStream(const char *data
, size_t len
)
36 m_i_streambuf
= new wxStreamBuffer(wxStreamBuffer::read
);
37 m_i_streambuf
->SetBufferIO((char*) data
, (char*) (data
+len
));
38 m_i_streambuf
->SetIntPosition(0); // seek to start pos
39 m_i_streambuf
->Fixed(TRUE
);
44 wxMemoryInputStream::~wxMemoryInputStream()
49 char wxMemoryInputStream::Peek()
51 return m_i_streambuf
->GetBufferStart()[m_i_streambuf
->GetIntPosition()];
54 size_t wxMemoryInputStream::OnSysRead(void *buffer
, size_t nbytes
)
57 return m_i_streambuf
->Read(buffer
, nbytes
);
60 off_t
wxMemoryInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
62 return m_i_streambuf
->Seek(pos
, mode
);
65 off_t
wxMemoryInputStream::OnSysTell() const
67 return m_i_streambuf
->Tell();
70 // ----------------------------------------------------------------------------
71 // wxMemoryOutputStream
72 // ----------------------------------------------------------------------------
74 wxMemoryOutputStream::wxMemoryOutputStream(char *data
, size_t len
)
77 m_o_streambuf
= new wxStreamBuffer(wxStreamBuffer::write
);
79 m_o_streambuf
->SetBufferIO(data
, data
+len
);
80 m_o_streambuf
->Fixed(TRUE
);
83 wxMemoryOutputStream::~wxMemoryOutputStream()
88 size_t wxMemoryOutputStream::OnSysWrite(const void *buffer
, size_t nbytes
)
91 return m_o_streambuf
->Write(buffer
, nbytes
);
94 off_t
wxMemoryOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
96 return m_o_streambuf
->Seek(pos
, mode
);
99 off_t
wxMemoryOutputStream::OnSysTell() const
101 return m_o_streambuf
->Tell();
104 size_t wxMemoryOutputStream::CopyTo(char *buffer
, size_t len
) const
112 memcpy(buffer
, m_o_streambuf
->GetBufferStart(), len
);