Main MRPT website > C++ reference
MRPT logo
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 43 of file CTextFileLinesParser.h.

#include <mrpt/utils/CTextFileLinesParser.h>

List of all members.

Public Member Functions

 CTextFileLinesParser ()
 Default constructor; should call open() at some moment later.
 CTextFileLinesParser (const std::string &fil)
 Constructor for opening a file

Exceptions:
std::exception On error opening file.

void open (const std::string &fil)
 Open a file (an alternative to the constructor with a file name).
void close ()
 Close the file (no need to call it normally, the file is closed upon destruction).
void rewind ()
 Reset the read pointer to the beginning of the file.
bool getNextLine (std::string &out_str)
 Reads from the file and return the next (non-comment) line, as a std::string.
bool getNextLine (std::istringstream &buf)
 Reads from the file and stores the next (non-comment) line into the given stream buffer.
size_t getCurrentLineNumber () const
 Return the line number of the last line returned with getNextLine.
void enableCommentFilters (bool filter_MATLAB_comments, bool filter_C_comments, bool filter_SH_comments)
 Enable/disable filtering of lines starting with "%", "//" or "#", respectively.

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

Constructor & Destructor Documentation

mrpt::utils::CTextFileLinesParser::CTextFileLinesParser (  )  [inline]

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

Definition at line 47 of file CTextFileLinesParser.h.

mrpt::utils::CTextFileLinesParser::CTextFileLinesParser ( const std::string &  fil  )  [inline]

Constructor for opening a file

Exceptions:
std::exception On error opening file.

Definition at line 50 of file CTextFileLinesParser.h.


Member Function Documentation

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.

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 123 of file CTextFileLinesParser.h.

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

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

Definition at line 120 of file CTextFileLinesParser.h.

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 97 of file CTextFileLinesParser.h.

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

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 79 of file CTextFileLinesParser.h.

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 55 of file CTextFileLinesParser.h.

References THROW_EXCEPTION_CUSTOM_MSG1.

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

Reset the read pointer to the beginning of the file.

Definition at line 69 of file CTextFileLinesParser.h.


Member Data Documentation

Definition at line 137 of file CTextFileLinesParser.h.

Definition at line 135 of file CTextFileLinesParser.h.

Definition at line 139 of file CTextFileLinesParser.h.

Definition at line 138 of file CTextFileLinesParser.h.

Definition at line 140 of file CTextFileLinesParser.h.

std::ifstream mrpt::utils::CTextFileLinesParser::m_in [private]

Definition at line 136 of file CTextFileLinesParser.h.




Page generated by Doxygen 1.7.1 for MRPT 0.9.4 SVN: at Mon Jan 10 23:33:19 UTC 2011