2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wfstream.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxTempFileOutputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxTempFileOutputStream
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
wxTempFileOutputStream is an output stream based on wxTempFile.
|
|
|
|
It provides a relatively safe way to replace the contents of the
|
2008-03-08 13:52:38 +00:00
|
|
|
existing file.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxTempFile
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxTempFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Associates wxTempFileOutputStream with the file to be replaced and opens it.
|
2009-01-08 18:26:35 +00:00
|
|
|
|
|
|
|
@warning
|
2008-09-25 21:31:45 +00:00
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
|
|
|
|
|
|
|
Call Commit() or wxOutputStream::Close() to replace the old file and close
|
|
|
|
this one. Calling Discard() (or allowing the destructor to do it) will
|
|
|
|
discard the changes.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxTempFileOutputStream(const wxString& fileName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Validate changes: deletes the old file of the given name and renames the new
|
2008-09-25 21:31:45 +00:00
|
|
|
file to the old name. Returns @true if both actions succeeded.
|
|
|
|
|
|
|
|
If @false is returned it may unfortunately mean two quite different things: either that
|
2008-03-08 13:52:38 +00:00
|
|
|
either the old file couldn't be deleted or that the new file couldn't be renamed
|
|
|
|
to the old name.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual bool Commit();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Discard changes: the old file contents are not changed, the temporary file is
|
|
|
|
deleted.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void Discard();
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFFileOutputStream
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
This class represents data written to a file.
|
|
|
|
There are actually two such groups of classes: this one is based on wxFFile
|
2009-05-09 12:42:59 +00:00
|
|
|
whereas wxFileOutputStream is based in the wxFile class.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
Note that wxOutputStream::SeekO() can seek beyond the end of the stream
|
|
|
|
(file) and will thus not return ::wxInvalidOffset for that.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-05-09 12:42:59 +00:00
|
|
|
@see wxBufferedOutputStream, wxFFileInputStream, wxFileOutputStream, wxFileInputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxFFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 18:26:35 +00:00
|
|
|
Open the given file @a filename with mode @a mode.
|
|
|
|
|
|
|
|
@warning
|
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxFFileOutputStream(const wxString& filename,
|
2008-09-27 20:26:28 +00:00
|
|
|
const wxString& mode = "wb");
|
2008-09-25 21:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in write-only mode using the file I/O object file.
|
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxFFileOutputStream(wxFFile& file);
|
2008-09-25 21:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in write-only mode using the file descriptor fp.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxFFileOutputStream(FILE* fp);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxFFileOutputStream();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFileOutputStream
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
This class represents data written to a file.
|
|
|
|
There are actually two such groups of classes: this one is based on wxFile
|
2009-05-09 12:42:59 +00:00
|
|
|
whereas wxFFileOutputStream is based in the wxFFile class.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
Note that wxOutputStream::SeekO() can seek beyond the end of the stream
|
|
|
|
(file) and will thus not return ::wxInvalidOffset for that.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-05-09 12:42:59 +00:00
|
|
|
@see wxBufferedOutputStream, wxFileInputStream, wxFFileOutputStream, wxFFileInputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 18:26:35 +00:00
|
|
|
Creates a new file with @a ofileName name and initializes the stream in write-only mode.
|
2009-12-27 19:39:55 +00:00
|
|
|
|
2009-01-08 18:26:35 +00:00
|
|
|
@warning
|
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxFileOutputStream(const wxString& ofileName);
|
2008-09-25 21:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in write-only mode using the file I/O object file.
|
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxFileOutputStream(wxFile& file);
|
2008-09-25 21:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in write-only mode using the file descriptor @e fd.
|
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxFileOutputStream(int fd);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxFileOutputStream();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFileInputStream
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
This class represents data read in from a file.
|
|
|
|
There are actually two such groups of classes: this one is based on wxFile
|
|
|
|
whereas wxFFileInputStream is based in the wxFFile class.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
Note that wxInputStream::SeekI() can seek beyond the end of the stream (file)
|
|
|
|
and will thus not return ::wxInvalidOffset for that.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxBufferedInputStream, wxFileOutputStream, wxFFileOutputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxFileInputStream : public wxInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 18:26:35 +00:00
|
|
|
Opens the specified file using its @a ifileName name in read-only mode.
|
2009-12-27 19:39:55 +00:00
|
|
|
|
2009-01-08 18:26:35 +00:00
|
|
|
@warning
|
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxFileInputStream(const wxString& ifileName);
|
2008-09-25 21:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in read-only mode using the file I/O object file.
|
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxFileInputStream(wxFile& file);
|
2008-09-25 21:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in read-only mode using the specified file descriptor.
|
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxFileInputStream(int fd);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxFileInputStream();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFFileInputStream
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
This class represents data read in from a file.
|
|
|
|
There are actually two such groups of classes: this one is based on wxFFile
|
|
|
|
whereas wxFileInputStream is based in the wxFile class.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 21:31:45 +00:00
|
|
|
Note that wxInputStream::SeekI() can seek beyond the end of the stream (file)
|
|
|
|
and will thus not return ::wxInvalidOffset for that.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
@see wxBufferedInputStream, wxFFileOutputStream, wxFileOutputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxFFileInputStream : public wxInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 18:26:35 +00:00
|
|
|
Opens the specified file using its @a filename name using the specified @a mode.
|
|
|
|
|
|
|
|
@warning
|
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxFFileInputStream(const wxString& filename,
|
|
|
|
const wxString& mode = "rb");
|
2008-09-25 21:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in read-only mode using the file I/O object file.
|
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxFFileInputStream(wxFFile& file);
|
2008-09-25 21:31:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in read-only mode using the specified file pointer @a fp.
|
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
wxFFileInputStream(FILE* fp);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxFFileInputStream();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFFileStream
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-12-27 19:39:55 +00:00
|
|
|
This stream allows to both read from and write to a file using buffered
|
|
|
|
STDIO functions.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
2008-09-25 21:31:45 +00:00
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-12-27 19:39:55 +00:00
|
|
|
@see wxFFileInputStream, wxFFileOutputStream, wxFileStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-12-27 19:39:55 +00:00
|
|
|
class wxFFileStream : public wxFFileInputStream,
|
|
|
|
public wxFFileOutputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 18:26:35 +00:00
|
|
|
Initializes a new file stream in the given @a mode using the specified
|
|
|
|
@a iofileName name.
|
2009-12-27 19:39:55 +00:00
|
|
|
|
2009-01-08 18:26:35 +00:00
|
|
|
@warning
|
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-06-15 17:34:50 +00:00
|
|
|
wxFFileStream(const wxString& iofileName, const wxString& mode = "w+b");
|
2009-12-27 19:39:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
|
|
|
|
This method returns @true if the stream can be both read from and
|
|
|
|
written to.
|
|
|
|
*/
|
|
|
|
bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxFileStream
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-12-27 19:39:55 +00:00
|
|
|
This class represents data that can be both read from and written to a file.
|
|
|
|
There are actually two such groups of classes: this one is based on wxFile
|
|
|
|
whereas wxFFileStream is based in the wxFFile class.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
2008-09-25 21:31:45 +00:00
|
|
|
@category{streams}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2009-12-27 19:39:55 +00:00
|
|
|
@see wxFileInputStream, wxFileOutputStream, wxFFileStream
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2009-12-27 19:39:55 +00:00
|
|
|
class wxFileStream : public wxFileOutputStream,
|
|
|
|
public wxFileInputStream
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-08 14:43:31 +00:00
|
|
|
Initializes a new file stream in read-write mode using the specified
|
2009-01-08 18:26:35 +00:00
|
|
|
@a iofileName name.
|
2009-12-27 19:39:55 +00:00
|
|
|
|
2009-01-08 18:26:35 +00:00
|
|
|
@warning
|
2009-12-27 19:39:55 +00:00
|
|
|
You should use IsOk() to verify if the constructor succeeded.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxFileStream(const wxString& iofileName);
|
2009-12-27 19:39:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
|
|
|
|
This method returns @true if the stream can be both read from and
|
|
|
|
written to.
|
|
|
|
*/
|
|
|
|
bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|