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

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

#include <File.h>

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

Public Member Functions

 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.
 

Detailed Description

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

Constructor & Destructor Documentation

RC::FileRead::FileRead ( const RStr filename)
inline

Opens the file specified by filename for reading.

Throws ErrorMsgFile if the file could not be opened.

Member Function Documentation

template<class T >
bool RC::FileRead::Get ( T &  data)
inline

Gets data of type T, after passing through FileGetWrapper.

Returns
True if the read succeeded.
bool RC::FileRead::Get ( RStr data,
bool  crop_newline = true 
)
inline

Gets one line into data, up to the newline, null, or end of file, removing the newline if crop_newline is true.

Returns
True if the read succeeded.
bool RC::FileRead::Get ( Data1D< RStr > &  data,
bool  crop_newlines = true 
)
inline

Fill data with lines from the file, removing the newlines if crop_newlines is true.

Returns
True if the reads succeeded.
template<class T >
bool RC::FileRead::Get ( Data1D< T > &  data)
inline

Fill data with elements of type T, calling Get on each one.

Returns
True if the reads succeeded.
template<class T >
bool RC::FileRead::Get ( Data2D< T > &  data)
inline

Fill data with elements of type T, calling Get on each one.

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

Returns
True if the reads succeeded.
template<class T >
bool RC::FileRead::Get ( Data3D< T > &  data)
inline

Fill data with elements of type T, calling Get on each one.

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

Returns
True if the reads succeeded.
bool RC::FileRead::GetAll ( Data1D< RStr > &  data,
bool  crop_newlines = true 
)
inline

Fill data with all lines from the file until the end, removing the newlines if crop_newlines is true.

Returns
True if the reads succeeded.
template<class T >
bool RC::FileRead::GetAll ( Data1D< T > &  data)
inline

Fill data with all elements of type T until the end of file, calling Get on each one.

Returns
True if the reads succeeded.
bool RC::FileRead::Open ( const RStr filename)
inline

Opens the file specified by filename for reading.

Returns
True if the file was successfully opened.
template<class T >
bool RC::FileRead::RawGet ( T &  data)
inline

Performs a buffered read of sizeof(T) bytes and assigns them to data.

Returns
True if the read succeeded.
template<class T >
size_t RC::FileRead::Read ( Data1D< T > &  data,
const size_t  amnt_to_read 
)
inline

Reads amnt_to_read elements of plain old data type T into data without buffering, resizing if too small.

Throws ErrorMsgFile if there was an error reading.

Returns
The number of elements successfully read.
template<class T >
size_t RC::FileRead::Read ( Data1D< T > &  data)
inline

Fills data with plain old data type T without buffering.

Throws ErrorMsgFile if there was an error reading.

Returns
The number of elements successfully read.
bool RC::FileRead::ReadLine ( RStr line,
bool  crop_newline = true 
)
inline

Reads one line until newline, null, or end of file. The newline is removed if crop_newline is true.

Throws ErrorMsgFile if there was a read error.

Returns
True if the read was successful.

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