Main MRPT website > C++ reference for MRPT 1.5.9
List of all members | Public Member Functions | Private Attributes
mrpt::utils::CTextFileLinesParser Class Reference

Detailed Description

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 27 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...
 
 CTextFileLinesParser (std::istream &in)
 
void open (const std::string &fil)
 Open a file (an alternative to the constructor with a file name) More...
 
void open (std::istream &in)
 
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
 
size_t m_curLineNum
 
bool m_filter_MATLAB_comments
 
bool m_filter_C_comments
 
bool m_filter_SH_comments
 
std::istream * m_in
 
bool m_in_ownership
 

Constructor & Destructor Documentation

◆ CTextFileLinesParser() [1/3]

mrpt::utils::CTextFileLinesParser::CTextFileLinesParser ( )
inline

Default constructor; should call open() at some moment later.

Definition at line 31 of file CTextFileLinesParser.h.

◆ CTextFileLinesParser() [2/3]

mrpt::utils::CTextFileLinesParser::CTextFileLinesParser ( const std::string fil)
inlineexplicit

Constructor for opening a file.

Exceptions
std::exceptionOn error opening file

Definition at line 34 of file CTextFileLinesParser.h.

◆ CTextFileLinesParser() [3/3]

mrpt::utils::CTextFileLinesParser::CTextFileLinesParser ( std::istream &  in)
inlineexplicit

Definition at line 38 of file CTextFileLinesParser.h.

Member Function Documentation

◆ close()

void mrpt::utils::CTextFileLinesParser::close ( )
inline

Close the file (no need to call it normally, the file is closed upon destruction)

Definition at line 66 of file CTextFileLinesParser.h.

◆ enableCommentFilters()

void mrpt::utils::CTextFileLinesParser::enableCommentFilters ( bool  filter_MATLAB_comments,
bool  filter_C_comments,
bool  filter_SH_comments 
)
inline

Enable/disable filtering of lines starting with "%", "//" or "#", respectively.

Definition at line 128 of file CTextFileLinesParser.h.

◆ getCurrentLineNumber()

size_t mrpt::utils::CTextFileLinesParser::getCurrentLineNumber ( ) const
inline

Return the line number of the last line returned with getNextLine.

Definition at line 125 of file CTextFileLinesParser.h.

Referenced by mrpt::graphs::detail::graph_ops< graph_t >::load_graph_of_poses_from_text_stream().

◆ getNextLine() [1/2]

bool mrpt::utils::CTextFileLinesParser::getNextLine ( std::string out_str)
inline

Reads from the file and return the next (non-comment) line, as a std::string.

Returns
false on EOF.

Definition at line 83 of file CTextFileLinesParser.h.

Referenced by mrpt::graphs::detail::graph_ops< graph_t >::load_graph_of_poses_from_text_stream().

◆ getNextLine() [2/2]

bool mrpt::utils::CTextFileLinesParser::getNextLine ( std::istringstream &  buf)
inline

Reads from the file and stores the next (non-comment) line into the given stream buffer.

Returns
false on EOF.

Definition at line 101 of file CTextFileLinesParser.h.

References ASSERT_, mrpt::system::strStarts(), and mrpt::system::trim().

◆ open() [1/2]

void mrpt::utils::CTextFileLinesParser::open ( const std::string fil)
inline

Open a file (an alternative to the constructor with a file name)

Definition at line 43 of file CTextFileLinesParser.h.

References THROW_EXCEPTION_FMT.

◆ open() [2/2]

void mrpt::utils::CTextFileLinesParser::open ( std::istream &  in)
inline

Definition at line 55 of file CTextFileLinesParser.h.

◆ rewind()

void mrpt::utils::CTextFileLinesParser::rewind ( )
inline

Reset the read pointer to the beginning of the file.

Definition at line 73 of file CTextFileLinesParser.h.

Referenced by mrpt::graphs::detail::graph_ops< graph_t >::load_graph_of_poses_from_text_stream().

Member Data Documentation

◆ m_curLineNum

size_t mrpt::utils::CTextFileLinesParser::m_curLineNum
private

Definition at line 141 of file CTextFileLinesParser.h.

◆ m_fileName

std::string mrpt::utils::CTextFileLinesParser::m_fileName
private

Definition at line 140 of file CTextFileLinesParser.h.

◆ m_filter_C_comments

bool mrpt::utils::CTextFileLinesParser::m_filter_C_comments
private

Definition at line 143 of file CTextFileLinesParser.h.

◆ m_filter_MATLAB_comments

bool mrpt::utils::CTextFileLinesParser::m_filter_MATLAB_comments
private

Definition at line 142 of file CTextFileLinesParser.h.

◆ m_filter_SH_comments

bool mrpt::utils::CTextFileLinesParser::m_filter_SH_comments
private

Definition at line 144 of file CTextFileLinesParser.h.

◆ m_in

std::istream* mrpt::utils::CTextFileLinesParser::m_in
private

Definition at line 145 of file CTextFileLinesParser.h.

◆ m_in_ownership

bool mrpt::utils::CTextFileLinesParser::m_in_ownership
private

Definition at line 146 of file CTextFileLinesParser.h.




Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020