The Original CHomP Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
chomp::homology::textfile Class Reference

A class for reading text data from a text file. More...

#include <textfile.h>

Public Member Functions

 textfile ()
 The default constructor. More...
 
 textfile (std::istream &in)
 A constructor for an opened file. More...
 
int open (const char *filename)
 Opens a file with the given name. More...
 
void close ()
 Closes the file. More...
 
 ~textfile ()
 The destructor. More...
 
long readnumber (long defaultnumber=0, int ignorecolons=0)
 Read an integer number from the input file. More...
 
int checkchar ()
 Returns the first non-white character waiting to be read. More...
 
int readchar ()
 Read one non-white character from the file. More...
 
int readword (char *buf, int maxlength)
 Reads one word from the file and returns its actual length. More...
 
int readphrase (const char *phrase)
 Reads a strongly expected phrase from the file. More...
 
void ignoreline ()
 Ignore the current line from the current position to the end of line, including the end of line character. More...
 
long linenumber ()
 Returns the current line number. More...
 
 operator int ()
 Returns the text file's status: 0 = not opened, 1 = opened, 13 = initialized with an input stream. More...
 

Private Member Functions

void ignorespaces ()
 Ignores white characters and fills in the variable 'ch' with the first non-white character. More...
 

Private Attributes

int ch
 The character already read and waiting to be interpreted. More...
 
long line
 The current line number. More...
 
std::ifstream * fs
 The true file if it was opened. More...
 
std::istream * s
 A pointer to an input stream (usually equal to 'fs'). More...
 

Detailed Description

A class for reading text data from a text file.

All blank characters and comments are ignored. NOTE: This class is deprecated, it is recommended to use the class std::istream directly.

Definition at line 552 of file textfile.h.

Constructor & Destructor Documentation

◆ textfile() [1/2]

chomp::homology::textfile::textfile ( )

The default constructor.

◆ textfile() [2/2]

chomp::homology::textfile::textfile ( std::istream &  in)

A constructor for an opened file.

◆ ~textfile()

chomp::homology::textfile::~textfile ( )

The destructor.

Member Function Documentation

◆ checkchar()

int chomp::homology::textfile::checkchar ( )

Returns the first non-white character waiting to be read.

Returns EOF if end-of-file has been reached.

◆ close()

void chomp::homology::textfile::close ( )

Closes the file.

◆ ignoreline()

void chomp::homology::textfile::ignoreline ( )

Ignore the current line from the current position to the end of line, including the end of line character.

◆ ignorespaces()

void chomp::homology::textfile::ignorespaces ( )
private

Ignores white characters and fills in the variable 'ch' with the first non-white character.

◆ linenumber()

long chomp::homology::textfile::linenumber ( )

Returns the current line number.

◆ open()

int chomp::homology::textfile::open ( const char *  filename)

Opens a file with the given name.

Returns 1 if a file associated with this object has already been opened before, 0 on success, -1 in case of an error (no message is displayed).

◆ operator int()

chomp::homology::textfile::operator int ( )

Returns the text file's status: 0 = not opened, 1 = opened, 13 = initialized with an input stream.

◆ readchar()

int chomp::homology::textfile::readchar ( )

Read one non-white character from the file.

Return EOF if end-of-file has been reached.

◆ readnumber()

long chomp::homology::textfile::readnumber ( long  defaultnumber = 0,
int  ignorecolons = 0 
)

Read an integer number from the input file.

If none can be read, returns the suggested default value. If requested, ignores a preceding ':', '=' or ',' if any.

◆ readphrase()

int chomp::homology::textfile::readphrase ( const char *  phrase)

Reads a strongly expected phrase from the file.

Ignores white characters before the phrase and inside it. Returns 0 on success, -1 if the phrase was not present in the input (shows an error message in that case).

◆ readword()

int chomp::homology::textfile::readword ( char *  buf,
int  maxlength 
)

Reads one word from the file and returns its actual length.

Member Data Documentation

◆ ch

int chomp::homology::textfile::ch
private

The character already read and waiting to be interpreted.

Definition at line 611 of file textfile.h.

◆ fs

std::ifstream* chomp::homology::textfile::fs
private

The true file if it was opened.

Definition at line 617 of file textfile.h.

◆ line

long chomp::homology::textfile::line
private

The current line number.

Definition at line 614 of file textfile.h.

◆ s

std::istream* chomp::homology::textfile::s
private

A pointer to an input stream (usually equal to 'fs').

Definition at line 620 of file textfile.h.


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