]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sstream.h
wx(Choice/List/Note)book controls send CHANG(ED/ING) events in SetSelection.
[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
28 wxStringInputStream(const wxString& s)
29 : m_str(s)
30 {
31 m_pos = 0;
32 }
33
121fa06a 34 virtual size_t GetSize() const { return m_str.length(); }
ba670bae
VZ
35
36protected:
121fa06a
VZ
37 virtual off_t OnSysSeek(off_t ofs, wxSeekMode mode);
38 virtual off_t OnSysTell() const;
39 virtual size_t OnSysRead(void *buffer, size_t size);
40
41private:
42 // the string we're reading from
43 wxString m_str;
44
45 // position in the stream in bytes, *not* in chars
46 size_t m_pos;
47
48
49 DECLARE_NO_COPY_CLASS(wxStringInputStream)
50};
51
52// ----------------------------------------------------------------------------
53// wxStringOutputStream writes data to the given string, expanding it as needed
54// ----------------------------------------------------------------------------
55
56class WXDLLIMPEXP_BASE wxStringOutputStream : public wxOutputStream
57{
58public:
59 // The stream will write data either to the provided string or to an
60 // internal string which can be retrieved using GetString()
61 wxStringOutputStream(wxString *pString = NULL)
62 {
63 m_str = pString ? pString : &m_strInternal;
64 m_pos = m_str->length() / sizeof(wxChar);
65 }
66
67 // get the string containing current output
68 const wxString& GetString() const { return *m_str; }
69
70protected:
a5ea75bc 71 virtual off_t OnSysTell() const;
121fa06a
VZ
72 virtual size_t OnSysWrite(const void *buffer, size_t size);
73
74private:
75 // internal string, not used if caller provided his own string
76 wxString m_strInternal;
77
78 // pointer given by the caller or just pointer to m_strInternal
79 wxString *m_str;
80
81 // position in the stream in bytes, *not* in chars
82 size_t m_pos;
83
84
85 DECLARE_NO_COPY_CLASS(wxStringOutputStream)
86};
87
88#endif // wxUSE_STREAMS
89
90#endif // _WX_SSTREAM_H_
91