]> git.saurik.com Git - wxWidgets.git/blame - src/common/wfstream.cpp
old makefiles removed
[wxWidgets.git] / src / common / wfstream.cpp
CommitLineData
3d4c6a21
GL
1/////////////////////////////////////////////////////////////////////////////
2// Name: fstream.cpp
3// Purpose: "File stream" classes
4// Author: Julian Smart
5// Modified by:
6// Created: 11/07/98
7// RCS-ID: $Id$
8// Copyright: (c) Guilhem Lavaux
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
593d4b0d 13#pragma implementation "wfstream.h"
3d4c6a21
GL
14#endif
15
79c3e0e1
GL
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
3d4c6a21
GL
18#include <stdio.h>
19#include <wx/stream.h>
593d4b0d 20#include <wx/wfstream.h>
3d4c6a21 21
79c3e0e1
GL
22#ifdef __BORLANDC__
23#pragma hdrstop
24#endif
25
79c3e0e1
GL
26// ----------------------------------------------------------------------------
27// wxFileInputStream
28// ----------------------------------------------------------------------------
29
30wxFileInputStream::wxFileInputStream(const wxString& fileName)
25c70b07 31 : wxInputStream()
3d4c6a21 32{
25c70b07
GL
33 m_file = new wxFile(fileName, wxFile::read);
34 m_file_destroy = TRUE;
6d44bf31 35 m_i_streambuf->SetBufferIO(1024);
3d4c6a21
GL
36}
37
25c70b07
GL
38wxFileInputStream::wxFileInputStream()
39 : wxInputStream()
40{
41 m_file_destroy = FALSE;
42 m_file = NULL;
43}
44
0aca1ded
GL
45wxFileInputStream::wxFileInputStream(wxFile& file)
46{
47 m_file = &file;
48 m_file_destroy = FALSE;
49 m_i_streambuf->SetBufferIO(1024);
50}
51
52wxFileInputStream::wxFileInputStream(int fd)
53{
54 m_file = new wxFile(fd);
55 m_file_destroy = TRUE;
56 m_i_streambuf->SetBufferIO(1024);
57}
58
79c3e0e1 59wxFileInputStream::~wxFileInputStream()
3d4c6a21 60{
25c70b07
GL
61 if (m_file_destroy)
62 delete m_file;
3d4c6a21
GL
63}
64
6d44bf31 65char wxFileInputStream::Peek()
3d4c6a21 66{
6d44bf31 67 return 0;
3d4c6a21
GL
68}
69
84b46c35
GL
70size_t wxFileInputStream::StreamSize() const
71{
72 return m_file->Length();
73}
74
75ed1d15 75size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
6d44bf31 76{
25c70b07 77 return m_file->Read(buffer, size);
6d44bf31
GL
78}
79
75ed1d15 80off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
3d4c6a21 81{
25c70b07 82 return m_file->Seek(pos, mode);
79c3e0e1
GL
83}
84
75ed1d15 85off_t wxFileInputStream::OnSysTell() const
79c3e0e1 86{
25c70b07 87 return m_file->Tell();
79c3e0e1
GL
88}
89
90// ----------------------------------------------------------------------------
91// wxFileOutputStream
92// ----------------------------------------------------------------------------
93
94wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
25c70b07
GL
95{
96 m_file = new wxFile(fileName, wxFile::write);
97 m_file_destroy = TRUE;
98 m_o_streambuf->SetBufferIO(1024);
99}
100
84b46c35
GL
101wxFileOutputStream::wxFileOutputStream(wxFile& file)
102{
103 m_file = &file;
104 m_file_destroy = FALSE;
105 m_o_streambuf->SetBufferIO(1024);
106}
107
25c70b07
GL
108wxFileOutputStream::wxFileOutputStream()
109 : wxOutputStream()
79c3e0e1 110{
6d44bf31 111 m_o_streambuf->SetBufferIO(1024);
25c70b07
GL
112 m_file_destroy = FALSE;
113 m_file = NULL;
3d4c6a21
GL
114}
115
0aca1ded
GL
116wxFileOutputStream::wxFileOutputStream(int fd)
117{
118 m_file = new wxFile(fd);
119 m_file_destroy = TRUE;
120 m_o_streambuf->SetBufferIO(1024);
121}
122
79c3e0e1 123wxFileOutputStream::~wxFileOutputStream()
3d4c6a21 124{
25c70b07
GL
125 if (m_file_destroy) {
126 Sync();
127 delete m_file;
128 }
79c3e0e1 129}
3d4c6a21 130
75ed1d15 131size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
79c3e0e1 132{
25c70b07 133 size_t ret = m_file->Write(buffer, size);
75ed1d15 134 m_lasterror = wxStream_EOF; // TODO
6d44bf31 135 return ret;
79c3e0e1 136}
3d4c6a21 137
75ed1d15 138off_t wxFileOutputStream::OnSysTell() const
79c3e0e1 139{
25c70b07 140 return m_file->Tell();
3d4c6a21
GL
141}
142
75ed1d15 143off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
3d4c6a21 144{
25c70b07 145 return m_file->Seek(pos, mode);
3d4c6a21
GL
146}
147
79c3e0e1 148void wxFileOutputStream::Sync()
3d4c6a21 149{
6d44bf31 150 wxOutputStream::Sync();
25c70b07 151 m_file->Flush();
3d4c6a21 152}
84b46c35
GL
153
154size_t wxFileOutputStream::StreamSize() const
155{
156 return m_file->Length();
157}
158
159// ----------------------------------------------------------------------------
160// wxFileStream
161// ----------------------------------------------------------------------------
162wxFileStream::wxFileStream(const wxString& fileName)
163 : wxFileInputStream(fileName), wxFileOutputStream(*wxFileInputStream::m_file)
164{
165}