ThePEG 2.3.0
|
CFileLineReader is a wrapper around a standard C FILE stream. More...
#include <CFileLineReader.h>
Public Member Functions | |
Standard constructors and destructors. | |
CFileLineReader () | |
The default constructor. | |
CFileLineReader (string filename, int len=defsize) | |
Constructor taking a filename as argument. | |
~CFileLineReader () | |
The destructor. | |
Initialization functions. | |
void | open (string filename) |
Initialize with a filename. | |
void | close () |
If the file was opened from within this object, close it. | |
bool | readline () |
Read a line from the underlying c-file into the line buffer. | |
void | resetline () |
Undo reading from the current line, ie. | |
string | getline () const |
Return a string containing what is left of the line buffer. | |
CFile | cFile () const |
Return the underlying c-file. | |
operator void * () | |
Return null if a previous read failed. | |
bool | operator! () |
Return true if a previous read failed. | |
bool | skip (char c) |
Scan forward up and until the first occurrence of the given character. | |
bool | find (string str) const |
Check if a given string is present in the current line buffer. | |
Operators to read from the line buffer. | |
CFile | file |
The c-file to be read from. | |
int | bufflen |
The length of the line buffer. | |
char * | buff |
The line buffer. | |
char * | pos |
The current position in the line buffer. | |
bool | bad |
The current state is bad if a read has failed. | |
static const int | defsize = 1024 |
The default size of the buffer. | |
char | getc () |
Return the next character of the line-buffer. | |
CFileLineReader & | operator>> (long &l) |
Read a long from the line buffer. | |
CFileLineReader & | operator>> (int &i) |
Read an int from the line buffer. | |
CFileLineReader & | operator>> (unsigned long &l) |
Read an unsigned long from the line buffer. | |
CFileLineReader & | operator>> (unsigned int &i) |
Read an unsigned int from the line buffer. | |
CFileLineReader & | operator>> (double &d) |
Read a double from the line buffer. | |
CFileLineReader & | operator>> (float &f) |
Read a float from the line buffer. | |
CFileLineReader & | operator>> (std::string &s) |
Read a (whitespace delimited) string from the line buffer. | |
CFileLineReader (const CFileLineReader &) | |
The copy constructor is private and not implemented. | |
CFileLineReader & | operator= (const CFileLineReader &)=delete |
The assignment operator is private and must never be called. | |
CFileLineReader is a wrapper around a standard C FILE stream.
With it one reads one line at the time (with readline()) into an internal buffer from which one can then read as from a standard std::istream with a limited set of operator>> functions. It can be thought of as an std::ifstream where the internal buffer must be filled by hand one line at the time.
Contrary to std::ifstream the CFileLineReader can also handle gipped files and pipes. Gzipped files are automatically handles by a pipe using the zcat
command if the file name ends with .gz
. Also if a file name ends with a |
sign, the preceding string is interpreted as a command defining a pipe from which to read.
Since CFileLineReader is very close to the standard C FILE stream it is in many cases much faster than eg. reading from lines via std::istringstream.
Definition at line 42 of file CFileLineReader.h.
ThePEG::CFileLineReader::CFileLineReader | ( | string | filename, |
int | len = defsize |
||
) |
Constructor taking a filename as argument.
Optionally the size len of the line buffer can be specified. If filename ends with .gz
a pipe is opened where the file is read by zcat
. If filename ends with a |
sign, the preceding string is interpreted as a command defining a pipe from which to read.
void ThePEG::CFileLineReader::open | ( | string | filename | ) |
Initialize with a filename.
If filename ends with .gz
a pipe is opened where the file is read by zcat
. If filename ends with a |
sign, the preceding string is interpreted as a command defining a pipe from which to read.
|
privatedelete |
The assignment operator is private and must never be called.
In fact, it should not even be implemented.
void ThePEG::CFileLineReader::resetline | ( | ) |
Undo reading from the current line, ie.
the next read will be from the beginning of the current line. Afterwards the state will be not bad.
bool ThePEG::CFileLineReader::skip | ( | char | c | ) |
Scan forward up and until the first occurrence of the given character.
|
private |
The current state is bad if a read has failed.
Definition at line 198 of file CFileLineReader.h.
|
private |
The line buffer.
Definition at line 188 of file CFileLineReader.h.
|
private |
The length of the line buffer.
Definition at line 183 of file CFileLineReader.h.
|
staticprivate |
The default size of the buffer.
Definition at line 203 of file CFileLineReader.h.
|
private |
The c-file to be read from.
Definition at line 178 of file CFileLineReader.h.
|
private |
The current position in the line buffer.
Definition at line 193 of file CFileLineReader.h.