9#ifndef CTextFileLinesParser_H
10#define CTextFileLinesParser_H
30 CTextFileLinesParser() : m_curLineNum(0), m_filter_MATLAB_comments(true), m_filter_C_comments(true), m_filter_SH_comments(true) { }
33 CTextFileLinesParser(
const std::string &fil) : m_filter_MATLAB_comments(true), m_filter_C_comments(true), m_filter_SH_comments(true) {
38 void open(
const std::string &fil)
44 m_in.open(fil.c_str());
65 std::istringstream buf;
86 std::getline(m_in,lin);
89 if (lin.empty())
continue;
108 bool filter_MATLAB_comments,
109 bool filter_C_comments,
110 bool filter_SH_comments
113 m_filter_MATLAB_comments = filter_MATLAB_comments;
114 m_filter_C_comments = filter_C_comments;
115 m_filter_SH_comments = filter_SH_comments;
A class for parsing text files, returning each non-empty and non-comment line, along its line number.
void close()
Close the file (no need to call it normally, the file is closed upon destruction)
bool m_filter_SH_comments
size_t getCurrentLineNumber() const
Return the line number of the last line returned with getNextLine.
CTextFileLinesParser()
Default constructor; should call open() at some moment later.
void open(const std::string &fil)
Open a file (an alternative to the constructor with a file name)
bool m_filter_MATLAB_comments
void rewind()
Reset the read pointer to the beginning of the file.
void enableCommentFilters(bool filter_MATLAB_comments, bool filter_C_comments, bool filter_SH_comments)
Enable/disable filtering of lines starting with "%", "//" or "#", respectively.
bool getNextLine(std::string &out_str)
Reads from the file and return the next (non-comment) line, as a std::string.
CTextFileLinesParser(const std::string &fil)
Constructor for opening a file.
bool getNextLine(std::istringstream &buf)
Reads from the file and stores the next (non-comment) line into the given stream buffer.
std::string BASE_IMPEXP trim(const std::string &str)
Removes leading and trailing spaces.
bool BASE_IMPEXP strStarts(const std::string &str, const std::string &subStr)
Return true if "str" starts with "subStr" (case sensitive)
#define THROW_EXCEPTION_CUSTOM_MSG1(msg, param1)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.