Main MRPT website > C++ reference
MRPT logo
CFileInputStream.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CFileInputStream_H
29 #define CFileInputStream_H
30 
31 #include <mrpt/utils/CStream.h>
32 
33 #include <iostream>
34 
35 /*---------------------------------------------------------------
36  Class
37  ---------------------------------------------------------------*/
38 namespace mrpt
39 {
40  namespace utils
41  {
42  /** This CStream derived class allow using a file as a read-only, binary stream.
43  *
44  * \sa CStream, CFileStream, CFileGZInputStream
45  * \ingroup mrpt_base_grp
46  */
48  {
49  protected:
50  /** Method responsible for reading from the stream.
51  */
52  size_t Read(void *Buffer, size_t Count);
53 
54  /** Method responsible for writing to the stream.
55  * Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.
56  */
57  size_t Write(const void *Buffer, size_t Count);
58 
59  private:
60  std::ifstream m_if; //!< The actual input file stream.
61 
62  // DECLARE_UNCOPIABLE( CFileInputStream )
63 
64  public:
65  /** Constructor
66  * \param fileName The file to be open in this stream
67  * \exception std::exception On error trying to open the file.
68  */
69  CFileInputStream(const std::string &fileName );
70 
71  /** Default constructor
72  */
74 
75  /** Open a file for reading
76  * \param fileName The file to be open in this stream
77  * \return true on success.
78  */
79  bool open(const std::string &fileName );
80 
81  /** Close the stream. */
82  void close();
83 
84  /** Destructor
85  */
86  virtual ~CFileInputStream();
87 
88  /** Says if file was open successfully or not.
89  */
90  bool fileOpenCorrectly();
91 
92  /** Will be true if EOF has been already reached.
93  */
94  bool checkEOF();
95 
96  /** Method for moving to a specified position in the streamed resource.
97  * See documentation of CStream::Seek
98  */
99  uint64_t Seek(long Offset, CStream::TSeekOrigin Origin = sFromBeginning);
100 
101  /** Method for getting the total number of bytes in the buffer.
102  */
103  uint64_t getTotalBytesCount();
104 
105  /** Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
106  */
107  uint64_t getPosition();
108 
109  /** Reads one string line from the file (until a new-line character)
110  * \return true if a line has been read, false on EOF or error.
111  */
112  bool readLine( std::string &str );
113 
114  }; // End of class def.
115 
116  } // End of namespace
117 } // end of namespace
118 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013