]>
git.saurik.com Git - wxWidgets.git/blob - src/common/wfstream.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: "File stream" classes
4 // Author: Julian Smart
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wfstream.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #include <wx/stream.h>
20 #include <wx/wfstream.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(wxFile
& file
)
48 m_file_destroy
= FALSE
;
49 m_i_streambuf
->SetBufferIO(1024);
52 wxFileInputStream::wxFileInputStream(int fd
)
54 m_file
= new wxFile(fd
);
55 m_file_destroy
= TRUE
;
56 m_i_streambuf
->SetBufferIO(1024);
59 wxFileInputStream::~wxFileInputStream()
65 char wxFileInputStream::Peek()
70 size_t wxFileInputStream::StreamSize() const
72 return m_file
->Length();
75 size_t wxFileInputStream::OnSysRead(void *buffer
, size_t size
)
77 return m_file
->Read(buffer
, size
);
80 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
82 return m_file
->Seek(pos
, mode
);
85 off_t
wxFileInputStream::OnSysTell() const
87 return m_file
->Tell();
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
96 m_file
= new wxFile(fileName
, wxFile::write
);
97 m_file_destroy
= TRUE
;
98 m_o_streambuf
->SetBufferIO(1024);
101 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
104 m_file_destroy
= FALSE
;
105 m_o_streambuf
->SetBufferIO(1024);
108 wxFileOutputStream::wxFileOutputStream()
111 m_o_streambuf
->SetBufferIO(1024);
112 m_file_destroy
= FALSE
;
116 wxFileOutputStream::wxFileOutputStream(int fd
)
118 m_file
= new wxFile(fd
);
119 m_file_destroy
= TRUE
;
120 m_o_streambuf
->SetBufferIO(1024);
123 wxFileOutputStream::~wxFileOutputStream()
125 if (m_file_destroy
) {
131 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
133 size_t ret
= m_file
->Write(buffer
, size
);
134 m_lasterror
= wxStream_EOF
; // TODO
138 off_t
wxFileOutputStream::OnSysTell() const
140 return m_file
->Tell();
143 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
145 return m_file
->Seek(pos
, mode
);
148 void wxFileOutputStream::Sync()
150 wxOutputStream::Sync();
154 size_t wxFileOutputStream::StreamSize() const
156 return m_file
->Length();
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
162 wxFileStream::wxFileStream(const wxString
& fileName
)
163 : wxFileInputStream(fileName
), wxFileOutputStream(*wxFileInputStream::m_file
)