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