]> git.saurik.com Git - wxWidgets.git/blame - src/common/wfstream.cpp
Hardcode colours in systems settings.
[wxWidgets.git] / src / common / wfstream.cpp
CommitLineData
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__
593d4b0d 13#pragma implementation "wfstream.h"
3d4c6a21
GL
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>
593d4b0d 20#include <wx/wfstream.h>
3d4c6a21 21
79c3e0e1
GL
22#ifdef __BORLANDC__
23#pragma hdrstop
24#endif
25
79c3e0e1
GL
26// ----------------------------------------------------------------------------
27// wxFileInputStream
28// ----------------------------------------------------------------------------
29
30wxFileInputStream::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
38wxFileInputStream::wxFileInputStream()
39 : wxInputStream()
40{
41 m_file_destroy = FALSE;
42 m_file = NULL;
43}
44
79c3e0e1 45wxFileInputStream::~wxFileInputStream()
3d4c6a21 46{
25c70b07
GL
47 if (m_file_destroy)
48 delete m_file;
3d4c6a21
GL
49}
50
6d44bf31 51char wxFileInputStream::Peek()
3d4c6a21 52{
6d44bf31 53 return 0;
3d4c6a21
GL
54}
55
84b46c35
GL
56size_t wxFileInputStream::StreamSize() const
57{
58 return m_file->Length();
59}
60
75ed1d15 61size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
6d44bf31 62{
25c70b07 63 return m_file->Read(buffer, size);
6d44bf31
GL
64}
65
75ed1d15 66off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
3d4c6a21 67{
25c70b07 68 return m_file->Seek(pos, mode);
79c3e0e1
GL
69}
70
75ed1d15 71off_t wxFileInputStream::OnSysTell() const
79c3e0e1 72{
25c70b07 73 return m_file->Tell();
79c3e0e1
GL
74}
75
76// ----------------------------------------------------------------------------
77// wxFileOutputStream
78// ----------------------------------------------------------------------------
79
80wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
25c70b07
GL
81{
82 m_file = new wxFile(fileName, wxFile::write);
83 m_file_destroy = TRUE;
84 m_o_streambuf->SetBufferIO(1024);
85}
86
84b46c35
GL
87wxFileOutputStream::wxFileOutputStream(wxFile& file)
88{
89 m_file = &file;
90 m_file_destroy = FALSE;
91 m_o_streambuf->SetBufferIO(1024);
92}
93
25c70b07
GL
94wxFileOutputStream::wxFileOutputStream()
95 : wxOutputStream()
79c3e0e1 96{
6d44bf31 97 m_o_streambuf->SetBufferIO(1024);
25c70b07
GL
98 m_file_destroy = FALSE;
99 m_file = NULL;
3d4c6a21
GL
100}
101
79c3e0e1 102wxFileOutputStream::~wxFileOutputStream()
3d4c6a21 103{
25c70b07
GL
104 if (m_file_destroy) {
105 Sync();
106 delete m_file;
107 }
79c3e0e1 108}
3d4c6a21 109
75ed1d15 110size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
79c3e0e1 111{
25c70b07 112 size_t ret = m_file->Write(buffer, size);
75ed1d15 113 m_lasterror = wxStream_EOF; // TODO
6d44bf31 114 return ret;
79c3e0e1 115}
3d4c6a21 116
75ed1d15 117off_t wxFileOutputStream::OnSysTell() const
79c3e0e1 118{
25c70b07 119 return m_file->Tell();
3d4c6a21
GL
120}
121
75ed1d15 122off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
3d4c6a21 123{
25c70b07 124 return m_file->Seek(pos, mode);
3d4c6a21
GL
125}
126
79c3e0e1 127void wxFileOutputStream::Sync()
3d4c6a21 128{
6d44bf31 129 wxOutputStream::Sync();
25c70b07 130 m_file->Flush();
3d4c6a21 131}
84b46c35
GL
132
133size_t wxFileOutputStream::StreamSize() const
134{
135 return m_file->Length();
136}
137
138// ----------------------------------------------------------------------------
139// wxFileStream
140// ----------------------------------------------------------------------------
141wxFileStream::wxFileStream(const wxString& fileName)
142 : wxFileInputStream(fileName), wxFileOutputStream(*wxFileInputStream::m_file)
143{
144}