Main MRPT website > C++ reference for MRPT 1.5.6
CFileInputStream.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-2017, 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 #ifndef CFileInputStream_H
10 #define CFileInputStream_H
11 
12 #include <mrpt/utils/CStream.h>
13 #include <fstream>
14 
15 namespace mrpt
16 {
17  namespace utils
18  {
19  /** This CStream derived class allow using a file as a read-only, binary stream.
20  *
21  * \sa CStream, CFileStream, CFileGZInputStream
22  * \ingroup mrpt_base_grp
23  */
25  {
26  protected:
27  size_t Read(void *Buffer, size_t Count) MRPT_OVERRIDE;
28  size_t Write(const void *Buffer, size_t Count) MRPT_OVERRIDE;
29  private:
30  std::ifstream m_if; //!< The actual input file stream.
31  public:
32  /** Constructor
33  * \param fileName The file to be open in this stream
34  * \exception std::exception On error trying to open the file.
35  */
36  CFileInputStream(const std::string &fileName );
37  /** Default constructor */
39  virtual ~CFileInputStream();
40 
41  /** Open a file for reading
42  * \param fileName The file to be open in this stream
43  * \return true on success.
44  */
45  bool open(const std::string &fileName );
46  void close(); //!< Close the stream
47  bool fileOpenCorrectly(); //!< Returns true if the file was open without errors.
48  bool is_open() { return fileOpenCorrectly(); } //!< Returns true if the file was open without errors.
49  bool checkEOF(); //!< Will be true if EOF has been already reached.
50  void clearError(); //!< Resets stream error status bits (e.g. after an EOF)
51 
52  /** Method for moving to a specified position in the streamed resource.
53  * See documentation of CStream::Seek */
54  uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning) MRPT_OVERRIDE;
55 
56  /** Method for getting the total number of bytes in the buffer. */
57  uint64_t getTotalBytesCount() MRPT_OVERRIDE;
58 
59  /** Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one. */
60  uint64_t getPosition() MRPT_OVERRIDE;
61 
62  /** Reads one string line from the file (until a new-line character)
63  * \return true if a line has been read, false on EOF or error. */
64  bool readLine( std::string &str );
65 
66  }; // End of class def.
67  } // End of namespace
68 } // end of namespace
69 #endif
TSeekOrigin
Used in CStream::Seek.
Definition: CStream.h:42
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
std::ifstream m_if
The actual input file stream.
STL namespace.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
__int64 int64_t
Definition: rptypes.h:51
bool is_open()
Returns true if the file was open without errors.
The base class of classes that cannot be copied: compile-time errors will be issued on any copy opera...
Definition: CUncopiable.h:30
GLsizei const GLchar ** string
Definition: glext.h:3919
unsigned __int64 uint64_t
Definition: rptypes.h:52
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
This CStream derived class allow using a file as a read-only, binary stream.



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019