]>
Commit | Line | Data |
---|---|---|
3d4c6a21 GL |
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 | ||
79c3e0e1 GL |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
3d4c6a21 GL |
18 | #include <stdio.h> |
19 | #include <wx/stream.h> | |
20 | #include <wx/fstream.h> | |
21 | ||
79c3e0e1 GL |
22 | #ifdef __BORLANDC__ |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
79c3e0e1 GL |
26 | // ---------------------------------------------------------------------------- |
27 | // wxFileInputStream | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
30 | wxFileInputStream::wxFileInputStream(const wxString& fileName) | |
25c70b07 | 31 | : wxInputStream() |
3d4c6a21 | 32 | { |
25c70b07 GL |
33 | m_file = new wxFile(fileName, wxFile::read); |
34 | m_file_destroy = TRUE; | |
6d44bf31 | 35 | m_i_streambuf->SetBufferIO(1024); |
3d4c6a21 GL |
36 | } |
37 | ||
25c70b07 GL |
38 | wxFileInputStream::wxFileInputStream() |
39 | : wxInputStream() | |
40 | { | |
41 | m_file_destroy = FALSE; | |
42 | m_file = NULL; | |
43 | } | |
44 | ||
79c3e0e1 | 45 | wxFileInputStream::~wxFileInputStream() |
3d4c6a21 | 46 | { |
25c70b07 GL |
47 | if (m_file_destroy) |
48 | delete m_file; | |
3d4c6a21 GL |
49 | } |
50 | ||
6d44bf31 | 51 | char wxFileInputStream::Peek() |
3d4c6a21 | 52 | { |
6d44bf31 | 53 | return 0; |
3d4c6a21 GL |
54 | } |
55 | ||
6d44bf31 GL |
56 | size_t wxFileInputStream::DoRead(void *buffer, size_t size) |
57 | { | |
25c70b07 | 58 | return m_file->Read(buffer, size); |
6d44bf31 GL |
59 | } |
60 | ||
61 | off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode) | |
3d4c6a21 | 62 | { |
25c70b07 | 63 | return m_file->Seek(pos, mode); |
79c3e0e1 GL |
64 | } |
65 | ||
6d44bf31 | 66 | off_t wxFileInputStream::DoTellInput() const |
79c3e0e1 | 67 | { |
25c70b07 | 68 | return m_file->Tell(); |
79c3e0e1 GL |
69 | } |
70 | ||
71 | // ---------------------------------------------------------------------------- | |
72 | // wxFileOutputStream | |
73 | // ---------------------------------------------------------------------------- | |
74 | ||
75 | wxFileOutputStream::wxFileOutputStream(const wxString& fileName) | |
25c70b07 GL |
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() | |
79c3e0e1 | 84 | { |
6d44bf31 | 85 | m_o_streambuf->SetBufferIO(1024); |
25c70b07 GL |
86 | m_file_destroy = FALSE; |
87 | m_file = NULL; | |
3d4c6a21 GL |
88 | } |
89 | ||
79c3e0e1 | 90 | wxFileOutputStream::~wxFileOutputStream() |
3d4c6a21 | 91 | { |
25c70b07 GL |
92 | if (m_file_destroy) { |
93 | Sync(); | |
94 | delete m_file; | |
95 | } | |
79c3e0e1 | 96 | } |
3d4c6a21 | 97 | |
6d44bf31 | 98 | size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size) |
79c3e0e1 | 99 | { |
25c70b07 GL |
100 | size_t ret = m_file->Write(buffer, size); |
101 | m_bad = m_file->Error(); | |
6d44bf31 | 102 | return ret; |
79c3e0e1 | 103 | } |
3d4c6a21 | 104 | |
6d44bf31 | 105 | off_t wxFileOutputStream::DoTellOutput() const |
79c3e0e1 | 106 | { |
25c70b07 | 107 | return m_file->Tell(); |
3d4c6a21 GL |
108 | } |
109 | ||
6d44bf31 | 110 | off_t wxFileOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode) |
3d4c6a21 | 111 | { |
25c70b07 | 112 | return m_file->Seek(pos, mode); |
3d4c6a21 GL |
113 | } |
114 | ||
79c3e0e1 | 115 | void wxFileOutputStream::Sync() |
3d4c6a21 | 116 | { |
6d44bf31 | 117 | wxOutputStream::Sync(); |
25c70b07 | 118 | m_file->Flush(); |
3d4c6a21 GL |
119 | } |
120 | ||
79c3e0e1 GL |
121 | // ---------------------------------------------------------------------------- |
122 | // wxFileStream | |
123 | // ---------------------------------------------------------------------------- | |
124 | ||
125 | wxFileStream::wxFileStream(const wxString& fileName) | |
25c70b07 | 126 | : wxFileInputStream(), wxFileOutputStream() |
3d4c6a21 | 127 | { |
25c70b07 GL |
128 | m_file = new wxFile(fileName, wxFile::read_write); |
129 | // Reread the initial buffer. | |
130 | m_i_streambuf->SetBufferIO(1024); | |
3d4c6a21 GL |
131 | } |
132 | ||
79c3e0e1 | 133 | wxFileStream::~wxFileStream() |
3d4c6a21 | 134 | { |
25c70b07 GL |
135 | Sync(); |
136 | delete m_file; | |
3d4c6a21 | 137 | } |