]>
git.saurik.com Git - wxWidgets.git/blob - src/common/fstream.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: "File stream" classes
4 // Author: Julian Smart
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "fstream.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #include <wx/stream.h>
20 #include <wx/fstream.h>
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 wxFileInputStream::wxFileInputStream(const wxString
& fileName
)
33 m_file
= new wxFile(fileName
, wxFile::read
);
34 m_file_destroy
= TRUE
;
35 m_i_streambuf
->SetBufferIO(1024);
38 wxFileInputStream::wxFileInputStream()
41 m_file_destroy
= FALSE
;
45 wxFileInputStream::~wxFileInputStream()
51 char wxFileInputStream::Peek()
56 size_t wxFileInputStream::DoRead(void *buffer
, size_t size
)
58 return m_file
->Read(buffer
, size
);
61 off_t
wxFileInputStream::DoSeekInput(off_t pos
, wxSeekMode mode
)
63 return m_file
->Seek(pos
, mode
);
66 off_t
wxFileInputStream::DoTellInput() const
68 return m_file
->Tell();
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
77 m_file
= new wxFile(fileName
, wxFile::write
);
78 m_file_destroy
= TRUE
;
79 m_o_streambuf
->SetBufferIO(1024);
82 wxFileOutputStream::wxFileOutputStream()
85 m_o_streambuf
->SetBufferIO(1024);
86 m_file_destroy
= FALSE
;
90 wxFileOutputStream::~wxFileOutputStream()
98 size_t wxFileOutputStream::DoWrite(const void *buffer
, size_t size
)
100 size_t ret
= m_file
->Write(buffer
, size
);
101 m_bad
= m_file
->Error();
105 off_t
wxFileOutputStream::DoTellOutput() const
107 return m_file
->Tell();
110 off_t
wxFileOutputStream::DoSeekOutput(off_t pos
, wxSeekMode mode
)
112 return m_file
->Seek(pos
, mode
);
115 void wxFileOutputStream::Sync()
117 wxOutputStream::Sync();
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 wxFileStream::wxFileStream(const wxString
& fileName
)
126 : wxFileInputStream(), wxFileOutputStream()
128 m_file
= new wxFile(fileName
, wxFile::read_write
);
129 // Reread the initial buffer.
130 m_i_streambuf
->SetBufferIO(1024);
133 wxFileStream::~wxFileStream()