Main MRPT website > C++ reference for MRPT 1.9.9
io/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-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 <mrpt/io/CStream.h>
12 #include <fstream>
13 
14 namespace mrpt
15 {
16 namespace io
17 {
18 /** This CStream derived class allow using a file as a read-only, binary stream.
19  *
20  * \sa CStream, CFileStream, CFileGZInputStream
21  * \ingroup mrpt_io_grp
22  */
23 class CFileInputStream : public CStream
24 {
25  private:
26  /** The actual input file stream. */
27  std::ifstream m_if;
28 
29  public:
30  /** Constructor
31  * \param fileName The file to be open in this stream
32  * \exception std::exception On error trying to open the file.
33  */
34  CFileInputStream(const std::string& fileName);
35  /** Default constructor */
37 
38  CFileInputStream(const CFileInputStream&) = delete;
40 
41  virtual ~CFileInputStream();
42 
43  /** Open a file for reading
44  * \param fileName The file to be open in this stream
45  * \return true on success.
46  */
47  bool open(const std::string& fileName);
48  /** Close the stream */
49  void close();
50  /** Returns true if the file was open without errors. */
51  bool fileOpenCorrectly() const;
52  /** Returns true if the file was open without errors. */
53  bool is_open() { return fileOpenCorrectly(); }
54  /** Will be true if EOF has been already reached. */
55  bool checkEOF();
56  /** Resets stream error status bits (e.g. after an EOF) */
57  void clearError();
58 
59  // See docs in base class
60  uint64_t Seek(
61  int64_t off, CStream::TSeekOrigin Origin = sFromBeginning) override;
62  // See docs in base class
63  uint64_t getTotalBytesCount() const override;
64  // See docs in base class
65  uint64_t getPosition() const override;
66 
67  /** Reads one string line from the file (until a new-line character)
68  * \return true if a line has been read, false on EOF or error. */
69  bool readLine(std::string& str);
70 
71  size_t Read(void* Buffer, size_t Count) override;
72  size_t Write(const void* Buffer, size_t Count) override;
73 }; // End of class def.
74 } // End of namespace
75 } // end of namespace
mrpt::io::CStream::TSeekOrigin
TSeekOrigin
Used in CStream::Seek.
Definition: io/CStream.h:34
mrpt::io::CFileInputStream::CFileInputStream
CFileInputStream()
Default constructor.
Definition: CFileInputStream.cpp:39
mrpt::io::CFileInputStream::Read
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
Definition: CFileInputStream.cpp:67
mrpt::io::CFileInputStream::fileOpenCorrectly
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
Definition: CFileInputStream.cpp:149
mrpt::io::CFileInputStream::~CFileInputStream
virtual ~CFileInputStream()
Definition: CFileInputStream.cpp:62
int64_t
__int64 int64_t
Definition: rptypes.h:49
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::io::CFileInputStream::m_if
std::ifstream m_if
The actual input file stream.
Definition: io/CFileInputStream.h:27
mrpt::io::CFileInputStream::getTotalBytesCount
uint64_t getTotalBytesCount() const override
Returns the total amount of bytes in the stream.
Definition: CFileInputStream.cpp:121
mrpt::io::CFileInputStream::open
bool open(const std::string &fileName)
Open a file for reading.
Definition: CFileInputStream.cpp:43
mrpt::io::CFileInputStream::clearError
void clearError()
Resets stream error status bits (e.g.
Definition: CFileInputStream.cpp:171
mrpt::io::CFileInputStream
This CStream derived class allow using a file as a read-only, binary stream.
Definition: io/CFileInputStream.h:23
mrpt::io::CFileInputStream::getPosition
uint64_t getPosition() const override
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the l...
Definition: CFileInputStream.cpp:137
mrpt::io::CStream::sFromBeginning
@ sFromBeginning
Definition: io/CStream.h:36
uint64_t
unsigned __int64 uint64_t
Definition: rptypes.h:50
mrpt::io::CFileInputStream::close
void close()
Close the stream.
Definition: CFileInputStream.cpp:54
mrpt::io::CFileInputStream::is_open
bool is_open()
Returns true if the file was open without errors.
Definition: io/CFileInputStream.h:53
CStream.h
mrpt::io::CFileInputStream::Write
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
Definition: CFileInputStream.cpp:79
mrpt::io::CFileInputStream::checkEOF
bool checkEOF()
Will be true if EOF has been already reached.
Definition: CFileInputStream.cpp:165
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::io::CFileInputStream::readLine
bool readLine(std::string &str)
Reads one string line from the file (until a new-line character)
Definition: CFileInputStream.cpp:153
mrpt::io::CFileInputStream::Seek
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.
Definition: CFileInputStream.cpp:91
mrpt::io::CFileInputStream::operator=
CFileInputStream & operator=(const CFileInputStream &)=delete
mrpt::io::CStream
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: io/CStream.h:30



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