added wxStringStream classes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29223 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -176,6 +176,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
||||
src/common/object.cpp
|
||||
src/common/process.cpp
|
||||
src/common/regex.cpp
|
||||
src/common/sstream.cpp
|
||||
src/common/stopwatch.cpp
|
||||
src/common/strconv.cpp
|
||||
src/common/stream.cpp
|
||||
@@ -272,6 +273,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
|
||||
wx/regex.h
|
||||
wx/scopeguard.h
|
||||
wx/snglinst.h
|
||||
wx/sstream.h
|
||||
wx/stack.h
|
||||
wx/stockitem.h
|
||||
wx/stopwatch.h
|
||||
|
@@ -210,6 +210,7 @@ All:
|
||||
- deprecated wxDateTime::SetToTheWeek() in favour of SetToWeekOfYear()
|
||||
- active mode support in wxFTP (Randall Fox)
|
||||
- sped up wxHTTP and wxFTP
|
||||
- added wxStringInput/OutputStreams
|
||||
|
||||
All (GUI):
|
||||
|
||||
|
@@ -491,6 +491,8 @@ libraries, and to provide enhanced functionality.
|
||||
\twocolitem{\helpref{wxFileOutputStream}{wxfileoutputstream}}{File output stream class}
|
||||
\twocolitem{\helpref{wxFFileInputStream}{wxffileinputstream}}{Another file input stream class}
|
||||
\twocolitem{\helpref{wxFFileOutputStream}{wxffileoutputstream}}{Another file output stream class}
|
||||
\twocolitem{\helpref{wxStringInputStream}{wxstringinputstream}}{String input stream class}
|
||||
\twocolitem{\helpref{wxStringOutputStream}{wxstringoutputstream}}{String output stream class}
|
||||
\twocolitem{\helpref{wxZlibInputStream}{wxzlibinputstream}}{Zlib (compression) input stream class}
|
||||
\twocolitem{\helpref{wxZlibOutputStream}{wxzliboutputstream}}{Zlib (compression) output stream class}
|
||||
\twocolitem{\helpref{wxZipInputStream}{wxzipinputstream}}{Input stream for reading from ZIP archives}
|
||||
|
@@ -296,7 +296,9 @@
|
||||
\input strtotxt.tex
|
||||
\input wxstring.tex
|
||||
\input strcldat.tex
|
||||
\input sistream.tex
|
||||
\input strlist.tex
|
||||
\input sostream.tex
|
||||
\input tokenizr.tex
|
||||
\input sysclevt.tex
|
||||
\input sysopt.tex
|
||||
|
35
docs/latex/wx/sistream.tex
Normal file
35
docs/latex/wx/sistream.tex
Normal file
@@ -0,0 +1,35 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Name: sistream.tex
|
||||
%% Purpose: wxStringInputStream docs
|
||||
%% Author: Vadim Zeitlin
|
||||
%% Modified by:
|
||||
%% Created: 2004-09-19
|
||||
%% RCS-ID: $Id$
|
||||
%% Copyright: (c) 2004 Vadim Zeitlin
|
||||
%% License: wxWidgets licence
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
\section{\class{wxStringInputStream}}\label{wxstringinputstream}
|
||||
|
||||
This class implements an input stream which reads data from a string. It
|
||||
supports seeking.
|
||||
|
||||
\wxheading{Derived from}
|
||||
|
||||
\helpref{wxInputStream}{wxinputstream}
|
||||
|
||||
\wxheading{Include files}
|
||||
|
||||
<wx/sckstrm.h>
|
||||
|
||||
|
||||
\latexignore{\rtfignore{\wxheading{Members}}}
|
||||
|
||||
\membersection{wxStringInputStream::wxStringInputStream}
|
||||
|
||||
\func{}{wxStringInputStream}{\param{const wxString\&}{ s}}
|
||||
|
||||
Creates a new read-only stream using the specified string. Note that the string
|
||||
is copied by the stream so if the original string is modified after using this
|
||||
constructor, changes to it are not reflected when reading from stream.
|
||||
|
43
docs/latex/wx/sostream.tex
Normal file
43
docs/latex/wx/sostream.tex
Normal file
@@ -0,0 +1,43 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%% Name: sostream.tex
|
||||
%% Purpose: wxStringOutputStream docs
|
||||
%% Author: Vadim Zeitlin
|
||||
%% Modified by:
|
||||
%% Created: 2004-09-19
|
||||
%% RCS-ID: $Id$
|
||||
%% Copyright: (c) 2004 Vadim Zeitlin
|
||||
%% License: wxWidgets licence
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
\section{\class{wxStringOutputStream}}\label{wxstringoutputstream}
|
||||
|
||||
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.
|
||||
|
||||
\wxheading{Derived from}
|
||||
|
||||
\helpref{wxOutputStream}{wxoutputstream}
|
||||
|
||||
\wxheading{Include files}
|
||||
|
||||
<wx/sckstrm.h>
|
||||
|
||||
|
||||
\latexignore{\rtfignore{\wxheading{Members}}}
|
||||
|
||||
\membersection{wxStringOutputStream::wxStringOutputStream}
|
||||
|
||||
\func{}{wxStringOutputStream}{\param{wxString}{ *str = \texttt{NULL}}}
|
||||
|
||||
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.
|
||||
|
||||
|
||||
\membersection{wxStringOutputStream::GetString}\label{wxstringoutputstreamgetstring}
|
||||
|
||||
\constfunc{const wxString\&}{GetString}{\void}
|
||||
|
||||
Returns the string containing all the data written to the stream so far.
|
||||
|
89
include/wx/sstream.h
Normal file
89
include/wx/sstream.h
Normal file
@@ -0,0 +1,89 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/sstream.h
|
||||
// Purpose: string-based streams
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 2004-09-19
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_SSTREAM_H_
|
||||
#define _WX_SSTREAM_H_
|
||||
|
||||
#include "wx/stream.h"
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStringInputStream is a stream reading from the given (fixed size) string
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_BASE wxStringInputStream : public wxInputStream
|
||||
{
|
||||
public:
|
||||
// ctor associates the stream with the given string which makes a copy of
|
||||
// it
|
||||
wxStringInputStream(const wxString& s)
|
||||
: m_str(s)
|
||||
{
|
||||
m_pos = 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual size_t GetSize() const { return m_str.length(); }
|
||||
virtual off_t OnSysSeek(off_t ofs, wxSeekMode mode);
|
||||
virtual off_t OnSysTell() const;
|
||||
virtual size_t OnSysRead(void *buffer, size_t size);
|
||||
|
||||
private:
|
||||
// the string we're reading from
|
||||
wxString m_str;
|
||||
|
||||
// position in the stream in bytes, *not* in chars
|
||||
size_t m_pos;
|
||||
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxStringInputStream)
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStringOutputStream writes data to the given string, expanding it as needed
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_BASE wxStringOutputStream : public wxOutputStream
|
||||
{
|
||||
public:
|
||||
// The stream will write data either to the provided string or to an
|
||||
// internal string which can be retrieved using GetString()
|
||||
wxStringOutputStream(wxString *pString = NULL)
|
||||
{
|
||||
m_str = pString ? pString : &m_strInternal;
|
||||
m_pos = m_str->length() / sizeof(wxChar);
|
||||
}
|
||||
|
||||
// get the string containing current output
|
||||
const wxString& GetString() const { return *m_str; }
|
||||
|
||||
protected:
|
||||
virtual size_t OnSysWrite(const void *buffer, size_t size);
|
||||
|
||||
private:
|
||||
// internal string, not used if caller provided his own string
|
||||
wxString m_strInternal;
|
||||
|
||||
// pointer given by the caller or just pointer to m_strInternal
|
||||
wxString *m_str;
|
||||
|
||||
// position in the stream in bytes, *not* in chars
|
||||
size_t m_pos;
|
||||
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxStringOutputStream)
|
||||
};
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
||||
#endif // _WX_SSTREAM_H_
|
||||
|
117
src/common/sstream.cpp
Normal file
117
src/common/sstream.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: common/sstream.cpp
|
||||
// Purpose: string-based streams implementation
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 2004-09-19
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#if wxUSE_STREAMS
|
||||
|
||||
#include "wx/sstream.h"
|
||||
|
||||
// ============================================================================
|
||||
// wxStringInputStream implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// seek/tell
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
off_t wxStringInputStream::OnSysSeek(off_t ofs, wxSeekMode mode)
|
||||
{
|
||||
switch ( mode )
|
||||
{
|
||||
case wxFromStart:
|
||||
// nothing to do, ofs already ok
|
||||
break;
|
||||
|
||||
case wxFromEnd:
|
||||
ofs += m_str.length()*sizeof(wxChar);
|
||||
break;
|
||||
|
||||
case wxFromCurrent:
|
||||
ofs += m_pos;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( _T("invalid seek mode") );
|
||||
return wxInvalidOffset;
|
||||
}
|
||||
|
||||
m_pos = wx_static_cast(size_t, ofs);
|
||||
|
||||
return ofs;
|
||||
}
|
||||
|
||||
off_t wxStringInputStream::OnSysTell() const
|
||||
{
|
||||
return wx_static_cast(off_t, m_pos);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// actual IO
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
size_t wxStringInputStream::OnSysRead(void *buffer, size_t size)
|
||||
{
|
||||
const size_t sizeMax = m_str.length()*sizeof(wxChar) - m_pos;
|
||||
|
||||
if ( size >= sizeMax )
|
||||
{
|
||||
if ( sizeMax == 0 )
|
||||
{
|
||||
m_lasterror = wxSTREAM_EOF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = sizeMax;
|
||||
}
|
||||
|
||||
memcpy(buffer, m_str.data() + m_pos, size);
|
||||
m_pos += size;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxStringOutputStream implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// actual IO
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
size_t wxStringOutputStream::OnSysWrite(const void *buffer, size_t size)
|
||||
{
|
||||
// in Unicode mode we might not be able to write the last byte
|
||||
size_t len = size / sizeof(wxChar);
|
||||
|
||||
const wxChar *p = wx_static_cast(const wxChar *, buffer);
|
||||
|
||||
m_str->Append(wxString(p, p + len + 1));
|
||||
|
||||
// return number of bytes actually written
|
||||
return len*sizeof(wxChar);
|
||||
}
|
||||
|
||||
#endif // wxUSE_STREAMS
|
||||
|
Reference in New Issue
Block a user