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

A file class for both reading and writing that provides buffered and unbuffered output to files. More...

#include <File.h>

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

Public Member Functions

 FileRW ()
 Default constructor.
 
 FileRW (const RStr &filename, const WriteMode mode=KEEP)
 Opens the file specified by filename for reading and writing, using the WriteMode specified by mode. More...
 
 FileRW (FILE *fp, bool do_close)
 Wraps the FILE* fp for reading and writing. It will close it when finished if do_close is true.
 
 FileRW (FILE *fp)
 Wraps the FILE* fp for reading and writing. It will close it when finished unless fp is stdin/stdout/stderr.
 
 FileRW (const FileBase &other)
 Base copy constructor.
 
bool Open (const RStr &filename, const WriteMode mode=KEEP)
 Opens the file specified by filename for reading and writing, using the WriteMode specified by mode. More...
 
void Open (FILE *fp, bool do_close)
 Wraps the FILE* fp for reading and writing. It will close it when finished if do_close is true.
 
void Open (FILE *fp)
 Wraps the FILE* fp for reading and writing. It will close it when finished unless fp is stdin/stdout/stderr.
 
- Public Member Functions inherited from RC::FileRead
 FileRead ()
 Default constructor.
 
 FileRead (const RStr &filename)
 Opens the file specified by filename for reading. More...
 
 FileRead (FILE *fp, bool do_close)
 Wraps the FILE* fp for reading. It will close it when finished if do_close is true.
 
 FileRead (FILE *fp)
 Wraps the FILE* fp for reading. It will close it when finished unless fp is stdin.
 
 FileRead (const FileBase &other)
 Base copy constructor.
 
bool Open (const RStr &filename)
 Opens the file specified by filename for reading. More...
 
void Open (FILE *fp, bool do_close)
 Wraps the FILE* fp for reading. It will close it when finished if do_close is true.
 
void Open (FILE *fp)
 Wraps the FILE* fp for reading. It will close it when finished unless fp is stdin.
 
template<class T >
size_t Read (Data1D< T > &data, const size_t amnt_to_read)
 Reads amnt_to_read elements of plain old data type T into data without buffering, resizing if too small. More...
 
template<class T >
size_t Read (Data1D< T > &data)
 Fills data with plain old data type T without buffering. More...
 
template<class T >
void ReadAll (Data1D< T > &data)
 Reads all data until the end of file into data as plain old data type T.
 
bool ReadLine (RStr &line, bool crop_newline=true)
 Reads one line until newline, null, or end of file. The newline is removed if crop_newline is true. More...
 
bool Read (RStr &line, bool crop_newline=true)
 Does ReadLine.
 
bool SkipLine ()
 Discards one line until newline, null, or end of file.
 
void ReadAllLines (Data1D< RStr > &lines, bool crop_newlines=true)
 Reads all the lines found until the end of the file. If crop_newlines is true they are removed from each line.
 
void ReadAll (Data1D< RStr > &lines, bool crop_newlines=true)
 Does ReadAllLines.
 
template<class T >
bool RawGet (T &data)
 Performs a buffered read of sizeof(T) bytes and assigns them to data. More...
 
template<class T >
bool Get (T &data)
 Gets data of type T, after passing through FileGetWrapper. More...
 
bool Get (RStr &data, bool crop_newline=true)
 Gets one line into data, up to the newline, null, or end of file, removing the newline if crop_newline is true. More...
 
bool Get (Data1D< RStr > &data, bool crop_newlines=true)
 Fill data with lines from the file, removing the newlines if crop_newlines is true. More...
 
template<class T >
bool Get (Data1D< T > &data)
 Fill data with elements of type T, calling Get on each one. More...
 
template<class T >
bool Get (Data2D< T > &data)
 Fill data with elements of type T, calling Get on each one. More...
 
template<class T >
bool Get (Data3D< T > &data)
 Fill data with elements of type T, calling Get on each one. More...
 
bool GetAll (Data1D< RStr > &data, bool crop_newlines=true)
 Fill data with all lines from the file until the end, removing the newlines if crop_newlines is true. More...
 
template<class T >
bool GetAll (Data1D< T > &data)
 Fill data with all elements of type T until the end of file, calling Get on each one. More...
 
- 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.
 
- Public Member Functions inherited from RC::FileWrite
 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.
 

Detailed Description

A file class for both reading and writing that provides buffered and unbuffered output to files.

Constructor & Destructor Documentation

◆ FileRW()

RC::FileRW::FileRW ( const RStr filename,
const WriteMode  mode = KEEP 
)
inline

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

Throws ErrorMsgFile if the file could not be opened.

Member Function Documentation

◆ Open()

bool RC::FileRW::Open ( const RStr filename,
const WriteMode  mode = KEEP 
)
inline

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

Returns
True if the file was successfully opened.

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