]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sstream.h
Added wxPropertyGrid::DedicateKey(), which prevents specific key presses from being...
[wxWidgets.git] / include / wx / sstream.h
CommitLineData
121fa06a
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/sstream.h
3// Purpose: string-based streams
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 2004-09-19
7// RCS-ID: $Id$
8// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_SSTREAM_H_
13#define _WX_SSTREAM_H_
14
15#include "wx/stream.h"
16
17#if wxUSE_STREAMS
18
19// ----------------------------------------------------------------------------
20// wxStringInputStream is a stream reading from the given (fixed size) string
21// ----------------------------------------------------------------------------
22
23class WXDLLIMPEXP_BASE wxStringInputStream : public wxInputStream
24{
25public:
26 // ctor associates the stream with the given string which makes a copy of
27 // it
c5d99d7b 28 wxStringInputStream(const wxString& s);
121fa06a 29
c5d99d7b 30 virtual wxFileOffset GetLength() const;
421f32d1 31 virtual bool IsSeekable() const { return true; }
ba670bae
VZ
32
33protected:
4004775e
RL
34 virtual wxFileOffset OnSysSeek(wxFileOffset ofs, wxSeekMode mode);
35 virtual wxFileOffset OnSysTell() const;
121fa06a
VZ
36 virtual size_t OnSysRead(void *buffer, size_t size);
37
38private:
c5d99d7b 39 // the string that was passed in the ctor
121fa06a
VZ
40 wxString m_str;
41
c5d99d7b 42 // the buffer we're reading from
86501081 43 wxCharBuffer m_buf;
c5d99d7b
RN
44
45 // length of the buffer we're reading from
46 size_t m_len;
47
121fa06a
VZ
48 // position in the stream in bytes, *not* in chars
49 size_t m_pos;
50
c0c133e1 51 wxDECLARE_NO_COPY_CLASS(wxStringInputStream);
121fa06a
VZ
52};
53
54// ----------------------------------------------------------------------------
55// wxStringOutputStream writes data to the given string, expanding it as needed
56// ----------------------------------------------------------------------------
57
58class WXDLLIMPEXP_BASE wxStringOutputStream : public wxOutputStream
59{
60public:
61 // The stream will write data either to the provided string or to an
62 // internal string which can be retrieved using GetString()
63482fd5
VZ
63 //
64 // Note that the conversion object should have the life time greater than
65 // this stream.
66 wxStringOutputStream(wxString *pString = NULL,
67 wxMBConv& conv = wxConvUTF8)
68 : m_conv(conv)
2c17722e 69#if wxUSE_UNICODE_WCHAR
63482fd5 70 , m_unconv(0)
2c17722e 71#endif // wxUSE_UNICODE_WCHAR
121fa06a
VZ
72 {
73 m_str = pString ? pString : &m_strInternal;
74 m_pos = m_str->length() / sizeof(wxChar);
75 }
76
77 // get the string containing current output
78 const wxString& GetString() const { return *m_str; }
79
421f32d1
VZ
80 virtual bool IsSeekable() const { return true; }
81
121fa06a 82protected:
4004775e 83 virtual wxFileOffset OnSysTell() const;
121fa06a
VZ
84 virtual size_t OnSysWrite(const void *buffer, size_t size);
85
86private:
87 // internal string, not used if caller provided his own string
88 wxString m_strInternal;
89
90 // pointer given by the caller or just pointer to m_strInternal
91 wxString *m_str;
92
93 // position in the stream in bytes, *not* in chars
94 size_t m_pos;
95
63482fd5
VZ
96 // converter to use: notice that with the default UTF-8 one the input
97 // stream must contain valid UTF-8 data, use wxConvISO8859_1 to work with
98 // arbitrary 8 bit data
99 wxMBConv& m_conv;
121fa06a 100
2c17722e
VZ
101#if wxUSE_UNICODE_WCHAR
102 // unconverted data from the last call to OnSysWrite()
103 wxMemoryBuffer m_unconv;
104#endif // wxUSE_UNICODE_WCHAR
105
c0c133e1 106 wxDECLARE_NO_COPY_CLASS(wxStringOutputStream);
121fa06a
VZ
107};
108
109#endif // wxUSE_STREAMS
110
111#endif // _WX_SSTREAM_H_
112