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



Page generated by Doxygen 1.8.17 for MRPT 1.4.0 SVN: at Sat Jan 18 22:37:07 UTC 2020