MRPT  1.9.9
io/CFileInputStream.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/io/CStream.h>
12 #include <fstream>
13 
14 namespace mrpt::io
15 {
16 /** This CStream derived class allow using a file as a read-only, binary stream.
17  *
18  * \sa CStream, CFileStream, CFileGZInputStream
19  * \ingroup mrpt_io_grp
20  */
21 class CFileInputStream : public CStream
22 {
23  private:
24  /** The actual input file stream. */
25  std::ifstream m_if;
26 
27  public:
28  /** Constructor
29  * \param fileName The file to be open in this stream
30  * \exception std::exception On error trying to open the file.
31  */
32  CFileInputStream(const std::string& fileName);
33  /** Default constructor */
35 
36  CFileInputStream(const CFileInputStream&) = delete;
38 
39  ~CFileInputStream() override;
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  /** Close the stream */
47  void close();
48  /** Returns true if the file was open without errors. */
49  bool fileOpenCorrectly() const;
50  /** Returns true if the file was open without errors. */
51  bool is_open() { return fileOpenCorrectly(); }
52  /** Will be true if EOF has been already reached. */
53  bool checkEOF();
54  /** Resets stream error status bits (e.g. after an EOF) */
55  void clearError();
56 
57  // See docs in base class
58  uint64_t Seek(
59  int64_t off, CStream::TSeekOrigin Origin = sFromBeginning) override;
60  // See docs in base class
61  uint64_t getTotalBytesCount() const override;
62  // See docs in base class
63  uint64_t getPosition() const override;
64 
65  /** Reads one string line from the file (until a new-line character)
66  * \return true if a line has been read, false on EOF or error. */
67  bool readLine(std::string& str);
68 
69  size_t Read(void* Buffer, size_t Count) override;
70  size_t Write(const void* Buffer, size_t Count) override;
71 }; // End of class def.
72 } // namespace mrpt::io
TSeekOrigin
Used in CStream::Seek.
Definition: io/CStream.h:32
void close()
Close the stream.
bool checkEOF()
Will be true if EOF has been already reached.
bool open(const std::string &fileName)
Open a file for reading.
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
void clearError()
Resets stream error status bits (e.g.
uint64_t Seek(int64_t off, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
bool is_open()
Returns true if the file was open without errors.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: io/CStream.h:28
This CStream derived class allow using a file as a read-only, binary stream.
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
bool readLine(std::string &str)
Reads one string line from the file (until a new-line character)
std::ifstream m_if
The actual input file stream.
CFileInputStream & operator=(const CFileInputStream &)=delete
uint64_t getTotalBytesCount() const override
Returns the total amount of bytes in the stream.
uint64_t getPosition() const override
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the l...
CFileInputStream()
Default constructor.
bool fileOpenCorrectly() const
Returns true if the file was open without errors.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020