]>
Commit | Line | Data |
---|---|---|
cf447356 | 1 | ///////////////////////////////////////////////////////////////////////////// |
40319aa0 | 2 | // Name: src/common/datstrm.cpp |
cf447356 GL |
3 | // Purpose: Data stream classes |
4 | // Author: Guilhem Lavaux | |
53663be8 | 5 | // Modified by: Mickael Gilabert |
cf447356 GL |
6 | // Created: 28/06/98 |
7 | // RCS-ID: $Id$ | |
13111b2a | 8 | // Copyright: (c) Guilhem Lavaux |
68379eaf | 9 | // Licence: wxWindows licence |
cf447356 GL |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
cf447356 GL |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
ce4169a4 | 16 | #pragma hdrstop |
cf447356 GL |
17 | #endif |
18 | ||
ce4169a4 RR |
19 | #if wxUSE_STREAMS |
20 | ||
cf447356 | 21 | #include "wx/datstrm.h" |
18680f86 WS |
22 | |
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/math.h" | |
25 | #endif //WX_PRECOMP | |
3cacae09 | 26 | |
f4ada568 GL |
27 | // --------------------------------------------------------------------------- |
28 | // wxDataInputStream | |
29 | // --------------------------------------------------------------------------- | |
30 | ||
a99acbb0 | 31 | #if wxUSE_UNICODE |
830f8f11 | 32 | wxDataInputStream::wxDataInputStream(wxInputStream& s, const wxMBConv& conv) |
d36c9347 | 33 | : m_input(&s), m_be_order(false), m_conv(conv.Clone()) |
a99acbb0 | 34 | #else |
3d4c6a21 | 35 | wxDataInputStream::wxDataInputStream(wxInputStream& s) |
68379eaf | 36 | : m_input(&s), m_be_order(false) |
a99acbb0 | 37 | #endif |
cf447356 | 38 | { |
cf447356 GL |
39 | } |
40 | ||
d36c9347 VZ |
41 | wxDataInputStream::~wxDataInputStream() |
42 | { | |
43 | #if wxUSE_UNICODE | |
44 | delete m_conv; | |
45 | #endif // wxUSE_UNICODE | |
46 | } | |
47 | ||
10c2f98a RR |
48 | #if wxUSE_UNICODE |
49 | void wxDataInputStream::SetConv( const wxMBConv &conv ) | |
50 | { | |
51 | delete m_conv; | |
52 | m_conv = conv.Clone(); | |
53 | } | |
54 | #endif | |
55 | ||
216a72f3 | 56 | #if wxHAS_INT64 |
41b0a113 RL |
57 | wxUint64 wxDataInputStream::Read64() |
58 | { | |
216a72f3 VZ |
59 | wxUint64 tmp; |
60 | Read64(&tmp, 1); | |
61 | return tmp; | |
41b0a113 | 62 | } |
216a72f3 | 63 | #endif // wxHAS_INT64 |
41b0a113 | 64 | |
7b8bd818 | 65 | wxUint32 wxDataInputStream::Read32() |
cf447356 | 66 | { |
5a96d2f4 | 67 | wxUint32 i32; |
cf447356 | 68 | |
5a96d2f4 | 69 | m_input->Read(&i32, 4); |
cf447356 | 70 | |
5a96d2f4 GL |
71 | if (m_be_order) |
72 | return wxUINT32_SWAP_ON_LE(i32); | |
73 | else | |
74 | return wxUINT32_SWAP_ON_BE(i32); | |
cf447356 GL |
75 | } |
76 | ||
7b8bd818 | 77 | wxUint16 wxDataInputStream::Read16() |
cf447356 | 78 | { |
5a96d2f4 | 79 | wxUint16 i16; |
cf447356 | 80 | |
5a96d2f4 | 81 | m_input->Read(&i16, 2); |
cf447356 | 82 | |
5a96d2f4 GL |
83 | if (m_be_order) |
84 | return wxUINT16_SWAP_ON_LE(i16); | |
85 | else | |
86 | return wxUINT16_SWAP_ON_BE(i16); | |
cf447356 GL |
87 | } |
88 | ||
7b8bd818 | 89 | wxUint8 wxDataInputStream::Read8() |
cf447356 | 90 | { |
7b8bd818 | 91 | wxUint8 buf; |
cf447356 | 92 | |
5a96d2f4 | 93 | m_input->Read(&buf, 1); |
7b8bd818 | 94 | return (wxUint8)buf; |
cf447356 GL |
95 | } |
96 | ||
3d4c6a21 | 97 | double wxDataInputStream::ReadDouble() |
cf447356 | 98 | { |
47d67540 | 99 | #if wxUSE_APPLE_IEEE |
cf447356 GL |
100 | char buf[10]; |
101 | ||
fae05df5 | 102 | m_input->Read(buf, 10); |
225dfbc5 | 103 | return wxConvertFromIeeeExtended((const wxInt8 *)buf); |
cf447356 GL |
104 | #else |
105 | return 0.0; | |
106 | #endif | |
107 | } | |
108 | ||
3d4c6a21 | 109 | wxString wxDataInputStream::ReadString() |
eafc087e | 110 | { |
0094bc4c | 111 | wxString ret; |
eafc087e | 112 | |
0094bc4c VZ |
113 | const size_t len = Read32(); |
114 | if ( len > 0 ) | |
115 | { | |
2ae47e3f | 116 | #if wxUSE_UNICODE |
935693c4 | 117 | wxCharBuffer tmp(len); |
0094bc4c VZ |
118 | if ( tmp ) |
119 | { | |
120 | m_input->Read(tmp.data(), len); | |
0094bc4c VZ |
121 | ret = m_conv->cMB2WX(tmp.data()); |
122 | } | |
2ae47e3f | 123 | #else |
0094bc4c VZ |
124 | wxStringBuffer buf(ret, len); |
125 | if ( buf ) | |
126 | m_input->Read(buf, len); | |
2ae47e3f | 127 | #endif |
0094bc4c VZ |
128 | } |
129 | ||
2b5f62a0 | 130 | return ret; |
eafc087e | 131 | } |
13111b2a | 132 | |
216a72f3 VZ |
133 | #if wxUSE_LONGLONG |
134 | ||
135 | template <class T> | |
136 | static | |
137 | void DoReadLL(T *buffer, size_t size, wxInputStream *input, bool be_order) | |
53663be8 | 138 | { |
216a72f3 VZ |
139 | typedef T DataType; |
140 | unsigned char *pchBuffer = new unsigned char[size * 8]; | |
141 | // TODO: Check for overflow when size is of type uint and is > than 512m | |
142 | input->Read(pchBuffer, size * 8); | |
143 | size_t idx_base = 0; | |
144 | if ( be_order ) | |
145 | { | |
146 | for ( size_t uiIndex = 0; uiIndex != size; ++uiIndex ) | |
147 | { | |
148 | buffer[uiIndex] = 0l; | |
149 | for ( unsigned ui = 0; ui != 8; ++ui ) | |
150 | { | |
151 | buffer[uiIndex] = buffer[uiIndex] * 256l + | |
152 | DataType((unsigned long) pchBuffer[idx_base + ui]); | |
153 | } | |
154 | ||
155 | idx_base += 8; | |
156 | } | |
157 | } | |
158 | else // little endian | |
159 | { | |
160 | for ( size_t uiIndex=0; uiIndex!=size; ++uiIndex ) | |
161 | { | |
162 | buffer[uiIndex] = 0l; | |
163 | for ( unsigned ui=0; ui!=8; ++ui ) | |
164 | buffer[uiIndex] = buffer[uiIndex] * 256l + | |
165 | DataType((unsigned long) pchBuffer[idx_base + 7 - ui]); | |
166 | idx_base += 8; | |
167 | } | |
168 | } | |
169 | delete[] pchBuffer; | |
170 | } | |
53663be8 | 171 | |
216a72f3 VZ |
172 | template <class T> |
173 | static void DoWriteLL(const T *buffer, size_t size, wxOutputStream *output, bool be_order) | |
174 | { | |
175 | typedef T DataType; | |
176 | unsigned char *pchBuffer = new unsigned char[size * 8]; | |
177 | size_t idx_base = 0; | |
178 | if ( be_order ) | |
179 | { | |
180 | for ( size_t uiIndex = 0; uiIndex != size; ++uiIndex ) | |
181 | { | |
182 | DataType i64 = buffer[uiIndex]; | |
183 | for ( unsigned ui = 0; ui != 8; ++ui ) | |
184 | { | |
185 | pchBuffer[idx_base + 7 - ui] = | |
186 | (unsigned char) (i64.GetLo() & 255l); | |
187 | i64 >>= 8l; | |
188 | } | |
189 | ||
190 | idx_base += 8; | |
191 | } | |
192 | } | |
193 | else // little endian | |
194 | { | |
195 | for ( size_t uiIndex=0; uiIndex != size; ++uiIndex ) | |
196 | { | |
197 | DataType i64 = buffer[uiIndex]; | |
198 | for (unsigned ui=0; ui!=8; ++ui) | |
199 | { | |
200 | pchBuffer[idx_base + ui] = | |
201 | (unsigned char) (i64.GetLo() & 255l); | |
202 | i64 >>= 8l; | |
203 | } | |
204 | ||
205 | idx_base += 8; | |
206 | } | |
207 | } | |
208 | ||
209 | // TODO: Check for overflow when size is of type uint and is > than 512m | |
210 | output->Write(pchBuffer, size * 8); | |
211 | delete[] pchBuffer; | |
212 | } | |
213 | ||
214 | #endif // wxUSE_LONGLONG | |
215 | ||
216 | #ifdef wxLongLong_t | |
217 | ||
218 | template <class T> | |
219 | static | |
220 | void DoReadI64(T *buffer, size_t size, wxInputStream *input, bool be_order) | |
221 | { | |
222 | typedef T DataType; | |
223 | unsigned char *pchBuffer = (unsigned char*) buffer; | |
224 | // TODO: Check for overflow when size is of type uint and is > than 512m | |
225 | input->Read(pchBuffer, size * 8); | |
226 | if ( be_order ) | |
227 | { | |
228 | for ( wxUint32 i = 0; i < size; i++ ) | |
229 | { | |
230 | DataType v = wxUINT64_SWAP_ON_LE(*buffer); | |
231 | *(buffer++) = v; | |
232 | } | |
233 | } | |
234 | else // little endian | |
235 | { | |
236 | for ( wxUint32 i=0; i<size; i++ ) | |
237 | { | |
238 | DataType v = wxUINT64_SWAP_ON_BE(*buffer); | |
239 | *(buffer++) = v; | |
240 | } | |
241 | } | |
242 | } | |
243 | ||
244 | template <class T> | |
245 | static | |
246 | void DoWriteI64(const T *buffer, size_t size, wxOutputStream *output, bool be_order) | |
247 | { | |
248 | typedef T DataType; | |
249 | if ( be_order ) | |
53663be8 | 250 | { |
216a72f3 | 251 | for ( size_t i = 0; i < size; i++ ) |
53663be8 | 252 | { |
216a72f3 VZ |
253 | DataType i64 = wxUINT64_SWAP_ON_LE(*buffer); |
254 | buffer++; | |
255 | output->Write(&i64, 8); | |
53663be8 VZ |
256 | } |
257 | } | |
216a72f3 | 258 | else // little endian |
53663be8 | 259 | { |
216a72f3 | 260 | for ( size_t i=0; i < size; i++ ) |
53663be8 | 261 | { |
216a72f3 VZ |
262 | DataType i64 = wxUINT64_SWAP_ON_BE(*buffer); |
263 | buffer++; | |
264 | output->Write(&i64, 8); | |
53663be8 VZ |
265 | } |
266 | } | |
267 | } | |
268 | ||
216a72f3 VZ |
269 | #endif // wxLongLong_t |
270 | ||
271 | ||
272 | #if wxHAS_INT64 | |
273 | void wxDataInputStream::Read64(wxUint64 *buffer, size_t size) | |
274 | { | |
275 | #ifndef wxLongLong_t | |
276 | DoReadLL(buffer, size, m_input, m_be_order); | |
277 | #else | |
278 | DoReadI64(buffer, size, m_input, m_be_order); | |
279 | #endif | |
280 | } | |
281 | ||
282 | void wxDataInputStream::Read64(wxInt64 *buffer, size_t size) | |
283 | { | |
284 | #ifndef wxLongLong_t | |
285 | DoReadLL(buffer, size, m_input, m_be_order); | |
286 | #else | |
287 | DoReadI64(buffer, size, m_input, m_be_order); | |
288 | #endif | |
289 | } | |
290 | #endif // wxHAS_INT64 | |
291 | ||
292 | #if defined(wxLongLong_t) && wxUSE_LONGLONG | |
293 | void wxDataInputStream::Read64(wxULongLong *buffer, size_t size) | |
294 | { | |
295 | DoReadLL(buffer, size, m_input, m_be_order); | |
296 | } | |
297 | ||
298 | void wxDataInputStream::Read64(wxLongLong *buffer, size_t size) | |
299 | { | |
300 | DoReadLL(buffer, size, m_input, m_be_order); | |
301 | } | |
302 | #endif // wxLongLong_t | |
303 | ||
304 | #if wxUSE_LONGLONG | |
305 | void wxDataInputStream::ReadLL(wxULongLong *buffer, size_t size) | |
306 | { | |
307 | DoReadLL(buffer, size, m_input, m_be_order); | |
308 | } | |
309 | ||
310 | void wxDataInputStream::ReadLL(wxLongLong *buffer, size_t size) | |
311 | { | |
312 | DoReadLL(buffer, size, m_input, m_be_order); | |
313 | } | |
314 | ||
315 | wxLongLong wxDataInputStream::ReadLL(void) | |
316 | { | |
317 | wxLongLong ll; | |
40319aa0 | 318 | DoReadLL(&ll, (size_t)1, m_input, m_be_order); |
216a72f3 VZ |
319 | return ll; |
320 | } | |
321 | #endif // wxUSE_LONGLONG | |
322 | ||
53663be8 VZ |
323 | void wxDataInputStream::Read32(wxUint32 *buffer, size_t size) |
324 | { | |
7448de8d | 325 | m_input->Read(buffer, size * 4); |
53663be8 | 326 | |
7448de8d | 327 | if (m_be_order) |
53663be8 | 328 | { |
7448de8d WS |
329 | for (wxUint32 i=0; i<size; i++) |
330 | { | |
331 | wxUint32 v = wxUINT32_SWAP_ON_LE(*buffer); | |
332 | *(buffer++) = v; | |
333 | } | |
53663be8 | 334 | } |
7448de8d | 335 | else |
53663be8 | 336 | { |
7448de8d WS |
337 | for (wxUint32 i=0; i<size; i++) |
338 | { | |
339 | wxUint32 v = wxUINT32_SWAP_ON_BE(*buffer); | |
340 | *(buffer++) = v; | |
341 | } | |
53663be8 | 342 | } |
53663be8 VZ |
343 | } |
344 | ||
345 | void wxDataInputStream::Read16(wxUint16 *buffer, size_t size) | |
346 | { | |
347 | m_input->Read(buffer, size * 2); | |
348 | ||
349 | if (m_be_order) | |
350 | { | |
351 | for (wxUint32 i=0; i<size; i++) | |
352 | { | |
353 | wxUint16 v = wxUINT16_SWAP_ON_LE(*buffer); | |
354 | *(buffer++) = v; | |
355 | } | |
356 | } | |
357 | else | |
358 | { | |
359 | for (wxUint32 i=0; i<size; i++) | |
360 | { | |
361 | wxUint16 v = wxUINT16_SWAP_ON_BE(*buffer); | |
362 | *(buffer++) = v; | |
363 | } | |
364 | } | |
365 | } | |
366 | ||
367 | void wxDataInputStream::Read8(wxUint8 *buffer, size_t size) | |
368 | { | |
369 | m_input->Read(buffer, size); | |
370 | } | |
371 | ||
372 | void wxDataInputStream::ReadDouble(double *buffer, size_t size) | |
373 | { | |
374 | for (wxUint32 i=0; i<size; i++) | |
375 | { | |
376 | *(buffer++) = ReadDouble(); | |
377 | } | |
378 | } | |
379 | ||
fae05df5 GL |
380 | wxDataInputStream& wxDataInputStream::operator>>(wxString& s) |
381 | { | |
382 | s = ReadString(); | |
383 | return *this; | |
384 | } | |
385 | ||
386 | wxDataInputStream& wxDataInputStream::operator>>(wxInt8& c) | |
387 | { | |
388 | c = (wxInt8)Read8(); | |
389 | return *this; | |
390 | } | |
391 | ||
392 | wxDataInputStream& wxDataInputStream::operator>>(wxInt16& i) | |
393 | { | |
394 | i = (wxInt16)Read16(); | |
395 | return *this; | |
396 | } | |
397 | ||
398 | wxDataInputStream& wxDataInputStream::operator>>(wxInt32& i) | |
399 | { | |
400 | i = (wxInt32)Read32(); | |
401 | return *this; | |
402 | } | |
403 | ||
404 | wxDataInputStream& wxDataInputStream::operator>>(wxUint8& c) | |
405 | { | |
406 | c = Read8(); | |
407 | return *this; | |
408 | } | |
409 | ||
410 | wxDataInputStream& wxDataInputStream::operator>>(wxUint16& i) | |
411 | { | |
412 | i = Read16(); | |
413 | return *this; | |
414 | } | |
415 | ||
416 | wxDataInputStream& wxDataInputStream::operator>>(wxUint32& i) | |
417 | { | |
418 | i = Read32(); | |
419 | return *this; | |
420 | } | |
421 | ||
216a72f3 | 422 | #if wxHAS_INT64 |
41b0a113 RL |
423 | wxDataInputStream& wxDataInputStream::operator>>(wxUint64& i) |
424 | { | |
425 | i = Read64(); | |
426 | return *this; | |
427 | } | |
428 | ||
216a72f3 VZ |
429 | wxDataInputStream& wxDataInputStream::operator>>(wxInt64& i) |
430 | { | |
431 | i = Read64(); | |
432 | return *this; | |
433 | } | |
434 | #endif // wxHAS_INT64 | |
435 | ||
436 | #if defined(wxLongLong_t) && wxUSE_LONGLONG | |
437 | wxDataInputStream& wxDataInputStream::operator>>(wxULongLong& i) | |
438 | { | |
439 | i = ReadLL(); | |
440 | return *this; | |
441 | } | |
442 | ||
443 | wxDataInputStream& wxDataInputStream::operator>>(wxLongLong& i) | |
444 | { | |
445 | i = ReadLL(); | |
446 | return *this; | |
447 | } | |
448 | #endif // wxLongLong_t | |
449 | ||
fae05df5 GL |
450 | wxDataInputStream& wxDataInputStream::operator>>(double& i) |
451 | { | |
452 | i = ReadDouble(); | |
453 | return *this; | |
454 | } | |
455 | ||
456 | wxDataInputStream& wxDataInputStream::operator>>(float& f) | |
457 | { | |
458 | f = (float)ReadDouble(); | |
459 | return *this; | |
460 | } | |
eafc087e | 461 | |
f4ada568 GL |
462 | // --------------------------------------------------------------------------- |
463 | // wxDataOutputStream | |
464 | // --------------------------------------------------------------------------- | |
465 | ||
a99acbb0 | 466 | #if wxUSE_UNICODE |
830f8f11 | 467 | wxDataOutputStream::wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv) |
d36c9347 | 468 | : m_output(&s), m_be_order(false), m_conv(conv.Clone()) |
a99acbb0 | 469 | #else |
3d4c6a21 | 470 | wxDataOutputStream::wxDataOutputStream(wxOutputStream& s) |
68379eaf | 471 | : m_output(&s), m_be_order(false) |
a99acbb0 | 472 | #endif |
3d4c6a21 GL |
473 | { |
474 | } | |
475 | ||
d36c9347 VZ |
476 | wxDataOutputStream::~wxDataOutputStream() |
477 | { | |
478 | #if wxUSE_UNICODE | |
479 | delete m_conv; | |
480 | #endif // wxUSE_UNICODE | |
481 | } | |
482 | ||
10c2f98a RR |
483 | #if wxUSE_UNICODE |
484 | void wxDataOutputStream::SetConv( const wxMBConv &conv ) | |
485 | { | |
486 | delete m_conv; | |
487 | m_conv = conv.Clone(); | |
488 | } | |
489 | #endif | |
490 | ||
216a72f3 | 491 | #if wxHAS_INT64 |
41b0a113 RL |
492 | void wxDataOutputStream::Write64(wxUint64 i) |
493 | { | |
216a72f3 VZ |
494 | Write64(&i, 1); |
495 | } | |
41b0a113 | 496 | |
216a72f3 VZ |
497 | void wxDataOutputStream::Write64(wxInt64 i) |
498 | { | |
499 | Write64(&i, 1); | |
41b0a113 | 500 | } |
216a72f3 | 501 | #endif // wxHAS_INT64 |
41b0a113 | 502 | |
7b8bd818 | 503 | void wxDataOutputStream::Write32(wxUint32 i) |
cf447356 | 504 | { |
5a96d2f4 | 505 | wxUint32 i32; |
cf447356 | 506 | |
5a96d2f4 GL |
507 | if (m_be_order) |
508 | i32 = wxUINT32_SWAP_ON_LE(i); | |
509 | else | |
510 | i32 = wxUINT32_SWAP_ON_BE(i); | |
511 | m_output->Write(&i32, 4); | |
cf447356 GL |
512 | } |
513 | ||
7b8bd818 | 514 | void wxDataOutputStream::Write16(wxUint16 i) |
cf447356 | 515 | { |
5a96d2f4 | 516 | wxUint16 i16; |
cf447356 | 517 | |
5a96d2f4 GL |
518 | if (m_be_order) |
519 | i16 = wxUINT16_SWAP_ON_LE(i); | |
520 | else | |
521 | i16 = wxUINT16_SWAP_ON_BE(i); | |
522 | ||
523 | m_output->Write(&i16, 2); | |
cf447356 GL |
524 | } |
525 | ||
7b8bd818 | 526 | void wxDataOutputStream::Write8(wxUint8 i) |
cf447356 | 527 | { |
fae05df5 | 528 | m_output->Write(&i, 1); |
cf447356 GL |
529 | } |
530 | ||
3d4c6a21 | 531 | void wxDataOutputStream::WriteString(const wxString& string) |
eafc087e | 532 | { |
a99acbb0 | 533 | #if wxUSE_UNICODE |
d36c9347 | 534 | const wxWX2MBbuf buf = string.mb_str(*m_conv); |
a99acbb0 | 535 | #else |
c980c992 | 536 | const wxWX2MBbuf buf = string.mb_str(); |
a99acbb0 VS |
537 | #endif |
538 | size_t len = strlen(buf); | |
539 | Write32(len); | |
540 | if (len > 0) | |
541 | m_output->Write(buf, len); | |
cf447356 GL |
542 | } |
543 | ||
3d4c6a21 | 544 | void wxDataOutputStream::WriteDouble(double d) |
cf447356 | 545 | { |
cf447356 GL |
546 | char buf[10]; |
547 | ||
47d67540 | 548 | #if wxUSE_APPLE_IEEE |
225dfbc5 | 549 | wxConvertToIeeeExtended(d, (wxInt8 *)buf); |
0e338ff9 | 550 | #else |
36e5a9a7 | 551 | wxUnusedVar(d); |
c5ceb215 | 552 | #if !defined(__VMS__) && !defined(__GNUG__) |
7d58a1bd VZ |
553 | #ifdef _MSC_VER |
554 | # pragma message("wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!") | |
555 | #else | |
338dd992 | 556 | # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!" |
7d58a1bd | 557 | #endif |
338dd992 JJ |
558 | #endif |
559 | buf[0] = '\0'; | |
0e338ff9 | 560 | #endif |
fae05df5 GL |
561 | m_output->Write(buf, 10); |
562 | } | |
563 | ||
216a72f3 | 564 | #if wxHAS_INT64 |
53663be8 VZ |
565 | void wxDataOutputStream::Write64(const wxUint64 *buffer, size_t size) |
566 | { | |
216a72f3 VZ |
567 | #ifndef wxLongLong_t |
568 | DoWriteLL(buffer, size, m_output, m_be_order); | |
569 | #else | |
570 | DoWriteI64(buffer, size, m_output, m_be_order); | |
571 | #endif | |
572 | } | |
573 | ||
574 | void wxDataOutputStream::Write64(const wxInt64 *buffer, size_t size) | |
575 | { | |
576 | #ifndef wxLongLong_t | |
577 | DoWriteLL(buffer, size, m_output, m_be_order); | |
578 | #else | |
579 | DoWriteI64(buffer, size, m_output, m_be_order); | |
580 | #endif | |
53663be8 | 581 | } |
216a72f3 VZ |
582 | #endif // wxHAS_INT64 |
583 | ||
584 | #if defined(wxLongLong_t) && wxUSE_LONGLONG | |
585 | void wxDataOutputStream::Write64(const wxULongLong *buffer, size_t size) | |
586 | { | |
587 | DoWriteLL(buffer, size, m_output, m_be_order); | |
588 | } | |
589 | ||
590 | void wxDataOutputStream::Write64(const wxLongLong *buffer, size_t size) | |
591 | { | |
592 | DoWriteLL(buffer, size, m_output, m_be_order); | |
593 | } | |
594 | #endif // wxLongLong_t | |
595 | ||
596 | #if wxUSE_LONGLONG | |
597 | void wxDataOutputStream::WriteLL(const wxULongLong *buffer, size_t size) | |
598 | { | |
599 | DoWriteLL(buffer, size, m_output, m_be_order); | |
600 | } | |
601 | ||
602 | void wxDataOutputStream::WriteLL(const wxLongLong *buffer, size_t size) | |
603 | { | |
604 | DoWriteLL(buffer, size, m_output, m_be_order); | |
605 | } | |
606 | ||
607 | void wxDataOutputStream::WriteLL(const wxLongLong &ll) | |
608 | { | |
609 | WriteLL(&ll, 1); | |
610 | } | |
611 | ||
612 | void wxDataOutputStream::WriteLL(const wxULongLong &ll) | |
613 | { | |
614 | WriteLL(&ll, 1); | |
615 | } | |
616 | #endif // wxUSE_LONGLONG | |
53663be8 VZ |
617 | |
618 | void wxDataOutputStream::Write32(const wxUint32 *buffer, size_t size) | |
619 | { | |
620 | if (m_be_order) | |
621 | { | |
622 | for (wxUint32 i=0; i<size ;i++) | |
623 | { | |
624 | wxUint32 i32 = wxUINT32_SWAP_ON_LE(*buffer); | |
625 | buffer++; | |
626 | m_output->Write(&i32, 4); | |
627 | } | |
628 | } | |
629 | else | |
630 | { | |
631 | for (wxUint32 i=0; i<size ;i++) | |
632 | { | |
633 | wxUint32 i32 = wxUINT32_SWAP_ON_BE(*buffer); | |
634 | buffer++; | |
635 | m_output->Write(&i32, 4); | |
636 | } | |
637 | } | |
638 | } | |
639 | ||
640 | void wxDataOutputStream::Write16(const wxUint16 *buffer, size_t size) | |
641 | { | |
642 | if (m_be_order) | |
643 | { | |
644 | for (wxUint32 i=0; i<size ;i++) | |
645 | { | |
646 | wxUint16 i16 = wxUINT16_SWAP_ON_LE(*buffer); | |
647 | buffer++; | |
648 | m_output->Write(&i16, 2); | |
649 | } | |
650 | } | |
651 | else | |
652 | { | |
653 | for (wxUint32 i=0; i<size ;i++) | |
654 | { | |
655 | wxUint16 i16 = wxUINT16_SWAP_ON_BE(*buffer); | |
656 | buffer++; | |
657 | m_output->Write(&i16, 2); | |
658 | } | |
659 | } | |
660 | } | |
661 | ||
662 | void wxDataOutputStream::Write8(const wxUint8 *buffer, size_t size) | |
663 | { | |
664 | m_output->Write(buffer, size); | |
665 | } | |
666 | ||
667 | void wxDataOutputStream::WriteDouble(const double *buffer, size_t size) | |
668 | { | |
669 | for (wxUint32 i=0; i<size; i++) | |
670 | { | |
671 | WriteDouble(*(buffer++)); | |
672 | } | |
673 | } | |
674 | ||
38caaa61 | 675 | wxDataOutputStream& wxDataOutputStream::operator<<(const wxString& string) |
fae05df5 GL |
676 | { |
677 | WriteString(string); | |
678 | return *this; | |
679 | } | |
680 | ||
681 | wxDataOutputStream& wxDataOutputStream::operator<<(wxInt8 c) | |
682 | { | |
683 | Write8((wxUint8)c); | |
684 | return *this; | |
685 | } | |
686 | ||
687 | wxDataOutputStream& wxDataOutputStream::operator<<(wxInt16 i) | |
688 | { | |
689 | Write16((wxUint16)i); | |
690 | return *this; | |
691 | } | |
692 | ||
693 | wxDataOutputStream& wxDataOutputStream::operator<<(wxInt32 i) | |
694 | { | |
695 | Write32((wxUint32)i); | |
696 | return *this; | |
697 | } | |
698 | ||
699 | wxDataOutputStream& wxDataOutputStream::operator<<(wxUint8 c) | |
700 | { | |
701 | Write8(c); | |
702 | return *this; | |
703 | } | |
704 | ||
705 | wxDataOutputStream& wxDataOutputStream::operator<<(wxUint16 i) | |
706 | { | |
707 | Write16(i); | |
708 | return *this; | |
709 | } | |
710 | ||
711 | wxDataOutputStream& wxDataOutputStream::operator<<(wxUint32 i) | |
712 | { | |
713 | Write32(i); | |
714 | return *this; | |
715 | } | |
716 | ||
216a72f3 | 717 | #if wxHAS_INT64 |
41b0a113 RL |
718 | wxDataOutputStream& wxDataOutputStream::operator<<(wxUint64 i) |
719 | { | |
720 | Write64(i); | |
721 | return *this; | |
722 | } | |
723 | ||
216a72f3 VZ |
724 | wxDataOutputStream& wxDataOutputStream::operator<<(wxInt64 i) |
725 | { | |
726 | Write64(i); | |
727 | return *this; | |
728 | } | |
729 | #endif // wxHAS_INT64 | |
730 | ||
731 | #if defined(wxLongLong_t) && wxUSE_LONGLONG | |
732 | wxDataOutputStream& wxDataOutputStream::operator<<(const wxULongLong &i) | |
733 | { | |
734 | WriteLL(i); | |
735 | return *this; | |
736 | } | |
737 | ||
738 | wxDataOutputStream& wxDataOutputStream::operator<<(const wxLongLong &i) | |
739 | { | |
740 | WriteLL(i); | |
741 | return *this; | |
742 | } | |
743 | #endif // wxLongLong_t | |
744 | ||
fae05df5 GL |
745 | wxDataOutputStream& wxDataOutputStream::operator<<(double f) |
746 | { | |
747 | WriteDouble(f); | |
748 | return *this; | |
749 | } | |
750 | ||
751 | wxDataOutputStream& wxDataOutputStream::operator<<(float f) | |
752 | { | |
753 | WriteDouble((double)f); | |
754 | return *this; | |
cf447356 | 755 | } |
ce4169a4 RR |
756 | |
757 | #endif | |
758 | // wxUSE_STREAMS |