9 #ifndef CTextFileLinesParser_H 10 #define CTextFileLinesParser_H 31 CTextFileLinesParser() : m_curLineNum(0), m_filter_MATLAB_comments(true), m_filter_C_comments(true), m_filter_SH_comments(true), m_in{ NULL }, m_in_ownership{
true } { }
34 explicit CTextFileLinesParser(
const std::string &fil) : m_filter_MATLAB_comments(true), m_filter_C_comments(true), m_filter_SH_comments(true), m_in{ NULL }, m_in_ownership{
true } {
38 explicit CTextFileLinesParser(std::istream&
in) : m_filter_MATLAB_comments(true), m_filter_C_comments(true), m_filter_SH_comments(true), m_in{ NULL }, m_in_ownership{
true } {
48 std::ifstream *ifs =
new std::ifstream;
50 ifs->open(fil.c_str());
58 m_fileName =
"{std::istream}";
61 m_in_ownership =
false;
68 if (m_in_ownership)
delete m_in;
85 std::istringstream buf;
104 while (!m_in->fail())
107 std::getline(*m_in,lin);
110 if (lin.empty())
continue;
129 bool filter_MATLAB_comments,
130 bool filter_C_comments,
131 bool filter_SH_comments
134 m_filter_MATLAB_comments = filter_MATLAB_comments;
135 m_filter_C_comments = filter_C_comments;
136 m_filter_SH_comments = filter_SH_comments;
CTextFileLinesParser()
Default constructor; should call open() at some moment later.
bool m_filter_SH_comments
bool getNextLine(std::istringstream &buf)
Reads from the file and stores the next (non-comment) line into the given stream buffer.
bool getNextLine(std::string &out_str)
Reads from the file and return the next (non-comment) line, as a std::string.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
CTextFileLinesParser(std::istream &in)
void rewind()
Reset the read pointer to the beginning of the file.
CTextFileLinesParser(const std::string &fil)
Constructor for opening a file.
A class for parsing text files, returning each non-empty and non-comment line, along its line number...
GLsizei const GLchar ** string
bool m_filter_MATLAB_comments
void open(const std::string &fil)
Open a file (an alternative to the constructor with a file name)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool BASE_IMPEXP strStarts(const std::string &str, const std::string &subStr)
Return true if "str" starts with "subStr" (case sensitive)
size_t getCurrentLineNumber() const
Return the line number of the last line returned with getNextLine.
std::string BASE_IMPEXP trim(const std::string &str)
Removes leading and trailing spaces.
void enableCommentFilters(bool filter_MATLAB_comments, bool filter_C_comments, bool filter_SH_comments)
Enable/disable filtering of lines starting with "%", "//" or "#", respectively.
void open(std::istream &in)
void close()
Close the file (no need to call it normally, the file is closed upon destruction) ...