A class for parsing text files, returning each non-empty and non-comment line, along its line number.
Lines are strip out of leading and trailing whitespaces. By default, lines starting with either "#", "//" or "%" are skipped (comment lines), unless this behavior is explicitly disabled with enableCommentFilters
Definition at line 28 of file CTextFileLinesParser.h.
#include <mrpt/utils/CTextFileLinesParser.h>
Public Member Functions | |
CTextFileLinesParser () | |
Default constructor; should call open() at some moment later. More... | |
CTextFileLinesParser (const std::string &fil) | |
Constructor for opening a file. More... | |
void | open (const std::string &fil) |
Open a file (an alternative to the constructor with a file name) More... | |
void | close () |
Close the file (no need to call it normally, the file is closed upon destruction) More... | |
void | rewind () |
Reset the read pointer to the beginning of the file. More... | |
bool | getNextLine (std::string &out_str) |
Reads from the file and return the next (non-comment) line, as a std::string. More... | |
bool | getNextLine (std::istringstream &buf) |
Reads from the file and stores the next (non-comment) line into the given stream buffer. More... | |
size_t | getCurrentLineNumber () const |
Return the line number of the last line returned with getNextLine. More... | |
void | enableCommentFilters (bool filter_MATLAB_comments, bool filter_C_comments, bool filter_SH_comments) |
Enable/disable filtering of lines starting with "%", "//" or "#", respectively. More... | |
Private Attributes | |
std::string | m_fileName |
std::ifstream | m_in |
size_t | m_curLineNum |
bool | m_filter_MATLAB_comments |
bool | m_filter_C_comments |
bool | m_filter_SH_comments |
|
inline |
Default constructor; should call open() at some moment later.
Definition at line 32 of file CTextFileLinesParser.h.
|
inline |
Constructor for opening a file.
std::exception | On error opening file |
Definition at line 42 of file CTextFileLinesParser.h.
References open().
|
inline |
Close the file (no need to call it normally, the file is closed upon destruction)
Definition at line 65 of file CTextFileLinesParser.h.
References m_in.
|
inline |
Enable/disable filtering of lines starting with "%", "//" or "#", respectively.
Definition at line 123 of file CTextFileLinesParser.h.
References m_filter_C_comments, m_filter_MATLAB_comments, and m_filter_SH_comments.
|
inline |
Return the line number of the last line returned with getNextLine.
Definition at line 120 of file CTextFileLinesParser.h.
References m_curLineNum.
Referenced by mrpt::graphs::detail::graph_ops< graph_t >::load_graph_of_poses_from_text_file().
|
inline |
Reads from the file and return the next (non-comment) line, as a std::string.
Definition at line 78 of file CTextFileLinesParser.h.
Referenced by mrpt::graphs::detail::graph_ops< graph_t >::load_graph_of_poses_from_text_file().
|
inline |
Reads from the file and stores the next (non-comment) line into the given stream buffer.
Definition at line 97 of file CTextFileLinesParser.h.
References m_curLineNum, m_filter_C_comments, m_filter_MATLAB_comments, m_filter_SH_comments, m_in, mrpt::system::strStarts(), and mrpt::system::trim().
|
inline |
Open a file (an alternative to the constructor with a file name)
Definition at line 51 of file CTextFileLinesParser.h.
References m_curLineNum, m_fileName, m_in, and THROW_EXCEPTION_FMT.
Referenced by CTextFileLinesParser().
|
inline |
Reset the read pointer to the beginning of the file.
Definition at line 67 of file CTextFileLinesParser.h.
References m_curLineNum, and m_in.
Referenced by mrpt::graphs::detail::graph_ops< graph_t >::load_graph_of_poses_from_text_file().
|
private |
Definition at line 135 of file CTextFileLinesParser.h.
Referenced by getCurrentLineNumber(), getNextLine(), open(), and rewind().
|
private |
Definition at line 133 of file CTextFileLinesParser.h.
Referenced by open().
|
private |
Definition at line 137 of file CTextFileLinesParser.h.
Referenced by enableCommentFilters(), and getNextLine().
|
private |
Definition at line 136 of file CTextFileLinesParser.h.
Referenced by enableCommentFilters(), and getNextLine().
|
private |
Definition at line 138 of file CTextFileLinesParser.h.
Referenced by enableCommentFilters(), and getNextLine().
|
private |
Definition at line 134 of file CTextFileLinesParser.h.
Referenced by close(), getNextLine(), open(), and rewind().
Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019 |