]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/fstream.cpp
no message
[wxWidgets.git] / src / common / fstream.cpp
... / ...
CommitLineData
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
30wxFileInputStream::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
38wxFileInputStream::wxFileInputStream()
39 : wxInputStream()
40{
41 m_file_destroy = FALSE;
42 m_file = NULL;
43}
44
45wxFileInputStream::~wxFileInputStream()
46{
47 if (m_file_destroy)
48 delete m_file;
49}
50
51char wxFileInputStream::Peek()
52{
53 return 0;
54}
55
56size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
57{
58 return m_file->Read(buffer, size);
59}
60
61off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
62{
63 return m_file->Seek(pos, mode);
64}
65
66off_t wxFileInputStream::OnSysTell() const
67{
68 return m_file->Tell();
69}
70
71// ----------------------------------------------------------------------------
72// wxFileOutputStream
73// ----------------------------------------------------------------------------
74
75wxFileOutputStream::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
82wxFileOutputStream::wxFileOutputStream()
83 : wxOutputStream()
84{
85 m_o_streambuf->SetBufferIO(1024);
86 m_file_destroy = FALSE;
87 m_file = NULL;
88}
89
90wxFileOutputStream::~wxFileOutputStream()
91{
92 if (m_file_destroy) {
93 Sync();
94 delete m_file;
95 }
96}
97
98size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
99{
100 size_t ret = m_file->Write(buffer, size);
101 m_lasterror = wxStream_EOF; // TODO
102 return ret;
103}
104
105off_t wxFileOutputStream::OnSysTell() const
106{
107 return m_file->Tell();
108}
109
110off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
111{
112 return m_file->Seek(pos, mode);
113}
114
115void wxFileOutputStream::Sync()
116{
117 wxOutputStream::Sync();
118 m_file->Flush();
119}