Coverage Report

Created: 2026-11-12 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wxwidgets/include/wx/datstrm.h
Line
Count
Source
1
/////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/datstrm.h
3
// Purpose:     Data stream classes
4
// Author:      Guilhem Lavaux
5
// Modified by: Mickael Gilabert
6
// Created:     28/06/1998
7
// Copyright:   (c) Guilhem Lavaux
8
// Licence:     wxWindows licence
9
/////////////////////////////////////////////////////////////////////////////
10
11
#ifndef _WX_DATSTREAM_H_
12
#define _WX_DATSTREAM_H_
13
14
#include "wx/stream.h"
15
#include "wx/longlong.h"
16
#include "wx/convauto.h"
17
18
#if wxUSE_STREAMS
19
20
// Common wxDataInputStream and wxDataOutputStream parameters.
21
class WXDLLIMPEXP_BASE wxDataStreamBase
22
{
23
public:
24
0
    void BigEndianOrdered(bool be_order) { m_be_order = be_order; }
25
26
    // By default we use extended precision (80 bit) format for both float and
27
    // doubles. Call this function to switch to alternative representation in
28
    // which IEEE 754 single precision (32 bits) is used for floats and double
29
    // precision (64 bits) is used for doubles.
30
    void UseBasicPrecisions()
31
0
    {
32
0
#if wxUSE_APPLE_IEEE
33
0
        m_useExtendedPrecision = false;
34
0
#endif // wxUSE_APPLE_IEEE
35
0
    }
36
37
    // UseExtendedPrecision() is not very useful as it corresponds to the
38
    // default value, only call it in your code if you want the compilation
39
    // fail with the error when using wxWidgets library compiled without
40
    // extended precision support.
41
#if wxUSE_APPLE_IEEE
42
    void UseExtendedPrecision()
43
0
    {
44
0
        m_useExtendedPrecision = true;
45
0
    }
46
#endif // wxUSE_APPLE_IEEE
47
48
    void SetConv( const wxMBConv &conv );
49
0
    wxMBConv *GetConv() const { return m_conv; }
50
51
protected:
52
    // Ctor and dtor are both protected, this class is never used directly but
53
    // only by its derived classes.
54
    wxDataStreamBase(const wxMBConv& conv);
55
    ~wxDataStreamBase();
56
57
58
    bool m_be_order;
59
60
#if wxUSE_APPLE_IEEE
61
    bool m_useExtendedPrecision;
62
#endif // wxUSE_APPLE_IEEE
63
64
    wxMBConv *m_conv;
65
66
    wxDECLARE_NO_COPY_CLASS(wxDataStreamBase);
67
};
68
69
70
class WXDLLIMPEXP_BASE wxDataInputStream : public wxDataStreamBase
71
{
72
public:
73
    wxDataInputStream(wxInputStream& s, const wxMBConv& conv = wxConvUTF8);
74
75
0
    bool IsOk() { return m_input->IsOk(); }
76
77
    wxUint64 Read64();
78
    wxLongLong ReadLL();
79
    wxUint32 Read32();
80
    wxUint16 Read16();
81
    wxUint8 Read8();
82
    double ReadDouble();
83
    float ReadFloat();
84
    wxString ReadString();
85
86
    void Read64(wxUint64 *buffer, size_t size);
87
    void Read64(wxInt64 *buffer, size_t size);
88
    void Read64(wxULongLong *buffer, size_t size);
89
    void Read64(wxLongLong *buffer, size_t size);
90
    void ReadLL(wxULongLong *buffer, size_t size);
91
    void ReadLL(wxLongLong *buffer, size_t size);
92
    void Read32(wxUint32 *buffer, size_t size);
93
    void Read16(wxUint16 *buffer, size_t size);
94
    void Read8(wxUint8 *buffer, size_t size);
95
    void ReadDouble(double *buffer, size_t size);
96
    void ReadFloat(float *buffer, size_t size);
97
98
    wxDataInputStream& operator>>(wxString& s);
99
    wxDataInputStream& operator>>(wxInt8& c);
100
    wxDataInputStream& operator>>(wxInt16& i);
101
    wxDataInputStream& operator>>(wxInt32& i);
102
    wxDataInputStream& operator>>(wxUint8& c);
103
    wxDataInputStream& operator>>(wxUint16& i);
104
    wxDataInputStream& operator>>(wxUint32& i);
105
    wxDataInputStream& operator>>(wxUint64& i);
106
    wxDataInputStream& operator>>(wxInt64& i);
107
    wxDataInputStream& operator>>(wxULongLong& i);
108
    wxDataInputStream& operator>>(wxLongLong& i);
109
    wxDataInputStream& operator>>(double& d);
110
    wxDataInputStream& operator>>(float& f);
111
112
protected:
113
    wxInputStream *m_input;
114
115
private:
116
    // Try to read exactly the given number of bytes into the provided buffer.
117
    //
118
    // Return true if all of them could be read or mark the input stream as
119
    // being in error and return false if fewer bytes than requested are
120
    // available, as this means the data is truncated and can't be used.
121
    bool ReadBytes(void *buffer, size_t size);
122
123
    wxDECLARE_NO_COPY_CLASS(wxDataInputStream);
124
};
125
126
class WXDLLIMPEXP_BASE wxDataOutputStream : public wxDataStreamBase
127
{
128
public:
129
    wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv = wxConvUTF8);
130
131
0
    bool IsOk() { return m_output->IsOk(); }
132
133
    void Write64(wxUint64 i);
134
    void Write64(wxInt64 i);
135
    void WriteLL(const wxLongLong &ll);
136
    void WriteLL(const wxULongLong &ll);
137
    void Write32(wxUint32 i);
138
    void Write16(wxUint16 i);
139
    void Write8(wxUint8 i);
140
    void WriteDouble(double d);
141
    void WriteFloat(float f);
142
    void WriteString(const wxString& string);
143
144
    void Write64(const wxUint64 *buffer, size_t size);
145
    void Write64(const wxInt64 *buffer, size_t size);
146
    void Write64(const wxULongLong *buffer, size_t size);
147
    void Write64(const wxLongLong *buffer, size_t size);
148
    void WriteLL(const wxULongLong *buffer, size_t size);
149
    void WriteLL(const wxLongLong *buffer, size_t size);
150
    void Write32(const wxUint32 *buffer, size_t size);
151
    void Write16(const wxUint16 *buffer, size_t size);
152
    void Write8(const wxUint8 *buffer, size_t size);
153
    void WriteDouble(const double *buffer, size_t size);
154
    void WriteFloat(const float *buffer, size_t size);
155
156
    wxDataOutputStream& operator<<(const wxString& string);
157
    wxDataOutputStream& operator<<(wxInt8 c);
158
    wxDataOutputStream& operator<<(wxInt16 i);
159
    wxDataOutputStream& operator<<(wxInt32 i);
160
    wxDataOutputStream& operator<<(wxUint8 c);
161
    wxDataOutputStream& operator<<(wxUint16 i);
162
    wxDataOutputStream& operator<<(wxUint32 i);
163
    wxDataOutputStream& operator<<(wxUint64 i);
164
    wxDataOutputStream& operator<<(wxInt64 i);
165
    wxDataOutputStream& operator<<(const wxULongLong &i);
166
    wxDataOutputStream& operator<<(const wxLongLong &i);
167
    wxDataOutputStream& operator<<(double d);
168
    wxDataOutputStream& operator<<(float f);
169
170
protected:
171
    wxOutputStream *m_output;
172
173
    wxDECLARE_NO_COPY_CLASS(wxDataOutputStream);
174
};
175
176
#endif
177
  // wxUSE_STREAMS
178
179
#endif
180
    // _WX_DATSTREAM_H_