Main MRPT website > C++ reference for MRPT 1.9.9
CTextFileLinesParser.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <fstream>
12 #include <string>
13 #include <iosfwd>
14 
15 namespace mrpt
16 {
17 namespace io
18 {
19 /** A class for parsing text files, returning each non-empty and non-comment
20 * line, along its line number. Lines are strip out of leading and trailing
21 * whitespaces. By default, lines starting with either "#", "//" or "%" are
22 * skipped as comment lines, unless this behavior is explicitly disabled with
23 * \a enableCommentFilters.
24 * \ingroup mrpt_io_grp
25 */
27 {
28  public:
29  /** Default constructor; should call \a open() at some moment later. */
31  /** Constructor for opening a file \exception std::exception On error
32  * opening file */
34 
35  /** Open a file (an alternative to the constructor with a file name) */
36  void open(const std::string& fil);
37 
38  /** Close the file (no need to call it normally, the file is closed upon
39  * destruction) */
40  void close();
41  /** Reset the read pointer to the beginning of the file */
42  void rewind();
43 
44  /** Reads from the file and return the next (non-comment) line, as a
45  * std::string
46  * \return false on EOF.
47  */
48  bool getNextLine(std::string& out_str);
49 
50  /** Reads from the file and stores the next (non-comment) line into the
51  * given stream buffer.
52  * \return false on EOF.
53  */
54  bool getNextLine(std::istringstream& buf);
55 
56  /** Return the line number of the last line returned with \a getNextLine */
57  size_t getCurrentLineNumber() const;
58 
59  /** Enable/disable filtering of lines starting with "%", "//" or "#",
60  * respectively. */
62  bool filter_MATLAB_comments, bool filter_C_comments,
63  bool filter_SH_comments);
64 
65  private:
67  std::ifstream m_in;
68  size_t m_curLineNum{0};
70  bool m_filter_C_comments{true};
72 
73 }; // end of CTextFileLinesParser
74 } // End of namespace
75 } // end of namespace
mrpt::io::CTextFileLinesParser::open
void open(const std::string &fil)
Open a file (an alternative to the constructor with a file name)
Definition: CTextFileLinesParser.cpp:25
mrpt::io::CTextFileLinesParser::m_fileName
std::string m_fileName
Definition: CTextFileLinesParser.h:66
mrpt::io::CTextFileLinesParser::m_filter_MATLAB_comments
bool m_filter_MATLAB_comments
Definition: CTextFileLinesParser.h:69
mrpt::io::CTextFileLinesParser::m_curLineNum
size_t m_curLineNum
Definition: CTextFileLinesParser.h:68
mrpt::io::CTextFileLinesParser::enableCommentFilters
void enableCommentFilters(bool filter_MATLAB_comments, bool filter_C_comments, bool filter_SH_comments)
Enable/disable filtering of lines starting with "%", "//" or "#", respectively.
Definition: CTextFileLinesParser.cpp:84
mrpt::io::CTextFileLinesParser::m_filter_SH_comments
bool m_filter_SH_comments
Definition: CTextFileLinesParser.h:71
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::io::CTextFileLinesParser::close
void close()
Close the file (no need to call it normally, the file is closed upon destruction)
Definition: CTextFileLinesParser.cpp:36
mrpt::io::CTextFileLinesParser::getCurrentLineNumber
size_t getCurrentLineNumber() const
Return the line number of the last line returned with getNextLine.
Definition: CTextFileLinesParser.cpp:79
mrpt::io::CTextFileLinesParser::getNextLine
bool getNextLine(std::string &out_str)
Reads from the file and return the next (non-comment) line, as a std::string.
Definition: CTextFileLinesParser.cpp:44
mrpt::io::CTextFileLinesParser::m_in
std::ifstream m_in
Definition: CTextFileLinesParser.h:67
mrpt::io::CTextFileLinesParser::rewind
void rewind()
Reset the read pointer to the beginning of the file.
Definition: CTextFileLinesParser.cpp:37
mrpt::io::CTextFileLinesParser::CTextFileLinesParser
CTextFileLinesParser()
Default constructor; should call open() at some moment later.
Definition: CTextFileLinesParser.h:30
mrpt::io::CTextFileLinesParser
A class for parsing text files, returning each non-empty and non-comment line, along its line number.
Definition: CTextFileLinesParser.h:26
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::io::CTextFileLinesParser::m_filter_C_comments
bool m_filter_C_comments
Definition: CTextFileLinesParser.h:70



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST