]> git.saurik.com Git - wxWidgets.git/blob - src/common/wfstream.cpp
A few weeks of Unicode fixes (my old win95 laptop compiles sloowly,
[wxWidgets.git] / src / common / wfstream.cpp
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 "wfstream.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18 #include <stdio.h>
19 #include <wx/stream.h>
20 #include <wx/wfstream.h>
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 // ----------------------------------------------------------------------------
27 // wxFileInputStream
28 // ----------------------------------------------------------------------------
29
30 wxFileInputStream::wxFileInputStream(const wxString& fileName)
31 : wxInputStream()
32 {
33 m_file = new wxFile(fileName, wxFile::read);
34 m_file_destroy = TRUE;
35 m_i_streambuf->SetBufferIO(1024);
36 }
37
38 wxFileInputStream::wxFileInputStream()
39 : wxInputStream()
40 {
41 m_file_destroy = FALSE;
42 m_file = NULL;
43 }
44
45 wxFileInputStream::wxFileInputStream(wxFile& file)
46 {
47 m_file = &file;
48 m_file_destroy = FALSE;
49 m_i_streambuf->SetBufferIO(1024);
50 }
51
52 wxFileInputStream::wxFileInputStream(int fd)
53 {
54 m_file = new wxFile(fd);
55 m_file_destroy = TRUE;
56 m_i_streambuf->SetBufferIO(1024);
57 }
58
59 wxFileInputStream::~wxFileInputStream()
60 {
61 if (m_file_destroy)
62 delete m_file;
63 }
64
65 char wxFileInputStream::Peek()
66 {
67 return 0;
68 }
69
70 size_t wxFileInputStream::StreamSize() const
71 {
72 return m_file->Length();
73 }
74
75 size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
76 {
77 return m_file->Read(buffer, size);
78 }
79
80 off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
81 {
82 return m_file->Seek(pos, mode);
83 }
84
85 off_t wxFileInputStream::OnSysTell() const
86 {
87 return m_file->Tell();
88 }
89
90 // ----------------------------------------------------------------------------
91 // wxFileOutputStream
92 // ----------------------------------------------------------------------------
93
94 wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
95 {
96 m_file = new wxFile(fileName, wxFile::write);
97 m_file_destroy = TRUE;
98 m_o_streambuf->SetBufferIO(1024);
99 }
100
101 wxFileOutputStream::wxFileOutputStream(wxFile& file)
102 {
103 m_file = &file;
104 m_file_destroy = FALSE;
105 m_o_streambuf->SetBufferIO(1024);
106 }
107
108 wxFileOutputStream::wxFileOutputStream()
109 : wxOutputStream()
110 {
111 m_o_streambuf->SetBufferIO(1024);
112 m_file_destroy = FALSE;
113 m_file = NULL;
114 }
115
116 wxFileOutputStream::wxFileOutputStream(int fd)
117 {
118 m_file = new wxFile(fd);
119 m_file_destroy = TRUE;
120 m_o_streambuf->SetBufferIO(1024);
121 }
122
123 wxFileOutputStream::~wxFileOutputStream()
124 {
125 if (m_file_destroy) {
126 Sync();
127 delete m_file;
128 }
129 }
130
131 size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
132 {
133 size_t ret = m_file->Write(buffer, size);
134 m_lasterror = wxStream_EOF; // TODO
135 return ret;
136 }
137
138 off_t wxFileOutputStream::OnSysTell() const
139 {
140 return m_file->Tell();
141 }
142
143 off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
144 {
145 return m_file->Seek(pos, mode);
146 }
147
148 void wxFileOutputStream::Sync()
149 {
150 wxOutputStream::Sync();
151 m_file->Flush();
152 }
153
154 size_t wxFileOutputStream::StreamSize() const
155 {
156 return m_file->Length();
157 }
158
159 // ----------------------------------------------------------------------------
160 // wxFileStream
161 // ----------------------------------------------------------------------------
162 wxFileStream::wxFileStream(const wxString& fileName)
163 : wxFileInputStream(fileName), wxFileOutputStream(*wxFileInputStream::m_file)
164 {
165 }