]> git.saurik.com Git - wxWidgets.git/blob - src/common/fstream.cpp
Added --with-unicode (not used yet) and --with-wcsrtombs options
[wxWidgets.git] / src / common / fstream.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 "fstream.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/fstream.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()
46 {
47 if (m_file_destroy)
48 delete m_file;
49 }
50
51 char wxFileInputStream::Peek()
52 {
53 return 0;
54 }
55
56 size_t wxFileInputStream::DoRead(void *buffer, size_t size)
57 {
58 return m_file->Read(buffer, size);
59 }
60
61 off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
62 {
63 return m_file->Seek(pos, mode);
64 }
65
66 off_t wxFileInputStream::DoTellInput() const
67 {
68 return m_file->Tell();
69 }
70
71 // ----------------------------------------------------------------------------
72 // wxFileOutputStream
73 // ----------------------------------------------------------------------------
74
75 wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
76 {
77 m_file = new wxFile(fileName, wxFile::write);
78 m_file_destroy = TRUE;
79 m_o_streambuf->SetBufferIO(1024);
80 }
81
82 wxFileOutputStream::wxFileOutputStream()
83 : wxOutputStream()
84 {
85 m_o_streambuf->SetBufferIO(1024);
86 m_file_destroy = FALSE;
87 m_file = NULL;
88 }
89
90 wxFileOutputStream::~wxFileOutputStream()
91 {
92 if (m_file_destroy) {
93 Sync();
94 delete m_file;
95 }
96 }
97
98 size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size)
99 {
100 size_t ret = m_file->Write(buffer, size);
101 m_bad = m_file->Error();
102 return ret;
103 }
104
105 off_t wxFileOutputStream::DoTellOutput() const
106 {
107 return m_file->Tell();
108 }
109
110 off_t wxFileOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode)
111 {
112 return m_file->Seek(pos, mode);
113 }
114
115 void wxFileOutputStream::Sync()
116 {
117 wxOutputStream::Sync();
118 m_file->Flush();
119 }
120
121 // ----------------------------------------------------------------------------
122 // wxFileStream
123 // ----------------------------------------------------------------------------
124
125 wxFileStream::wxFileStream(const wxString& fileName)
126 : wxFileInputStream(), wxFileOutputStream()
127 {
128 m_file = new wxFile(fileName, wxFile::read_write);
129 // Reread the initial buffer.
130 m_i_streambuf->SetBufferIO(1024);
131 }
132
133 wxFileStream::~wxFileStream()
134 {
135 Sync();
136 delete m_file;
137 }