zz::fs::FileReader Class Reference

The FileReader class for read-only operations. This class is derived from UnCopyable, so no copy operation. Move operation is allowed by std::move();. More...

#include <zupply.hpp>

Inheritance diagram for zz::fs::FileReader:
zz::UnCopyable

Public Member Functions

 FileReader (std::string filename, int retryTimes=consts::kDefaultFileOpenRetryTimes, int retryInterval=consts::kDefaultFileOpenRetryInterval)
 FileReader constructor. More...
 
std::string filename () const
 FileReader move constructor. More...
 
bool is_open () const
 Check if is opened. More...
 
bool is_valid () const
 Check if valid filename is set. More...
 
void close ()
 Close file handler.
 
std::size_t file_size ()
 Get file size in byte, member function. More...
 
std::size_t count_lines ()
 Count number of lines in text file. More...
 
std::string next_line (bool trimWhiteSpaces=false)
 Get next line. More...
 
int goto_line (int n)
 Count number of lines in text file If reached end of file, will return the number of lines. More...
 

Detailed Description

The FileReader class for read-only operations. This class is derived from UnCopyable, so no copy operation. Move operation is allowed by std::move();.

Constructor & Destructor Documentation

zz::fs::FileReader::FileReader ( std::string  filename,
int  retryTimes = consts::kDefaultFileOpenRetryTimes,
int  retryInterval = consts::kDefaultFileOpenRetryInterval 
)

FileReader constructor.

Parameters
filename
retryTimesRetry open times
retryIntervalRetry interval in ms

Member Function Documentation

std::size_t zz::fs::FileReader::count_lines ( )

Count number of lines in text file.

Returns
Number of lines
std::size_t zz::fs::FileReader::file_size ( )

Get file size in byte, member function.

Returns
File size in byte
std::string zz::fs::FileReader::filename ( ) const
inline

FileReader move constructor.

Parameters
other

Return filename

Returns
Filename
int zz::fs::FileReader::goto_line ( int  n)

Count number of lines in text file If reached end of file, will return the number of lines.

Parameters
nLine # to jump to
Returns
-1 if failed, otherwise return the position actually jumped to
bool zz::fs::FileReader::is_open ( ) const
inline

Check if is opened.

Returns
True if opened
bool zz::fs::FileReader::is_valid ( ) const
inline

Check if valid filename is set.

Returns
True if valid
std::string zz::fs::FileReader::next_line ( bool  trimWhiteSpaces = false)

Get next line.

Parameters
trimWhitespacesWhether or not trim whitespaces
Returns
A std::string of the line

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