ThePEG::CFileLineReader Class Reference

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

#include <CFileLineReader.h>

List of all members.

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.
string getline () const
 Return a string containing what is left of the line buffer.
FILE * 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.
Standard constructors and destructors.
 CFileLineReader ()
 The default constructor.
 CFileLineReader (FILE *f, int len=defsize)
 Constructor taking a c-file f opened from the outside as argument.
 CFileLineReader (string filename, int len=defsize)
 Constructor taking a filename as argument.
 ~CFileLineReader ()
 The destructor.
Initialization functions.
void open (FILE *f)
 Initialize with a c-file f opened from the outside.
void open (string filename)
 Initialize with a filename.
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 Types

enum  StreamType { unknown, plainfile, pipe }
 Enumerate different kinds of c-files. More...

Private Member Functions

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

Private Attributes

FILE * 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.
StreamType type
 The type of the c-file used.

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 41 of file CFileLineReader.h.


Member Enumeration Documentation

Enumerate different kinds of c-files.

Enumerator:
unknown  Unknown type opened from the outside.

plainfile  A plain file opened with fopen().

pipe  A pipe opened with popen().

Definition at line 189 of file CFileLineReader.h.


Constructor & Destructor Documentation

ThePEG::CFileLineReader::CFileLineReader ( FILE *  f,
int  len = defsize 
)

Constructor taking a c-file f opened from the outside as argument.

Optionally the size len of the line buffer can be specified.

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

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.

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.

Returns:
true if the given character was found.

CFileLineReader& ThePEG::CFileLineReader::operator= ( const CFileLineReader  )  [private]

The assignment operator is private and must never be called.

In fact, it should not even be implemented.


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

Generated on Thu Apr 29 12:43:23 2010 for ThePEG by  doxygen 1.5.5