]>
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"
27 #if wxUSE_STREAMS && wxUSE_FILE
30 #include <wx/stream.h>
31 #include <wx/wfstream.h>
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 wxFileInputStream::wxFileInputStream(const wxString
& fileName
)
40 m_file
= new wxFile(fileName
, wxFile::read
);
41 m_file_destroy
= TRUE
;
42 m_i_streambuf
->SetBufferIO(1024);
45 wxFileInputStream::wxFileInputStream()
48 m_file_destroy
= FALSE
;
52 wxFileInputStream::wxFileInputStream(wxFile
& file
)
55 m_file_destroy
= FALSE
;
56 m_i_streambuf
->SetBufferIO(1024);
59 wxFileInputStream::wxFileInputStream(int fd
)
61 m_file
= new wxFile(fd
);
62 m_file_destroy
= TRUE
;
63 m_i_streambuf
->SetBufferIO(1024);
66 wxFileInputStream::~wxFileInputStream()
72 char wxFileInputStream::Peek()
77 size_t wxFileInputStream::StreamSize() const
79 return m_file
->Length();
82 size_t wxFileInputStream::OnSysRead(void *buffer
, size_t size
)
84 return m_file
->Read(buffer
, size
);
87 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
89 return m_file
->Seek(pos
, mode
);
92 off_t
wxFileInputStream::OnSysTell() const
94 return m_file
->Tell();
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
103 m_file
= new wxFile(fileName
, wxFile::write
);
104 m_file_destroy
= TRUE
;
105 m_o_streambuf
->SetBufferIO(1024);
108 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
111 m_file_destroy
= FALSE
;
112 m_o_streambuf
->SetBufferIO(1024);
115 wxFileOutputStream::wxFileOutputStream()
118 m_o_streambuf
->SetBufferIO(1024);
119 m_file_destroy
= FALSE
;
123 wxFileOutputStream::wxFileOutputStream(int fd
)
125 m_file
= new wxFile(fd
);
126 m_file_destroy
= TRUE
;
127 m_o_streambuf
->SetBufferIO(1024);
130 wxFileOutputStream::~wxFileOutputStream()
132 if (m_file_destroy
) {
138 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
140 size_t ret
= m_file
->Write(buffer
, size
);
141 m_lasterror
= wxStream_EOF
; // TODO
145 off_t
wxFileOutputStream::OnSysTell() const
147 return m_file
->Tell();
150 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
152 return m_file
->Seek(pos
, mode
);
155 void wxFileOutputStream::Sync()
157 wxOutputStream::Sync();
161 size_t wxFileOutputStream::StreamSize() const
163 return m_file
->Length();
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
169 wxFileStream::wxFileStream(const wxString
& fileName
)
170 : wxFileInputStream(fileName
), wxFileOutputStream(*wxFileInputStream::m_file
)
175 // wxUSE_STREAMS && wxUSE_FILE