![]() |
Plasma Engine
2.0
|
The default class to use to write data to a file, implements the plStreamWriter interface. More...
#include <FileWriter.h>
Public Member Functions | |
plFileWriter ()=default | |
Constructor, does nothing. | |
~plFileWriter () | |
Destructor, closes the file, if it is still open (RAII). | |
plResult | Open (plStringView sFile, plUInt32 uiCacheSize=1024 *1024, plFileShareMode::Enum fileShareMode=plFileShareMode::Default, bool bAllowFileEvents=true) |
Opens the given file for writing. Returns PL_SUCCESS if the file could be opened. A cache is created to speed up small writes. | |
void | Close () |
Closes the file, if it is open. | |
virtual plResult | WriteBytes (const void *pWriteBuffer, plUInt64 uiBytesToWrite) override |
Writes the given number of bytes to the file. Returns PL_SUCCESS if all bytes were successfully written. | |
virtual plResult | Flush () override |
Will write anything that's currently in the write-cache to disk. Will decrease performance if used excessively. | |
![]() | |
plString128 | GetFilePathAbsolute () const |
Returns the absolute path with which the file was opened (including the prefix of the data directory). | |
plString128 | GetFilePathRelative () const |
Returns the relative path of the file within its data directory (excluding the prefix of the data directory). | |
plDataDirectoryType * | GetDataDirectory () const |
Returns the plDataDirectoryType over which this file has been opened. | |
bool | IsOpen () const |
Returns true, if the file is currently open. | |
plUInt64 | GetFileSize () const |
Returns the current total size of the file. | |
![]() | |
plStreamWriter () | |
Constructor. | |
virtual | ~plStreamWriter () |
Virtual destructor to ensure correct cleanup. | |
template<typename T > | |
plResult | WriteWordValue (const T *pWordValue) |
Helper method to write a word value correctly (copes with potentially different endianess) | |
template<typename T > | |
plResult | WriteDWordValue (const T *pDWordValue) |
Helper method to write a dword value correctly (copes with potentially different endianess) | |
template<typename T > | |
plResult | WriteQWordValue (const T *pQWordValue) |
Helper method to write a qword value correctly (copes with potentially different endianess) | |
PL_ALWAYS_INLINE void | WriteVersion (plTypeVersion version) |
Writes a type version to the stream. | |
template<typename ArrayType , typename ValueType > | |
plResult | WriteArray (const plArrayBase< ValueType, ArrayType > &array) |
Writes an array of elements to the stream. | |
template<typename ValueType , plUInt16 uiSize> | |
plResult | WriteArray (const plSmallArrayBase< ValueType, uiSize > &array) |
Writes a small array of elements to the stream. | |
template<typename ValueType , plUInt32 uiSize> | |
plResult | WriteArray (const ValueType(&array)[uiSize]) |
Writes a C style fixed array. | |
template<typename KeyType , typename Comparer > | |
plResult | WriteSet (const plSetBase< KeyType, Comparer > &set) |
Writes a set. | |
template<typename KeyType , typename ValueType , typename Comparer > | |
plResult | WriteMap (const plMapBase< KeyType, ValueType, Comparer > &map) |
Writes a map. | |
template<typename KeyType , typename ValueType , typename Hasher > | |
plResult | WriteHashTable (const plHashTableBase< KeyType, ValueType, Hasher > &hashTable) |
Writes a hash table (note that the entry order might change on read) | |
plResult | WriteString (const plStringView sStringView) |
Writes a string. | |
Additional Inherited Members | |
![]() | |
plDataDirectoryWriter * | GetFileWriter (plStringView sFile, plFileShareMode::Enum FileShareMode, bool bAllowFileEvents) |
![]() | |
plDataDirectoryWriter * | m_pDataDirWriter |
The default class to use to write data to a file, implements the plStreamWriter interface.
This file writer buffers writes up to a certain amount of bytes (configurable). It closes the file automatically once it goes out of scope.
|
overridevirtual |
Will write anything that's currently in the write-cache to disk. Will decrease performance if used excessively.
Reimplemented from plStreamWriter.
plResult plFileWriter::Open | ( | plStringView | sFile, |
plUInt32 | uiCacheSize = 1024 * 1024, | ||
plFileShareMode::Enum | fileShareMode = plFileShareMode::Default, | ||
bool | bAllowFileEvents = true ) |
Opens the given file for writing. Returns PL_SUCCESS if the file could be opened. A cache is created to speed up small writes.
You should typically not disable bAllowFileEvents, unless you need to prevent recursive file events, which is only the case, if you are doing file accesses from within a File Event Handler.
|
overridevirtual |
Writes the given number of bytes to the file. Returns PL_SUCCESS if all bytes were successfully written.
As this class buffers writes with an internal cache, PL_SUCCESS does NOT mean that the data is actually written to disk.
Implements plStreamWriter.