]>
Commit | Line | Data |
---|---|---|
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 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Guilhem Lavaux | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_DATSTREAM_H_ | |
13 | #define _WX_DATSTREAM_H_ | |
14 | ||
15 | #include "wx/stream.h" | |
16 | #include "wx/longlong.h" | |
17 | #include "wx/convauto.h" | |
18 | ||
19 | #if wxUSE_STREAMS | |
20 | ||
21 | // Common wxDataInputStream and wxDataOutputStream parameters. | |
22 | class WXDLLIMPEXP_BASE wxDataStreamBase | |
23 | { | |
24 | public: | |
25 | void BigEndianOrdered(bool be_order) { m_be_order = be_order; } | |
26 | ||
27 | // By default we use extended precision (80 bit) format for both float and | |
28 | // doubles. Call this function to switch to alternative representation in | |
29 | // which IEEE 754 single precision (32 bits) is used for floats and double | |
30 | // precision (64 bits) is used for doubles. | |
31 | void UseBasicPrecisions() | |
32 | { | |
33 | #if wxUSE_APPLE_IEEE | |
34 | m_useExtendedPrecision = false; | |
35 | #endif // wxUSE_APPLE_IEEE | |
36 | } | |
37 | ||
38 | // UseExtendedPrecision() is not very useful as it corresponds to the | |
39 | // default value, only call it in your code if you want the compilation | |
40 | // fail with the error when using wxWidgets library compiled without | |
41 | // extended precision support. | |
42 | #if wxUSE_APPLE_IEEE | |
43 | void UseExtendedPrecision() | |
44 | { | |
45 | m_useExtendedPrecision = true; | |
46 | } | |
47 | #endif // wxUSE_APPLE_IEEE | |
48 | ||
49 | #if wxUSE_UNICODE | |
50 | void SetConv( const wxMBConv &conv ); | |
51 | wxMBConv *GetConv() const { return m_conv; } | |
52 | #endif | |
53 | ||
54 | protected: | |
55 | // Ctor and dtor are both protected, this class is never used directly but | |
56 | // only by its derived classes. | |
57 | wxDataStreamBase(const wxMBConv& conv); | |
58 | ~wxDataStreamBase(); | |
59 | ||
60 | ||
61 | bool m_be_order; | |
62 | ||
63 | #if wxUSE_APPLE_IEEE | |
64 | bool m_useExtendedPrecision; | |
65 | #endif // wxUSE_APPLE_IEEE | |
66 | ||
67 | #if wxUSE_UNICODE | |
68 | wxMBConv *m_conv; | |
69 | #endif | |
70 | ||
71 | wxDECLARE_NO_COPY_CLASS(wxDataStreamBase); | |
72 | }; | |
73 | ||
74 | ||
75 | class WXDLLIMPEXP_BASE wxDataInputStream : public wxDataStreamBase | |
76 | { | |
77 | public: | |
78 | wxDataInputStream(wxInputStream& s, const wxMBConv& conv = wxConvUTF8); | |
79 | ||
80 | bool IsOk() { return m_input->IsOk(); } | |
81 | ||
82 | #if wxHAS_INT64 | |
83 | wxUint64 Read64(); | |
84 | #endif | |
85 | #if wxUSE_LONGLONG | |
86 | wxLongLong ReadLL(); | |
87 | #endif | |
88 | wxUint32 Read32(); | |
89 | wxUint16 Read16(); | |
90 | wxUint8 Read8(); | |
91 | double ReadDouble(); | |
92 | float ReadFloat(); | |
93 | wxString ReadString(); | |
94 | ||
95 | #if wxHAS_INT64 | |
96 | void Read64(wxUint64 *buffer, size_t size); | |
97 | void Read64(wxInt64 *buffer, size_t size); | |
98 | #endif | |
99 | #if defined(wxLongLong_t) && wxUSE_LONGLONG | |
100 | void Read64(wxULongLong *buffer, size_t size); | |
101 | void Read64(wxLongLong *buffer, size_t size); | |
102 | #endif | |
103 | #if wxUSE_LONGLONG | |
104 | void ReadLL(wxULongLong *buffer, size_t size); | |
105 | void ReadLL(wxLongLong *buffer, size_t size); | |
106 | #endif | |
107 | void Read32(wxUint32 *buffer, size_t size); | |
108 | void Read16(wxUint16 *buffer, size_t size); | |
109 | void Read8(wxUint8 *buffer, size_t size); | |
110 | void ReadDouble(double *buffer, size_t size); | |
111 | void ReadFloat(float *buffer, size_t size); | |
112 | ||
113 | wxDataInputStream& operator>>(wxString& s); | |
114 | wxDataInputStream& operator>>(wxInt8& c); | |
115 | wxDataInputStream& operator>>(wxInt16& i); | |
116 | wxDataInputStream& operator>>(wxInt32& i); | |
117 | wxDataInputStream& operator>>(wxUint8& c); | |
118 | wxDataInputStream& operator>>(wxUint16& i); | |
119 | wxDataInputStream& operator>>(wxUint32& i); | |
120 | #if wxHAS_INT64 | |
121 | wxDataInputStream& operator>>(wxUint64& i); | |
122 | wxDataInputStream& operator>>(wxInt64& i); | |
123 | #endif | |
124 | #if defined(wxLongLong_t) && wxUSE_LONGLONG | |
125 | wxDataInputStream& operator>>(wxULongLong& i); | |
126 | wxDataInputStream& operator>>(wxLongLong& i); | |
127 | #endif | |
128 | wxDataInputStream& operator>>(double& d); | |
129 | wxDataInputStream& operator>>(float& f); | |
130 | ||
131 | protected: | |
132 | wxInputStream *m_input; | |
133 | ||
134 | wxDECLARE_NO_COPY_CLASS(wxDataInputStream); | |
135 | }; | |
136 | ||
137 | class WXDLLIMPEXP_BASE wxDataOutputStream : public wxDataStreamBase | |
138 | { | |
139 | public: | |
140 | wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv = wxConvUTF8); | |
141 | ||
142 | bool IsOk() { return m_output->IsOk(); } | |
143 | ||
144 | #if wxHAS_INT64 | |
145 | void Write64(wxUint64 i); | |
146 | void Write64(wxInt64 i); | |
147 | #endif | |
148 | #if wxUSE_LONGLONG | |
149 | void WriteLL(const wxLongLong &ll); | |
150 | void WriteLL(const wxULongLong &ll); | |
151 | #endif | |
152 | void Write32(wxUint32 i); | |
153 | void Write16(wxUint16 i); | |
154 | void Write8(wxUint8 i); | |
155 | void WriteDouble(double d); | |
156 | void WriteFloat(float f); | |
157 | void WriteString(const wxString& string); | |
158 | ||
159 | #if wxHAS_INT64 | |
160 | void Write64(const wxUint64 *buffer, size_t size); | |
161 | void Write64(const wxInt64 *buffer, size_t size); | |
162 | #endif | |
163 | #if defined(wxLongLong_t) && wxUSE_LONGLONG | |
164 | void Write64(const wxULongLong *buffer, size_t size); | |
165 | void Write64(const wxLongLong *buffer, size_t size); | |
166 | #endif | |
167 | #if wxUSE_LONGLONG | |
168 | void WriteLL(const wxULongLong *buffer, size_t size); | |
169 | void WriteLL(const wxLongLong *buffer, size_t size); | |
170 | #endif | |
171 | void Write32(const wxUint32 *buffer, size_t size); | |
172 | void Write16(const wxUint16 *buffer, size_t size); | |
173 | void Write8(const wxUint8 *buffer, size_t size); | |
174 | void WriteDouble(const double *buffer, size_t size); | |
175 | void WriteFloat(const float *buffer, size_t size); | |
176 | ||
177 | wxDataOutputStream& operator<<(const wxString& string); | |
178 | wxDataOutputStream& operator<<(wxInt8 c); | |
179 | wxDataOutputStream& operator<<(wxInt16 i); | |
180 | wxDataOutputStream& operator<<(wxInt32 i); | |
181 | wxDataOutputStream& operator<<(wxUint8 c); | |
182 | wxDataOutputStream& operator<<(wxUint16 i); | |
183 | wxDataOutputStream& operator<<(wxUint32 i); | |
184 | #if wxHAS_INT64 | |
185 | wxDataOutputStream& operator<<(wxUint64 i); | |
186 | wxDataOutputStream& operator<<(wxInt64 i); | |
187 | #endif | |
188 | #if defined(wxLongLong_t) && wxUSE_LONGLONG | |
189 | wxDataOutputStream& operator<<(const wxULongLong &i); | |
190 | wxDataOutputStream& operator<<(const wxLongLong &i); | |
191 | #endif | |
192 | wxDataOutputStream& operator<<(double d); | |
193 | wxDataOutputStream& operator<<(float f); | |
194 | ||
195 | protected: | |
196 | wxOutputStream *m_output; | |
197 | ||
198 | wxDECLARE_NO_COPY_CLASS(wxDataOutputStream); | |
199 | }; | |
200 | ||
201 | #endif | |
202 | // wxUSE_STREAMS | |
203 | ||
204 | #endif | |
205 | // _WX_DATSTREAM_H_ |