Coverage Report

Created: 2023-02-22 06:06

/src/wxwidgets/include/wx/txtstrm.h
Line
Count
Source (jump to first uncovered line)
1
/////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/txtstrm.h
3
// Purpose:     Text stream classes
4
// Author:      Guilhem Lavaux
5
// Modified by:
6
// Created:     28/06/1998
7
// Copyright:   (c) Guilhem Lavaux
8
// Licence:     wxWindows licence
9
/////////////////////////////////////////////////////////////////////////////
10
11
#ifndef _WX_TXTSTREAM_H_
12
#define _WX_TXTSTREAM_H_
13
14
#include "wx/stream.h"
15
#include "wx/convauto.h"
16
17
#if wxUSE_STREAMS
18
19
class WXDLLIMPEXP_FWD_BASE wxTextInputStream;
20
class WXDLLIMPEXP_FWD_BASE wxTextOutputStream;
21
22
typedef wxTextInputStream& (*__wxTextInputManip)(wxTextInputStream&);
23
typedef wxTextOutputStream& (*__wxTextOutputManip)(wxTextOutputStream&);
24
25
WXDLLIMPEXP_BASE wxTextOutputStream &endl( wxTextOutputStream &stream );
26
27
28
// Obsolete constant defined only for compatibility, not used.
29
#define wxEOT wxT('\4')
30
31
// If you're scanning through a file using wxTextInputStream, you should check for EOF _before_
32
// reading the next item (word / number), because otherwise the last item may get lost.
33
// You should however be prepared to receive an empty item (empty string / zero number) at the
34
// end of file, especially on Windows systems. This is unavoidable because most (but not all) files end
35
// with whitespace (i.e. usually a newline).
36
class WXDLLIMPEXP_BASE wxTextInputStream
37
{
38
public:
39
    wxTextInputStream(wxInputStream& s,
40
                      const wxString &sep=wxT(" \t"),
41
                      const wxMBConv& conv = wxConvAuto());
42
    ~wxTextInputStream();
43
44
0
    const wxInputStream& GetInputStream() const { return m_input; }
45
46
    // base may be between 2 and 36, inclusive, or the special 0 (= C format)
47
    wxUint64 Read64(int base = 10);
48
    wxUint32 Read32(int base = 10);
49
    wxUint16 Read16(int base = 10);
50
    wxUint8  Read8(int base = 10);
51
    wxInt64  Read64S(int base = 10);
52
    wxInt32  Read32S(int base = 10);
53
    wxInt16  Read16S(int base = 10);
54
    wxInt8   Read8S(int base = 10);
55
    double   ReadDouble();
56
    wxString ReadLine();
57
    wxString ReadWord();
58
    wxChar   GetChar();
59
60
0
    wxString GetStringSeparators() const { return m_separators; }
61
0
    void SetStringSeparators(const wxString &c) { m_separators = c; }
62
63
    // Operators
64
    wxTextInputStream& operator>>(wxString& word);
65
    wxTextInputStream& operator>>(char& c);
66
#if wxWCHAR_T_IS_REAL_TYPE
67
    wxTextInputStream& operator>>(wchar_t& wc);
68
#endif
69
    wxTextInputStream& operator>>(wxInt16& i);
70
    wxTextInputStream& operator>>(wxInt32& i);
71
    wxTextInputStream& operator>>(wxInt64& i);
72
    wxTextInputStream& operator>>(wxUint16& i);
73
    wxTextInputStream& operator>>(wxUint32& i);
74
    wxTextInputStream& operator>>(wxUint64& i);
75
    wxTextInputStream& operator>>(double& i);
76
    wxTextInputStream& operator>>(float& f);
77
78
0
    wxTextInputStream& operator>>( __wxTextInputManip func) { return func(*this); }
79
80
protected:
81
    wxInputStream &m_input;
82
    wxString m_separators;
83
84
    // Data possibly (see m_validXXX) read from the stream but not decoded yet.
85
    // This is necessary because GetChar() may only return a single character
86
    // but we may get more than one character when decoding raw input bytes.
87
    char m_lastBytes[10];
88
89
    // The bytes [0, m_validEnd) of m_lastBytes contain the bytes read by the
90
    // last GetChar() call (this interval may be empty if GetChar() hasn't been
91
    // called yet). The bytes [0, m_validBegin) have been already decoded and
92
    // returned to caller or stored in m_lastWChar in the particularly
93
    // egregious case of decoding a non-BMP character when using UTF-16 for
94
    // wchar_t. Finally, the bytes [m_validBegin, m_validEnd) remain to be
95
    // decoded and returned during the next call (again, this interval can, and
96
    // usually will, be empty too if m_validBegin == m_validEnd).
97
    size_t m_validBegin,
98
           m_validEnd;
99
100
    wxMBConv *m_conv;
101
102
    // The second half of a surrogate character when using UTF-16 for wchar_t:
103
    // we can't return it immediately from GetChar() when we read a Unicode
104
    // code point outside of the BMP, but we can't keep it in m_lastBytes
105
    // either because it can't separately decoded, so we have a separate 1
106
    // wchar_t buffer just for this case.
107
#if SIZEOF_WCHAR_T == 2
108
    wchar_t m_lastWChar;
109
#endif // SIZEOF_WCHAR_T == 2
110
111
    bool   EatEOL(const wxChar &c);
112
    void   UngetLast(); // should be used instead of wxInputStream::Ungetch() because of Unicode issues
113
    wxChar NextNonSeparators();
114
115
    wxDECLARE_NO_COPY_CLASS(wxTextInputStream);
116
};
117
118
enum wxEOL
119
{
120
  wxEOL_NATIVE,
121
  wxEOL_UNIX,
122
  wxEOL_MAC,
123
  wxEOL_DOS
124
};
125
126
class WXDLLIMPEXP_BASE wxTextOutputStream
127
{
128
public:
129
    wxTextOutputStream(wxOutputStream& s,
130
                       wxEOL mode = wxEOL_NATIVE,
131
                       const wxMBConv& conv = wxConvAuto());
132
    virtual ~wxTextOutputStream();
133
134
0
    const wxOutputStream& GetOutputStream() const { return m_output; }
135
136
    void SetMode( wxEOL mode = wxEOL_NATIVE );
137
0
    wxEOL GetMode() { return m_mode; }
138
139
    template<typename T>
140
    void Write(const T& i)
141
0
    {
142
0
        wxString str;
143
0
        str << i;
144
145
0
        WriteString(str);
146
0
    }
Unexecuted instantiation: void wxTextOutputStream::Write<short>(short const&)
Unexecuted instantiation: void wxTextOutputStream::Write<int>(int const&)
Unexecuted instantiation: void wxTextOutputStream::Write<long long>(long long const&)
Unexecuted instantiation: void wxTextOutputStream::Write<unsigned short>(unsigned short const&)
Unexecuted instantiation: void wxTextOutputStream::Write<unsigned int>(unsigned int const&)
Unexecuted instantiation: void wxTextOutputStream::Write<unsigned long long>(unsigned long long const&)
Unexecuted instantiation: void wxTextOutputStream::Write<double>(double const&)
Unexecuted instantiation: void wxTextOutputStream::Write<float>(float const&)
147
148
    void Write64(wxUint64 i);
149
    void Write32(wxUint32 i);
150
    void Write16(wxUint16 i);
151
    void Write8(wxUint8 i);
152
    virtual void WriteDouble(double d);
153
    virtual void WriteString(const wxString& string);
154
155
    wxTextOutputStream& PutChar(wxChar c);
156
157
    void Flush();
158
159
    wxTextOutputStream& operator<<(const wxString& string);
160
    wxTextOutputStream& operator<<(char c);
161
#if wxWCHAR_T_IS_REAL_TYPE
162
    wxTextOutputStream& operator<<(wchar_t wc);
163
#endif
164
    wxTextOutputStream& operator<<(wxInt16 c);
165
    wxTextOutputStream& operator<<(wxInt32 c);
166
    wxTextOutputStream& operator<<(wxInt64 c);
167
    wxTextOutputStream& operator<<(wxUint16 c);
168
    wxTextOutputStream& operator<<(wxUint32 c);
169
    wxTextOutputStream& operator<<(wxUint64 c);
170
    wxTextOutputStream& operator<<(double f);
171
    wxTextOutputStream& operator<<(float f);
172
173
0
    wxTextOutputStream& operator<<( __wxTextOutputManip func) { return func(*this); }
174
175
protected:
176
    wxOutputStream &m_output;
177
    wxEOL           m_mode;
178
179
    wxMBConv *m_conv;
180
181
#if SIZEOF_WCHAR_T == 2
182
    // The first half of a surrogate character if one was passed to PutChar()
183
    // and couldn't be output when it was called the last time.
184
    wchar_t m_lastWChar;
185
#endif // SIZEOF_WCHAR_T == 2
186
187
    wxDECLARE_NO_COPY_CLASS(wxTextOutputStream);
188
};
189
190
#endif
191
  // wxUSE_STREAMS
192
193
#endif
194
    // _WX_DATSTREAM_H_