]> git.saurik.com Git - wxWidgets.git/blame - src/common/datstrm.cpp
wxImage now uses GTK 1.2's fast rendering code if possible
[wxWidgets.git] / src / common / datstrm.cpp
CommitLineData
cf447356
GL
1/////////////////////////////////////////////////////////////////////////////
2// Name: datstrm.cpp
3// Purpose: Data stream classes
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 28/06/98
7// RCS-ID: $Id$
8// Copyright: (c) Guilhem Lavaux
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "datstrm.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/defs.h"
25#endif
26
27#include "wx/datstrm.h"
3cacae09 28
f4ada568
GL
29// ---------------------------------------------------------------------------
30// wxDataInputStream
31// ---------------------------------------------------------------------------
32
3d4c6a21
GL
33wxDataInputStream::wxDataInputStream(wxInputStream& s)
34 : wxFilterInputStream(s)
cf447356 35{
cf447356
GL
36}
37
3d4c6a21 38wxDataInputStream::~wxDataInputStream()
cf447356 39{
cf447356
GL
40}
41
3d4c6a21 42unsigned long wxDataInputStream::Read32()
cf447356
GL
43{
44 char buf[4];
45
3d4c6a21 46 Read(buf, 4);
cf447356
GL
47
48 return (unsigned long)buf[0] |
49 ((unsigned long)buf[1] << 8) |
50 ((unsigned long)buf[2] << 16) |
51 ((unsigned long)buf[3] << 24);
52}
53
3d4c6a21 54unsigned short wxDataInputStream::Read16()
cf447356
GL
55{
56 char buf[2];
57
3d4c6a21 58 Read(buf, 2);
cf447356
GL
59
60 return (unsigned short)buf[0] |
61 ((unsigned short)buf[1] << 8);
62}
63
3d4c6a21 64unsigned char wxDataInputStream::Read8()
cf447356
GL
65{
66 char buf;
67
3d4c6a21 68 Read(&buf, 1);
cf447356
GL
69 return (unsigned char)buf;
70}
71
5260b1c5
JS
72// Must be at global scope for VC++ 5
73extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes);
74
3d4c6a21 75double wxDataInputStream::ReadDouble()
cf447356 76{
47d67540 77#if wxUSE_APPLE_IEEE
cf447356
GL
78 char buf[10];
79
3d4c6a21 80 Read(buf, 10);
cf447356
GL
81 return ConvertFromIeeeExtended((unsigned char *)buf);
82#else
83 return 0.0;
84#endif
85}
86
3d4c6a21 87wxString wxDataInputStream::ReadLine()
cf447356 88{
6d44bf31
GL
89 char c, last_endl = 0;
90 bool end_line = FALSE;
91 wxString line;
92
93 while (!end_line) {
94 c = GetC();
95 switch (c) {
96 case '\n':
97 end_line = TRUE;
98 break;
99 case '\r':
100 last_endl = '\r';
101 break;
102 default:
103 if (last_endl == '\r') {
104 end_line = TRUE;
105 InputStreamBuffer()->WriteBack(c);
106 break;
107 }
108 line += c;
109 break;
110 }
111 }
112 return line;
cf447356
GL
113}
114
3d4c6a21 115wxString wxDataInputStream::ReadString()
eafc087e
GL
116{
117 wxString wx_string;
118 char *string;
119 unsigned long len;
120
eafc087e
GL
121 len = Read32();
122 string = new char[len+1];
123
3d4c6a21 124 Read(string, len);
eafc087e
GL
125
126 string[len] = 0;
127 wx_string = string;
128 delete string;
129
a3622daa 130 return wx_string;
eafc087e
GL
131}
132
f4ada568
GL
133// ---------------------------------------------------------------------------
134// wxDataOutputStream
135// ---------------------------------------------------------------------------
136
3d4c6a21
GL
137wxDataOutputStream::wxDataOutputStream(wxOutputStream& s)
138 : wxFilterOutputStream(s)
139{
140}
141
f0b07807
KB
142wxDataOutputStream::~wxDataOutputStream()
143{
144}
145
3d4c6a21 146void wxDataOutputStream::Write32(unsigned long i)
cf447356
GL
147{
148 char buf[4];
149
cf447356
GL
150 buf[0] = i & 0xff;
151 buf[1] = (i >> 8) & 0xff;
152 buf[2] = (i >> 16) & 0xff;
153 buf[3] = (i >> 24) & 0xff;
3d4c6a21 154 Write(buf, 4);
cf447356
GL
155}
156
3d4c6a21 157void wxDataOutputStream::Write16(unsigned short i)
cf447356
GL
158{
159 char buf[2];
160
cf447356
GL
161 buf[0] = i & 0xff;
162 buf[1] = (i >> 8) & 0xff;
3d4c6a21 163 Write(buf, 2);
cf447356
GL
164}
165
3d4c6a21 166void wxDataOutputStream::Write8(unsigned char i)
cf447356 167{
3d4c6a21 168 Write(&i, 1);
cf447356
GL
169}
170
3d4c6a21 171void wxDataOutputStream::WriteLine(const wxString& line)
cf447356 172{
2049ba38 173#ifdef __WXMSW__
84fff0b3 174 wxString tmp_string = line + _T("\r\n");
eafc087e 175#else
84fff0b3 176 wxString tmp_string = line + _T('\n');
eafc087e
GL
177#endif
178
84fff0b3 179 Write((const wxChar *) tmp_string, tmp_string.Length()*sizeof(wxChar));
eafc087e
GL
180}
181
3d4c6a21 182void wxDataOutputStream::WriteString(const wxString& string)
eafc087e 183{
debe6624 184 Write32(string.Length());
84fff0b3 185 Write((const wxChar *) string, string.Length()*sizeof(wxChar));
cf447356
GL
186}
187
5260b1c5
JS
188// Must be at global scope for VC++ 5
189extern "C" void ConvertToIeeeExtended(double num, unsigned char *bytes);
190
3d4c6a21 191void wxDataOutputStream::WriteDouble(double d)
cf447356 192{
cf447356
GL
193 char buf[10];
194
47d67540 195#if wxUSE_APPLE_IEEE
cf447356 196 ConvertToIeeeExtended(d, (unsigned char *)buf);
0e338ff9 197#else
631f1bfe 198# pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!"
0e338ff9
KB
199 buf[0] = '\0';
200#endif
3d4c6a21 201 Write(buf, 10);
cf447356 202}