Version: 3.2.5
wxTempFileOutputStream Class Reference

#include <wx/wfstream.h>

+ Inheritance diagram for wxTempFileOutputStream:

Detailed Description

wxTempFileOutputStream is an output stream based on wxTempFile.

It provides a relatively safe way to replace the contents of the existing file.

Library:  wxBase
Category:  Streams
See also
wxTempFile

Public Member Functions

 wxTempFileOutputStream (const wxString &fileName)
 Associates wxTempFileOutputStream with the file to be replaced and opens it. More...
 
virtual bool Commit ()
 Validate changes: deletes the old file of the given name and renames the new file to the old name. More...
 
virtual void Discard ()
 Discard changes: the old file contents are not changed, the temporary file is deleted. More...
 
- Public Member Functions inherited from wxOutputStream
 wxOutputStream ()
 Creates a dummy wxOutputStream object. More...
 
virtual ~wxOutputStream ()
 Destructor. More...
 
virtual bool Close ()
 Closes the stream, returning false if an error occurs. More...
 
virtual size_t LastWrite () const
 Returns the number of bytes written during the last Write(). More...
 
void PutC (char c)
 Puts the specified character in the output queue and increments the stream position. More...
 
virtual wxFileOffset SeekO (wxFileOffset pos, wxSeekMode mode=wxFromStart)
 Changes the stream current position. More...
 
virtual wxFileOffset TellO () const
 Returns the current stream position. More...
 
virtual wxOutputStreamWrite (const void *buffer, size_t size)
 Writes up to the specified amount of bytes using the data of buffer. More...
 
wxOutputStreamWrite (wxInputStream &stream_in)
 Reads data from the specified input stream and stores them in the current stream. More...
 
bool WriteAll (const void *buffer, size_t size)
 Writes exactly the specified number of bytes from the buffer. More...
 
- Public Member Functions inherited from wxStreamBase
 wxStreamBase ()
 Creates a dummy stream object. More...
 
virtual ~wxStreamBase ()
 Destructor. More...
 
wxStreamError GetLastError () const
 This function returns the last error. More...
 
virtual wxFileOffset GetLength () const
 Returns the length of the stream in bytes. More...
 
virtual size_t GetSize () const
 This function returns the size of the stream. More...
 
virtual bool IsOk () const
 Returns true if no error occurred on the stream. More...
 
virtual bool IsSeekable () const
 Returns true if the stream supports seeking to arbitrary offsets. More...
 
void Reset (wxStreamError error=wxSTREAM_NO_ERROR)
 Resets the stream state. More...
 
bool operator! () const
 Returns the opposite of IsOk(). More...
 

Additional Inherited Members

- Protected Member Functions inherited from wxOutputStream
size_t OnSysWrite (const void *buffer, size_t bufsize)
 Internal function. More...
 
- Protected Member Functions inherited from wxStreamBase
virtual wxFileOffset OnSysSeek (wxFileOffset pos, wxSeekMode mode)
 Internal function. More...
 
virtual wxFileOffset OnSysTell () const
 Internal function. More...
 

Constructor & Destructor Documentation

◆ wxTempFileOutputStream()

wxTempFileOutputStream::wxTempFileOutputStream ( const wxString fileName)

Associates wxTempFileOutputStream 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.

Member Function Documentation

◆ Commit()

virtual bool wxTempFileOutputStream::Commit ( )
virtual

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.

◆ Discard()

virtual void wxTempFileOutputStream::Discard ( )
virtual

Discard changes: the old file contents are not changed, the temporary file is deleted.