]>
Commit | Line | Data |
---|---|---|
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 | ||
23 | class WXDLLIMPEXP_BASE wxStringInputStream : public wxInputStream | |
24 | { | |
25 | public: | |
26 | // ctor associates the stream with the given string which makes a copy of | |
27 | // it | |
c5d99d7b RN |
28 | wxStringInputStream(const wxString& s); |
29 | virtual ~wxStringInputStream(); | |
121fa06a | 30 | |
c5d99d7b | 31 | virtual wxFileOffset GetLength() const; |
ba670bae VZ |
32 | |
33 | protected: | |
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 | ||
38 | private: | |
c5d99d7b | 39 | // the string that was passed in the ctor |
121fa06a VZ |
40 | wxString m_str; |
41 | ||
c5d99d7b RN |
42 | // the buffer we're reading from |
43 | char* m_buf; | |
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 | ||
121fa06a VZ |
51 | DECLARE_NO_COPY_CLASS(wxStringInputStream) |
52 | }; | |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // wxStringOutputStream writes data to the given string, expanding it as needed | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | class WXDLLIMPEXP_BASE wxStringOutputStream : public wxOutputStream | |
59 | { | |
60 | public: | |
61 | // The stream will write data either to the provided string or to an | |
62 | // internal string which can be retrieved using GetString() | |
63 | wxStringOutputStream(wxString *pString = NULL) | |
2c17722e VZ |
64 | #if wxUSE_UNICODE_WCHAR |
65 | : m_unconv(0) | |
66 | #endif // wxUSE_UNICODE_WCHAR | |
121fa06a VZ |
67 | { |
68 | m_str = pString ? pString : &m_strInternal; | |
69 | m_pos = m_str->length() / sizeof(wxChar); | |
70 | } | |
71 | ||
72 | // get the string containing current output | |
73 | const wxString& GetString() const { return *m_str; } | |
74 | ||
75 | protected: | |
4004775e | 76 | virtual wxFileOffset OnSysTell() const; |
121fa06a VZ |
77 | virtual size_t OnSysWrite(const void *buffer, size_t size); |
78 | ||
79 | private: | |
80 | // internal string, not used if caller provided his own string | |
81 | wxString m_strInternal; | |
82 | ||
83 | // pointer given by the caller or just pointer to m_strInternal | |
84 | wxString *m_str; | |
85 | ||
86 | // position in the stream in bytes, *not* in chars | |
87 | size_t m_pos; | |
88 | ||
61c213fe | 89 | #if wxUSE_WCHAR_T |
c5d99d7b RN |
90 | // string encoding converter (UTF8 is the standard) |
91 | wxMBConvUTF8 m_conv; | |
61c213fe MW |
92 | #else |
93 | wxMBConv m_conv; | |
94 | #endif | |
121fa06a | 95 | |
2c17722e VZ |
96 | #if wxUSE_UNICODE_WCHAR |
97 | // unconverted data from the last call to OnSysWrite() | |
98 | wxMemoryBuffer m_unconv; | |
99 | #endif // wxUSE_UNICODE_WCHAR | |
100 | ||
121fa06a VZ |
101 | DECLARE_NO_COPY_CLASS(wxStringOutputStream) |
102 | }; | |
103 | ||
104 | #endif // wxUSE_STREAMS | |
105 | ||
106 | #endif // _WX_SSTREAM_H_ | |
107 |