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