2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wfstream.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxTempFileOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxTempFileOutputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04:00
|
|
|
wxTempFileOutputStream is an output stream based on wxTempFile.
|
|
|
|
It provides a relatively safe way to replace the contents of the
|
2008-03-08 08:52:38 -05:00
|
|
|
existing file.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxTempFile
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxTempFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Associates wxTempFileOutputStream with the file to be replaced and opens it.
|
2009-01-08 13:26:35 -05:00
|
|
|
|
|
|
|
@warning
|
2008-09-25 17:31:45 -04: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 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxTempFileOutputStream(const wxString& fileName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Validate changes: deletes the old file of the given name and renames the new
|
2008-09-25 17:31:45 -04: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 08:52:38 -05: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 07:21:10 -04:00
|
|
|
virtual bool Commit();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Discard changes: the old file contents are not changed, the temporary file is
|
|
|
|
deleted.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual void Discard();
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2020-02-21 08:52:40 -05:00
|
|
|
/**
|
|
|
|
@class wxTempFFileOutputStream
|
|
|
|
|
|
|
|
wxTempFFileOutputStream is an output stream based on wxTempFFile.
|
|
|
|
It provides a relatively safe way to replace the contents of the
|
|
|
|
existing file.
|
|
|
|
|
|
|
|
@since 3.1.4
|
|
|
|
|
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
|
|
|
|
|
|
|
@see wxTempFFile
|
|
|
|
*/
|
|
|
|
class wxTempFFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Associates wxTempFFileOutputStream with the file to be replaced and opens it.
|
|
|
|
|
|
|
|
@warning
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
wxTempFFileOutputStream(const wxString& fileName);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Validate changes: deletes the old file of the given name and renames the new
|
|
|
|
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
|
|
|
|
either the old file couldn't be deleted or that the new file couldn't be renamed
|
|
|
|
to the old name.
|
|
|
|
*/
|
|
|
|
virtual bool Commit();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Discard changes: the old file contents are not changed, the temporary file is
|
|
|
|
deleted.
|
|
|
|
*/
|
|
|
|
virtual void Discard();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxFFileOutputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04: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 08:42:59 -04:00
|
|
|
whereas wxFileOutputStream is based in the wxFile class.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04: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 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-05-09 08:42:59 -04:00
|
|
|
@see wxBufferedOutputStream, wxFFileInputStream, wxFileOutputStream, wxFileInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxFFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 13:26:35 -05: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 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxFFileOutputStream(const wxString& filename,
|
2008-09-27 16:26:28 -04:00
|
|
|
const wxString& mode = "wb");
|
2008-09-25 17:31:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in write-only mode using the file I/O object file.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxFFileOutputStream(wxFFile& file);
|
2008-09-25 17:31:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in write-only mode using the file descriptor fp.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
wxFFileOutputStream(FILE* fp);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxFFileOutputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOk() const;
|
2013-03-09 10:08:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the underlying file object.
|
|
|
|
@since 2.9.5
|
|
|
|
*/
|
|
|
|
wxFFile* GetFile() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxFileOutputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04: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 08:42:59 -04:00
|
|
|
whereas wxFFileOutputStream is based in the wxFFile class.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04: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 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-05-09 08:42:59 -04:00
|
|
|
@see wxBufferedOutputStream, wxFileInputStream, wxFFileOutputStream, wxFFileInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxFileOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 13:26:35 -05:00
|
|
|
Creates a new file with @a ofileName name and initializes the stream in write-only mode.
|
2009-12-27 14:39:55 -05:00
|
|
|
|
2009-01-08 13:26:35 -05:00
|
|
|
@warning
|
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxFileOutputStream(const wxString& ofileName);
|
2008-09-25 17:31:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in write-only mode using the file I/O object file.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxFileOutputStream(wxFile& file);
|
2008-09-25 17:31:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in write-only mode using the file descriptor @e fd.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxFileOutputStream(int fd);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxFileOutputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOk() const;
|
2013-03-09 10:08:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the underlying file object.
|
|
|
|
@since 2.9.5
|
|
|
|
*/
|
|
|
|
wxFile* GetFile() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxFileInputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04: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 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04: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 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxBufferedInputStream, wxFileOutputStream, wxFFileOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxFileInputStream : public wxInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 13:26:35 -05:00
|
|
|
Opens the specified file using its @a ifileName name in read-only mode.
|
2009-12-27 14:39:55 -05:00
|
|
|
|
2009-01-08 13:26:35 -05:00
|
|
|
@warning
|
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxFileInputStream(const wxString& ifileName);
|
2008-09-25 17:31:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in read-only mode using the file I/O object file.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxFileInputStream(wxFile& file);
|
2008-09-25 17:31:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in read-only mode using the specified file descriptor.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxFileInputStream(int fd);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxFileInputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOk() const;
|
2013-03-09 10:08:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the underlying file object.
|
|
|
|
@since 2.9.5
|
|
|
|
*/
|
|
|
|
wxFile* GetFile() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxFFileInputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04: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 09:43:31 -05:00
|
|
|
|
2008-09-25 17:31:45 -04: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 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxBufferedInputStream, wxFFileOutputStream, wxFileOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxFFileInputStream : public wxInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 13:26:35 -05: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 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxFFileInputStream(const wxString& filename,
|
|
|
|
const wxString& mode = "rb");
|
2008-09-25 17:31:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in read-only mode using the file I/O object file.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxFFileInputStream(wxFFile& file);
|
2008-09-25 17:31:45 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes a file stream in read-only mode using the specified file pointer @a fp.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
wxFFileInputStream(FILE* fp);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxFFileInputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the stream is initialized and ready.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOk() const;
|
2013-03-09 10:08:44 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the underlying file object.
|
|
|
|
@since 2.9.5
|
|
|
|
*/
|
|
|
|
wxFFile* GetFile() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxFFileStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2019-01-25 21:14:20 -05:00
|
|
|
This stream allows both reading from and writing to a file using buffered
|
2009-12-27 14:39:55 -05:00
|
|
|
STDIO functions.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-09-25 17:31:45 -04:00
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-12-27 14:39:55 -05:00
|
|
|
@see wxFFileInputStream, wxFFileOutputStream, wxFileStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-12-27 14:39:55 -05:00
|
|
|
class wxFFileStream : public wxFFileInputStream,
|
|
|
|
public wxFFileOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-01-08 13:26:35 -05:00
|
|
|
Initializes a new file stream in the given @a mode using the specified
|
|
|
|
@a iofileName name.
|
2009-12-27 14:39:55 -05:00
|
|
|
|
2009-01-08 13:26:35 -05:00
|
|
|
@warning
|
|
|
|
You should use wxStreamBase::IsOk() to verify if the constructor succeeded.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-06-15 13:34:50 -04:00
|
|
|
wxFFileStream(const wxString& iofileName, const wxString& mode = "w+b");
|
2009-12-27 14:39:55 -05: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 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxFileStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-12-27 14:39:55 -05: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 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-09-25 17:31:45 -04:00
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-12-27 14:39:55 -05:00
|
|
|
@see wxFileInputStream, wxFileOutputStream, wxFFileStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-12-27 14:39:55 -05:00
|
|
|
class wxFileStream : public wxFileOutputStream,
|
|
|
|
public wxFileInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
Initializes a new file stream in read-write mode using the specified
|
2009-01-08 13:26:35 -05:00
|
|
|
@a iofileName name.
|
2009-12-27 14:39:55 -05:00
|
|
|
|
2009-01-08 13:26:35 -05:00
|
|
|
@warning
|
2009-12-27 14:39:55 -05:00
|
|
|
You should use IsOk() to verify if the constructor succeeded.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxFileStream(const wxString& iofileName);
|
2009-12-27 14:39:55 -05: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 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|