thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
ThePEG::CFileLineReader Class Reference

CFileLineReader is a wrapper around a standard C FILE stream. More...

#include <CFileLineReader.h>

Public Member Functions

bool readline ()
 Read a line from the underlying c-file into the line buffer.
 
void resetline ()
 Undo reading from the current line, ie. More...
 
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. More...
 
bool find (string str) const
 Check if a given string is present in the current line buffer.
 
Standard constructors and destructors.
 CFileLineReader ()
 The default constructor.
 
 CFileLineReader (string filename, int len=defsize)
 Constructor taking a filename as argument. More...
 
 ~CFileLineReader ()
 The destructor.
 
Initialization functions.
void open (string filename)
 Initialize with a filename. More...
 
void close ()
 If the file was opened from within this object, close it.
 
Operators to read from the line buffer.
char getc ()
 Return the next character of the line-buffer.
 
CFileLineReaderoperator>> (long &l)
 Read a long from the line buffer.
 
CFileLineReaderoperator>> (int &i)
 Read an int from the line buffer.
 
CFileLineReaderoperator>> (unsigned long &l)
 Read an unsigned long from the line buffer.
 
CFileLineReaderoperator>> (unsigned int &i)
 Read an unsigned int from the line buffer.
 
CFileLineReaderoperator>> (double &d)
 Read a double from the line buffer.
 
CFileLineReaderoperator>> (float &f)
 Read a float from the line buffer.
 
CFileLineReaderoperator>> (std::string &s)
 Read a (whitespace delimited) string from the line buffer.
 

Private Member Functions

 CFileLineReader (const CFileLineReader &)
 The copy constructor is private and not implemented.
 
CFileLineReaderoperator= (const CFileLineReader &)=delete
 The assignment operator is private and must never be called. More...
 

Private Attributes

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 Private Attributes

static const int defsize = 1024
 The default size of the buffer.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CFileLineReader()

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.

Member Function Documentation

◆ open()

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.

◆ operator=()

CFileLineReader& ThePEG::CFileLineReader::operator= ( const CFileLineReader )
privatedelete

The assignment operator is private and must never be called.

In fact, it should not even be implemented.

◆ resetline()

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.

◆ skip()

bool ThePEG::CFileLineReader::skip ( char  c)

Scan forward up and until the first occurrence of the given character.

Returns
true if the given character was found.

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