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