2012-02-06 16:44:09 +01:00
|
|
|
/*
|
2013-05-29 18:43:35 +02:00
|
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
|
|
* It is subject to the copyright notice and license terms in the
|
|
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
|
|
* distribution and at
|
|
|
|
* http://code.lm7.fr/p/owlps/source/tree/master/COPYRIGHT.t2t
|
|
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms
|
|
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
|
|
* distributed along with this file, either separately or by replacing
|
2013-06-22 23:30:17 +02:00
|
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-03-23 11:32:05 +01:00
|
|
|
#ifndef _OWLPS_POSITIONING_TEXTFILEREADER_HH_
|
|
|
|
#define _OWLPS_POSITIONING_TEXTFILEREADER_HH_
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
|
2011-04-06 12:03:51 +02:00
|
|
|
/// Reads text from a file, line by line
|
|
|
|
/**
|
|
|
|
* If the file name is a dash ('-'), the standard input is used.
|
|
|
|
*/
|
2010-03-23 11:32:05 +01:00
|
|
|
class TextFileReader
|
|
|
|
{
|
2010-04-01 11:15:48 +02:00
|
|
|
protected:
|
2011-04-06 12:03:51 +02:00
|
|
|
/// Name of the input file
|
2010-03-23 11:32:05 +01:00
|
|
|
std::string file_name ;
|
2011-04-06 12:03:51 +02:00
|
|
|
/// Stream associated with the file
|
2010-03-23 11:32:05 +01:00
|
|
|
std::ifstream file ;
|
2011-04-06 12:03:51 +02:00
|
|
|
/// Original rdbuf of the stream
|
|
|
|
std::streambuf *file_buf ;
|
|
|
|
/// Number of the last line read
|
2010-04-01 11:15:48 +02:00
|
|
|
unsigned int current_line_nb ;
|
2010-03-23 11:32:05 +01:00
|
|
|
|
|
|
|
/// 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 */
|
|
|
|
//@{
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Reads the next non-blank line
|
2010-04-01 11:15:48 +02:00
|
|
|
bool read_nonblank_line(std::string &text) ;
|
2011-06-20 12:11:20 +02:00
|
|
|
/// Reads the next line
|
2010-03-23 11:32:05 +01:00
|
|
|
bool read_line(std::string &text) ;
|
|
|
|
bool eof(void) const ;
|
|
|
|
//@}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-30 21:23:05 +02:00
|
|
|
* @returns `true` if the end of file is reached.
|
|
|
|
* @returns `false` if there is something more to read.
|
2010-03-23 11:32:05 +01:00
|
|
|
*/
|
|
|
|
inline bool TextFileReader::eof() const
|
|
|
|
{
|
|
|
|
return ! file && file.eof() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _OWLPS_POSITIONING_TEXTFILEREADER_HH_
|