Main MRPT website > C++ reference for MRPT 1.9.9
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  */
24 class CFileInputStream : public CStream
25 {
26  protected:
27  size_t Read(void* Buffer, size_t Count) override;
28  size_t Write(const void* Buffer, size_t Count) override;
29 
30  private:
31  /** The actual input file stream. */
32  std::ifstream m_if;
33 
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 
43  CFileInputStream(const CFileInputStream&) = delete;
45 
46  virtual ~CFileInputStream();
47 
48  /** Open a file for reading
49  * \param fileName The file to be open in this stream
50  * \return true on success.
51  */
52  bool open(const std::string& fileName);
53  /** Close the stream */
54  void close();
55  /** Returns true if the file was open without errors. */
56  bool fileOpenCorrectly();
57  /** Returns true if the file was open without errors. */
58  bool is_open() { return fileOpenCorrectly(); }
59  /** Will be true if EOF has been already reached. */
60  bool checkEOF();
61 
62  /** Method for moving to a specified position in the streamed resource.
63  * See documentation of CStream::Seek */
64  uint64_t Seek(
65  uint64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning) override;
66 
67  /** Method for getting the total number of bytes in the buffer. */
68  uint64_t getTotalBytesCount() override;
69 
70  /** Method for getting the current cursor position, where 0 is the first
71  * byte and TotalBytesCount-1 the last one. */
72  uint64_t getPosition() override;
73 
74  /** Reads one string line from the file (until a new-line character)
75  * \return true if a line has been read, false on EOF or error. */
76  bool readLine(std::string& str);
77 
78 }; // End of class def.
79 static_assert(
82  "Copy Check");
83 } // End of namespace
84 } // end of namespace
85 #endif
CFileInputStream()
Default constructor.
TSeekOrigin
Used in CStream::Seek.
Definition: CStream.h:45
std::ifstream m_if
The actual input file stream.
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
uint64_t getPosition() override
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the l...
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
CFileInputStream & operator=(const CFileInputStream &)=delete
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
void close()
Close the stream.
uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Method for moving to a specified position in the streamed resource.
bool is_open()
Returns true if the file was open without errors.
GLsizei const GLchar ** string
Definition: glext.h:4101
bool checkEOF()
Will be true if EOF has been already reached.
bool readLine(std::string &str)
Reads one string line from the file (until a new-line character)
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool open(const std::string &fileName)
Open a file for reading.
bool fileOpenCorrectly()
Returns true if the file was open without errors.
GLsizei const GLfloat * value
Definition: glext.h:4117
This CStream derived class allow using a file as a read-only, binary stream.
uint64_t getTotalBytesCount() override
Method for getting the total number of bytes in the buffer.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019