Main MRPT website > C++ reference for MRPT 1.3.2
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-2015, 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  /** Method responsible for reading from the stream.
31  */
32  size_t Read(void *Buffer, size_t Count);
33 
34  /** Method responsible for writing to the stream.
35  * Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.
36  */
37  size_t Write(const void *Buffer, size_t Count);
38 
39  private:
40  std::ifstream m_if; //!< The actual input file stream.
41 
42  // DECLARE_UNCOPIABLE( CFileInputStream )
43 
44  public:
45  /** Constructor
46  * \param fileName The file to be open in this stream
47  * \exception std::exception On error trying to open the file.
48  */
49  CFileInputStream(const std::string &fileName );
50 
51  /** Default constructor
52  */
54 
55  /** Open a file for reading
56  * \param fileName The file to be open in this stream
57  * \return true on success.
58  */
59  bool open(const std::string &fileName );
60 
61  /** Close the stream. */
62  void close();
63 
64  /** Destructor
65  */
66  virtual ~CFileInputStream();
67 
68  /** Says if file was open successfully or not.
69  */
70  bool fileOpenCorrectly();
71 
72  /** Will be true if EOF has been already reached.
73  */
74  bool checkEOF();
75 
76  /** Method for moving to a specified position in the streamed resource.
77  * See documentation of CStream::Seek
78  */
79  uint64_t Seek( uint64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning);
80 
81  /** Method for getting the total number of bytes in the buffer.
82  */
83  uint64_t getTotalBytesCount();
84 
85  /** Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
86  */
87  uint64_t getPosition();
88 
89  /** Reads one string line from the file (until a new-line character)
90  * \return true if a line has been read, false on EOF or error.
91  */
92  bool readLine( std::string &str );
93 
94  }; // End of class def.
95 
96  } // End of namespace
97 } // end of namespace
98 #endif
std::ifstream m_if
The actual input file stream.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
TSeekOrigin
Used in CStream::Seek.
Definition: CStream.h:42
The base class of classes that cannot be copied: compile-time errors will be issued on any copy opera...
Definition: CUncopiable.h:30
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.9.1 for MRPT 1.3.2 SVN:Unversioned directory at Thu Dec 10 00:07:55 UTC 2015