]> git.saurik.com Git - wxWidgets.git/blob - src/common/wfstream.cpp
menu title is drawn in bold font and the commands from it are ignored
[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()
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::StreamSize() const
57 {
58 return m_file->Length();
59 }
60
61 size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
62 {
63 return m_file->Read(buffer, size);
64 }
65
66 off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
67 {
68 return m_file->Seek(pos, mode);
69 }
70
71 off_t wxFileInputStream::OnSysTell() const
72 {
73 return m_file->Tell();
74 }
75
76 // ----------------------------------------------------------------------------
77 // wxFileOutputStream
78 // ----------------------------------------------------------------------------
79
80 wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
81 {
82 m_file = new wxFile(fileName, wxFile::write);
83 m_file_destroy = TRUE;
84 m_o_streambuf->SetBufferIO(1024);
85 }
86
87 wxFileOutputStream::wxFileOutputStream(wxFile& file)
88 {
89 m_file = &file;
90 m_file_destroy = FALSE;
91 m_o_streambuf->SetBufferIO(1024);
92 }
93
94 wxFileOutputStream::wxFileOutputStream()
95 : wxOutputStream()
96 {
97 m_o_streambuf->SetBufferIO(1024);
98 m_file_destroy = FALSE;
99 m_file = NULL;
100 }
101
102 wxFileOutputStream::~wxFileOutputStream()
103 {
104 if (m_file_destroy) {
105 Sync();
106 delete m_file;
107 }
108 }
109
110 size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
111 {
112 size_t ret = m_file->Write(buffer, size);
113 m_lasterror = wxStream_EOF; // TODO
114 return ret;
115 }
116
117 off_t wxFileOutputStream::OnSysTell() const
118 {
119 return m_file->Tell();
120 }
121
122 off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
123 {
124 return m_file->Seek(pos, mode);
125 }
126
127 void wxFileOutputStream::Sync()
128 {
129 wxOutputStream::Sync();
130 m_file->Flush();
131 }
132
133 size_t wxFileOutputStream::StreamSize() const
134 {
135 return m_file->Length();
136 }
137
138 // ----------------------------------------------------------------------------
139 // wxFileStream
140 // ----------------------------------------------------------------------------
141 wxFileStream::wxFileStream(const wxString& fileName)
142 : wxFileInputStream(fileName), wxFileOutputStream(*wxFileInputStream::m_file)
143 {
144 }