xoreos  0.0.5
Public Member Functions | Protected Attributes | List of all members
Common::WriteFile Class Reference

A simple streaming file writing class. More...

#include <writefile.h>

Inheritance diagram for Common::WriteFile:
Inheritance graph
[legend]
Collaboration diagram for Common::WriteFile:
Collaboration graph
[legend]

Public Member Functions

 WriteFile ()
 
 WriteFile (const UString &fileName)
 
 ~WriteFile ()
 
bool open (const UString &fileName)
 Try to open the file with the given fileName. More...
 
void close ()
 Close the file, if open. More...
 
bool isOpen () const
 Checks if the object opened a file successfully. More...
 
void flush ()
 Commit any buffered data to the underlying channel or storage medium; unbuffered streams can use the default implementation. More...
 
size_t write (const void *dataPtr, size_t dataSize)
 Write data into the stream. More...
 
size_t size () const
 Return the number of bytes written to the current file in total. More...
 
size_t pos () const
 Return the current position ot the stream in the file. More...
 
size_t seek (ptrdiff_t offset, Origin whence=SeekableWriteStream::kOriginBegin)
 Seek to the speciied offset from the specified origin. More...
 
- Public Member Functions inherited from Common::SeekableWriteStream
 SeekableWriteStream ()
 
 ~SeekableWriteStream ()
 
virtual size_t skip (ptrdiff_t offset)
 Skip the specified number of bytes, adding that offset to the current position in the stream. More...
 
- Public Member Functions inherited from Common::WriteStream
 WriteStream ()
 
virtual ~WriteStream ()
 
void writeByte (byte value)
 
void writeSByte (int8 value)
 
void writeUint16LE (uint16 value)
 
void writeUint32LE (uint32 value)
 
void writeUint64LE (uint64 value)
 
void writeUint16BE (uint16 value)
 
void writeUint32BE (uint32 value)
 
void writeUint64BE (uint64 value)
 
void writeBytes (byte value, size_t n)
 Write n bytes of value to the stream. More...
 
FORCEINLINE void writeZeros (size_t n)
 Write n zeros to the stream. More...
 
FORCEINLINE void writeSint16LE (int16 value)
 
FORCEINLINE void writeSint32LE (int32 value)
 
FORCEINLINE void writeSint64LE (int64 value)
 
FORCEINLINE void writeSint16BE (int16 value)
 
FORCEINLINE void writeSint32BE (int32 value)
 
FORCEINLINE void writeSint64BE (int64 value)
 
FORCEINLINE void writeIEEEFloatLE (float value)
 
FORCEINLINE void writeIEEEFloatBE (float value)
 
FORCEINLINE void writeIEEEDoubleLE (double value)
 
FORCEINLINE void writeIEEEDoubleBE (double value)
 
size_t writeStream (ReadStream &stream, size_t n)
 Copy n bytes of the given stream into the stream. More...
 
size_t writeStream (ReadStream &stream)
 Copy the complete contents of the given stream. More...
 
void writeString (const UString &str)
 Write the given string to the stream, encoded as UTF-8. More...
 

Protected Attributes

std::FILE * _handle
 The actual file handle. More...
 
size_t _size
 

Additional Inherited Members

- Public Types inherited from Common::SeekableWriteStream
enum  Origin { kOriginBegin = 0, kOriginCurrent = 1, kOriginEnd = 2, kOriginMAX }
 The position a seeking offset takes as a base. More...
 
- Static Public Member Functions inherited from Common::SeekableWriteStream
static size_t evalSeek (ptrdiff_t offset, Origin whence, size_t pos, size_t begin, size_t size)
 Evaluate the seek offset relative to whence into a position from the beginning. More...
 

Detailed Description

A simple streaming file writing class.

Definition at line 40 of file writefile.h.

Constructor & Destructor Documentation

◆ WriteFile() [1/2]

Common::WriteFile::WriteFile ( )

Definition at line 35 of file writefile.cpp.

◆ WriteFile() [2/2]

Common::WriteFile::WriteFile ( const UString fileName)

Definition at line 38 of file writefile.cpp.

References Common::UString::c_str(), and open().

Here is the call graph for this function:

◆ ~WriteFile()

Common::WriteFile::~WriteFile ( )

Definition at line 43 of file writefile.cpp.

References close().

Here is the call graph for this function:

Member Function Documentation

◆ close()

void Common::WriteFile::close ( )

◆ flush()

void Common::WriteFile::flush ( )
virtual

Commit any buffered data to the underlying channel or storage medium; unbuffered streams can use the default implementation.

When flushing fails, a kWriteError exception is thrown.

Reimplemented from Common::WriteStream.

Definition at line 83 of file writefile.cpp.

References _handle, and Common::kWriteError.

Referenced by close(), Aurora::ResourceManager::dumpResourcesList(), Engines::dumpStream(), Common::DebugManager::logString(), Engines::ConsoleWindow::printLine(), Engines::ConsoleWindow::setRedirect(), Graphics::writeBMP(), and Engines::ConsoleWindow::~ConsoleWindow().

Here is the caller graph for this function:

◆ isOpen()

bool Common::WriteFile::isOpen ( ) const

Checks if the object opened a file successfully.

Returns
true if any file is opened, false otherwise.

Definition at line 79 of file writefile.cpp.

References _handle.

Referenced by Common::DebugManager::logString(), and Engines::ConsoleWindow::printLine().

Here is the caller graph for this function:

◆ open()

bool Common::WriteFile::open ( const UString fileName)

◆ pos()

size_t Common::WriteFile::pos ( ) const
virtual

Return the current position ot the stream in the file.

Implements Common::SeekableWriteStream.

Definition at line 108 of file writefile.cpp.

References _handle.

Referenced by seek(), and write().

Here is the caller graph for this function:

◆ seek()

size_t Common::WriteFile::seek ( ptrdiff_t  offset,
SeekableWriteStream::Origin  whence = SeekableWriteStream::kOriginBegin 
)
virtual

Seek to the speciied offset from the specified origin.

Implements Common::SeekableWriteStream.

Definition at line 112 of file writefile.cpp.

References _handle, _size, Common::SeekableWriteStream::evalSeek(), Common::kSeekError, pos(), and size().

Here is the call graph for this function:

◆ size()

size_t Common::WriteFile::size ( ) const
virtual

Return the number of bytes written to the current file in total.

Implements Common::SeekableWriteStream.

Definition at line 104 of file writefile.cpp.

References _size.

Referenced by seek(), and write().

Here is the caller graph for this function:

◆ write()

size_t Common::WriteFile::write ( const void *  dataPtr,
size_t  dataSize 
)
virtual

Write data into the stream.

Subclasses must implement this method; all other write methods are implemented using it.

Parameters
dataPtrpointer to the data to be written.
dataSizenumber of bytes to be written.
Returns
the number of bytes which were actually written.

Implements Common::WriteStream.

Definition at line 91 of file writefile.cpp.

References _handle, _size, pos(), and size().

Referenced by Graphics::writeBMP().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _handle

std::FILE* Common::WriteFile::_handle
protected

The actual file handle.

Definition at line 76 of file writefile.h.

Referenced by close(), flush(), isOpen(), open(), pos(), seek(), and write().

◆ _size

size_t Common::WriteFile::_size
protected

Definition at line 78 of file writefile.h.

Referenced by close(), seek(), size(), and write().


The documentation for this class was generated from the following files: