owlps/owlps-positioning/src/textfilereader.hh

49 lines
952 B
C++

#ifndef _OWLPS_POSITIONING_TEXTFILEREADER_HH_
#define _OWLPS_POSITIONING_TEXTFILEREADER_HH_
#include <string>
#include <fstream>
/// Read text from a file, line by line
class TextFileReader
{
protected:
std::string file_name ;
std::ifstream file ;
unsigned int current_line_nb ;
/// Checks if the file is readable and closes it if not
bool eof_close(void) ;
public:
TextFileReader(const std::string &_file_name) ;
virtual ~TextFileReader(void) ;
/** @name Operations */
//@{
/// Read the next non-blank line
bool read_nonblank_line(std::string &text) ;
/// Read the next line
bool read_line(std::string &text) ;
bool eof(void) const ;
//@}
} ;
/* *** Operations *** */
/**
* @return \em true if the end of file is reached.
* @return \em false if there is something more to read.
*/
inline bool TextFileReader::eof() const
{
return ! file && file.eof() ;
}
#endif // _OWLPS_POSITIONING_TEXTFILEREADER_HH_