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