]> git.saurik.com Git - wxWidgets.git/blame - src/common/fstream.cpp
* Fixed a bug in notebook.tex
[wxWidgets.git] / src / common / fstream.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__
13#pragma implementation "fstream.h"
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>
20#include <wx/fstream.h>
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
79c3e0e1 45wxFileInputStream::~wxFileInputStream()
3d4c6a21 46{
25c70b07
GL
47 if (m_file_destroy)
48 delete m_file;
3d4c6a21
GL
49}
50
6d44bf31 51char wxFileInputStream::Peek()
3d4c6a21 52{
6d44bf31 53 return 0;
3d4c6a21
GL
54}
55
6d44bf31
GL
56size_t wxFileInputStream::DoRead(void *buffer, size_t size)
57{
25c70b07 58 return m_file->Read(buffer, size);
6d44bf31
GL
59}
60
61off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
3d4c6a21 62{
25c70b07 63 return m_file->Seek(pos, mode);
79c3e0e1
GL
64}
65
6d44bf31 66off_t wxFileInputStream::DoTellInput() const
79c3e0e1 67{
25c70b07 68 return m_file->Tell();
79c3e0e1
GL
69}
70
71// ----------------------------------------------------------------------------
72// wxFileOutputStream
73// ----------------------------------------------------------------------------
74
75wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
25c70b07
GL
76{
77 m_file = new wxFile(fileName, wxFile::write);
78 m_file_destroy = TRUE;
79 m_o_streambuf->SetBufferIO(1024);
80}
81
82wxFileOutputStream::wxFileOutputStream()
83 : wxOutputStream()
79c3e0e1 84{
6d44bf31 85 m_o_streambuf->SetBufferIO(1024);
25c70b07
GL
86 m_file_destroy = FALSE;
87 m_file = NULL;
3d4c6a21
GL
88}
89
79c3e0e1 90wxFileOutputStream::~wxFileOutputStream()
3d4c6a21 91{
25c70b07
GL
92 if (m_file_destroy) {
93 Sync();
94 delete m_file;
95 }
79c3e0e1 96}
3d4c6a21 97
6d44bf31 98size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size)
79c3e0e1 99{
25c70b07
GL
100 size_t ret = m_file->Write(buffer, size);
101 m_bad = m_file->Error();
6d44bf31 102 return ret;
79c3e0e1 103}
3d4c6a21 104
6d44bf31 105off_t wxFileOutputStream::DoTellOutput() const
79c3e0e1 106{
25c70b07 107 return m_file->Tell();
3d4c6a21
GL
108}
109
6d44bf31 110off_t wxFileOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode)
3d4c6a21 111{
25c70b07 112 return m_file->Seek(pos, mode);
3d4c6a21
GL
113}
114
79c3e0e1 115void wxFileOutputStream::Sync()
3d4c6a21 116{
6d44bf31 117 wxOutputStream::Sync();
25c70b07 118 m_file->Flush();
3d4c6a21
GL
119}
120
79c3e0e1
GL
121// ----------------------------------------------------------------------------
122// wxFileStream
123// ----------------------------------------------------------------------------
124
125wxFileStream::wxFileStream(const wxString& fileName)
25c70b07 126 : wxFileInputStream(), wxFileOutputStream()
3d4c6a21 127{
25c70b07
GL
128 m_file = new wxFile(fileName, wxFile::read_write);
129 // Reread the initial buffer.
130 m_i_streambuf->SetBufferIO(1024);
3d4c6a21
GL
131}
132
79c3e0e1 133wxFileStream::~wxFileStream()
3d4c6a21 134{
25c70b07
GL
135 Sync();
136 delete m_file;
3d4c6a21 137}