]>
Commit | Line | Data |
---|---|---|
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" | |
28 | ||
c4e7c2aa | 29 | /* |
3cacae09 GL |
30 | #if !USE_SHARED_LIBRARY |
31 | IMPLEMENT_CLASS(wxDataInputStream, wxFilterInputStream) | |
32 | IMPLEMENT_CLASS(wxDataOutputStream, wxFilterOutputStream) | |
33 | #endif | |
c4e7c2aa | 34 | */ |
3cacae09 | 35 | |
3d4c6a21 GL |
36 | wxDataInputStream::wxDataInputStream(wxInputStream& s) |
37 | : wxFilterInputStream(s) | |
cf447356 | 38 | { |
cf447356 GL |
39 | } |
40 | ||
3d4c6a21 | 41 | wxDataInputStream::~wxDataInputStream() |
cf447356 | 42 | { |
cf447356 GL |
43 | } |
44 | ||
3d4c6a21 | 45 | unsigned long wxDataInputStream::Read32() |
cf447356 GL |
46 | { |
47 | char buf[4]; | |
48 | ||
3d4c6a21 | 49 | Read(buf, 4); |
cf447356 GL |
50 | |
51 | return (unsigned long)buf[0] | | |
52 | ((unsigned long)buf[1] << 8) | | |
53 | ((unsigned long)buf[2] << 16) | | |
54 | ((unsigned long)buf[3] << 24); | |
55 | } | |
56 | ||
3d4c6a21 | 57 | unsigned short wxDataInputStream::Read16() |
cf447356 GL |
58 | { |
59 | char buf[2]; | |
60 | ||
3d4c6a21 | 61 | Read(buf, 2); |
cf447356 GL |
62 | |
63 | return (unsigned short)buf[0] | | |
64 | ((unsigned short)buf[1] << 8); | |
65 | } | |
66 | ||
3d4c6a21 | 67 | unsigned char wxDataInputStream::Read8() |
cf447356 GL |
68 | { |
69 | char buf; | |
70 | ||
3d4c6a21 | 71 | Read(&buf, 1); |
cf447356 GL |
72 | return (unsigned char)buf; |
73 | } | |
74 | ||
5260b1c5 JS |
75 | // Must be at global scope for VC++ 5 |
76 | extern "C" double ConvertFromIeeeExtended(const unsigned char *bytes); | |
77 | ||
3d4c6a21 | 78 | double wxDataInputStream::ReadDouble() |
cf447356 | 79 | { |
cf447356 GL |
80 | #if USE_APPLE_IEEE |
81 | char buf[10]; | |
82 | ||
3d4c6a21 | 83 | Read(buf, 10); |
cf447356 GL |
84 | return ConvertFromIeeeExtended((unsigned char *)buf); |
85 | #else | |
86 | return 0.0; | |
87 | #endif | |
88 | } | |
89 | ||
3d4c6a21 | 90 | wxString wxDataInputStream::ReadLine() |
cf447356 GL |
91 | { |
92 | char i_strg[255]; | |
93 | ||
3d4c6a21 | 94 | // TODO: Implement ReadLine |
cf447356 GL |
95 | return i_strg; |
96 | } | |
97 | ||
3d4c6a21 | 98 | wxString wxDataInputStream::ReadString() |
eafc087e GL |
99 | { |
100 | wxString wx_string; | |
101 | char *string; | |
102 | unsigned long len; | |
103 | ||
eafc087e GL |
104 | len = Read32(); |
105 | string = new char[len+1]; | |
106 | ||
3d4c6a21 | 107 | Read(string, len); |
eafc087e GL |
108 | |
109 | string[len] = 0; | |
110 | wx_string = string; | |
111 | delete string; | |
112 | ||
113 | return wx_string; | |
114 | } | |
115 | ||
3d4c6a21 GL |
116 | wxDataOutputStream::wxDataOutputStream(wxOutputStream& s) |
117 | : wxFilterOutputStream(s) | |
118 | { | |
119 | } | |
120 | ||
f0b07807 KB |
121 | wxDataOutputStream::~wxDataOutputStream() |
122 | { | |
123 | } | |
124 | ||
3d4c6a21 | 125 | void wxDataOutputStream::Write32(unsigned long i) |
cf447356 GL |
126 | { |
127 | char buf[4]; | |
128 | ||
cf447356 GL |
129 | buf[0] = i & 0xff; |
130 | buf[1] = (i >> 8) & 0xff; | |
131 | buf[2] = (i >> 16) & 0xff; | |
132 | buf[3] = (i >> 24) & 0xff; | |
3d4c6a21 | 133 | Write(buf, 4); |
cf447356 GL |
134 | } |
135 | ||
3d4c6a21 | 136 | void wxDataOutputStream::Write16(unsigned short i) |
cf447356 GL |
137 | { |
138 | char buf[2]; | |
139 | ||
cf447356 GL |
140 | buf[0] = i & 0xff; |
141 | buf[1] = (i >> 8) & 0xff; | |
3d4c6a21 | 142 | Write(buf, 2); |
cf447356 GL |
143 | } |
144 | ||
3d4c6a21 | 145 | void wxDataOutputStream::Write8(unsigned char i) |
cf447356 | 146 | { |
3d4c6a21 | 147 | Write(&i, 1); |
cf447356 GL |
148 | } |
149 | ||
3d4c6a21 | 150 | void wxDataOutputStream::WriteLine(const wxString& line) |
cf447356 | 151 | { |
2049ba38 | 152 | #ifdef __WXMSW__ |
eafc087e GL |
153 | wxString tmp_string = line + "\r\n"; |
154 | #else | |
cf447356 | 155 | wxString tmp_string = line + '\n'; |
eafc087e GL |
156 | #endif |
157 | ||
3d4c6a21 | 158 | Write((const char *) tmp_string, tmp_string.Length()); |
eafc087e GL |
159 | } |
160 | ||
3d4c6a21 | 161 | void wxDataOutputStream::WriteString(const wxString& string) |
eafc087e | 162 | { |
debe6624 | 163 | Write32(string.Length()); |
3d4c6a21 | 164 | Write((const char *) string, string.Length()); |
cf447356 GL |
165 | } |
166 | ||
5260b1c5 JS |
167 | // Must be at global scope for VC++ 5 |
168 | extern "C" void ConvertToIeeeExtended(double num, unsigned char *bytes); | |
169 | ||
3d4c6a21 | 170 | void wxDataOutputStream::WriteDouble(double d) |
cf447356 | 171 | { |
cf447356 GL |
172 | char buf[10]; |
173 | ||
0e338ff9 | 174 | #if USE_APPLE_IEEE |
cf447356 | 175 | ConvertToIeeeExtended(d, (unsigned char *)buf); |
0e338ff9 KB |
176 | #else |
177 | # pragma warning "wxDataStream::WriteDouble() not using IeeeExtended - will not work!" | |
178 | buf[0] = '\0'; | |
179 | #endif | |
3d4c6a21 | 180 | Write(buf, 10); |
cf447356 | 181 | } |