rcolyer.net
RC Lib  Version 202403231100
Public Member Functions | List of all members
RC::FileWrite Class Reference

A file writing class that provides buffered and unbuffered output to files with support for non-POD classes. More...

#include <File.h>

Inheritance diagram for RC::FileWrite:
RC::FileBase RC::FileRW

Public Member Functions

 FileWrite ()
 Default constructor.
 
 FileWrite (const RStr &filename, const WriteMode mode=TRUNCATE)
 Opens the file specified by filename for writing, using the WriteMode specified by mode. More...
 
 FileWrite (FILE *fp, bool do_close)
 Wraps the FILE* fp for writing. It will close it when finished if do_close is true.
 
 FileWrite (FILE *fp)
 Wraps the FILE* fp for writing. It will close it when finished unless fp is stdout.
 
 FileWrite (const FileBase &other)
 Base copy constructor.
 
bool Open (const RStr &filename, const WriteMode mode=TRUNCATE)
 Opens the file specified by filename for writing, using the WriteMode specified by mode. More...
 
void Open (FILE *fp, bool do_close)
 Wraps the FILE* fp for writing. It will close it when finished if do_close is true.
 
void Open (FILE *fp)
 Wraps the FILE* fp for writing. It will close it when finished unless fp is stdout or stderr.
 
template<class T >
void Write (const Data1D< T > &data, const size_t amnt_to_write)
 Writes amnt_to_write elements of plain old data type T from data without buffering. More...
 
template<class T >
void Write (const Data1D< T > &data)
 Writes all of data's plain old data type T without buffering. More...
 
void WriteStr (const char *str)
 Writes the null-terminated contents of str without buffering. More...
 
void WriteStr (const RStr &str)
 Writes the RStr str without buffering. More...
 
void WriteAllStr (const Data1D< RStr > &lines, const bool add_newlines)
 Writes all lines without buffering, adding a newline after each if add_newlines is true. More...
 
template<class T >
void RawPut (const T &data)
 Performs a buffered write of sizeof(T) raw bytes extracted from data.
 
template<class T >
void Put (const T &data)
 Puts data of type T into the write buffer, after passing through FilePutWrapper.
 
void Put (const char *str)
 Puts the null-terminated character data str into the write buffer, excluding the null.
 
void Put (const RStr &str)
 Puts the RStr str into the write buffer.
 
template<class T >
void Put (const Data1D< T > &data)
 Calls Put for each element of data.
 
template<class T >
void Put (const Data2D< T > &data)
 Calls Put for each element of data. More...
 
template<class T >
void Put (const Data3D< T > &data)
 Calls Put for each element of data. More...
 
void Put (const Data1D< RStr > &data, const bool add_newline)
 Puts each RStr in data into the write buffer, adding newlines to each if add_newline is true.
 
FileWriteoperator<< (FileRead &read)
 Get all the remaining data from the FileRead, and Put it to this FileWrite.
 
- Public Member Functions inherited from RC::FileBase
 FileBase ()
 Default constructor.
 
 FileBase (const FileBase &other)
 Copy constructor.
 
FileBaseoperator= (const FileBase &other)
 Assignment operator.
 
virtual ~FileBase ()
 Flushes the write buffer before destructing. This will close the file if it is the last FileBase sharing it.
 
RStr GetFilename () const
 Returns the filename if one was given upon opening.
 
void SetFilename (const RStr &newfilename) const
 Manually changes the associated filename.
 
void Close ()
 Flushes the buffers and closes the file.
 
bool IsOpen () const
 True if the file is open.
 
bool IsClosed () const
 True if the file is closed.
 
bool IsReadable () const
 True if the file is open and readable.
 
bool IsWritable () const
 True if the file is open and writable.
 
FILE * Raw () const
 Returns a raw FILE* which can be used with the C file functions.
 
void Assert () const
 Throws ErrorMsgFile if the file is closed.
 
size_t Size () const
 Returns the file size in bytes.
 
void SetPosition (const size_t pos)
 Sets the reading and writing position to pos bytes into the file.
 
void RelativePosition (const i64 amnt)
 Sets the position for the next read or write operation. More...
 
size_t GetPosition (bool quiet_fail=false) const
 Gets the position for the next read or write operation. More...
 
void Rewind ()
 Clears the read-ahead buffer used by FileRead::Get calls.
 
void Flush ()
 Flushes all unsaved data to the storage system.
 
void ClearBuffer ()
 Processes the remaining data in the Put/Get buffer.
 

Detailed Description

A file writing class that provides buffered and unbuffered output to files with support for non-POD classes.

Constructor & Destructor Documentation

◆ FileWrite()

RC::FileWrite::FileWrite ( const RStr filename,
const WriteMode  mode = TRUNCATE 
)
inline

Opens the file specified by filename for writing, using the WriteMode specified by mode.

Throws ErrorMsgFile if the file could not be opened.

Member Function Documentation

◆ Open()

bool RC::FileWrite::Open ( const RStr filename,
const WriteMode  mode = TRUNCATE 
)
inline

Opens the file specified by filename for writing, using the WriteMode specified by mode.

Returns
True if the file was successfully opened.

◆ Put() [1/2]

template<class T >
void RC::FileWrite::Put ( const Data2D< T > &  data)
inline

Calls Put for each element of data.

For data[y][x], x is the inner loop.

◆ Put() [2/2]

template<class T >
void RC::FileWrite::Put ( const Data3D< T > &  data)
inline

Calls Put for each element of data.

For data[z][y][x], x is the inner loop.

◆ Write() [1/2]

template<class T >
void RC::FileWrite::Write ( const Data1D< T > &  data)
inline

Writes all of data's plain old data type T without buffering.

Throws ErrorMsgFile if there was an error writing.

◆ Write() [2/2]

template<class T >
void RC::FileWrite::Write ( const Data1D< T > &  data,
const size_t  amnt_to_write 
)
inline

Writes amnt_to_write elements of plain old data type T from data without buffering.

Throws ErrorMsgFile if there was an error writing.

◆ WriteAllStr()

void RC::FileWrite::WriteAllStr ( const Data1D< RStr > &  lines,
const bool  add_newlines 
)
inline

Writes all lines without buffering, adding a newline after each if add_newlines is true.

Throws ErrorMsgFile if there was a write error.

◆ WriteStr() [1/2]

void RC::FileWrite::WriteStr ( const char *  str)
inline

Writes the null-terminated contents of str without buffering.

Throws ErrorMsgFile if there was a write error.

◆ WriteStr() [2/2]

void RC::FileWrite::WriteStr ( const RStr str)
inline

Writes the RStr str without buffering.

Throws ErrorMsgFile if there was a write error.


The documentation for this class was generated from the following file:
email address
— (c) 2015