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