Main MRPT website > C++ reference
MRPT logo
CFileGZInputStream.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 CFileGZInputStream_H
29 #define CFileGZInputStream_H
30 
31 #include <mrpt/utils/CStream.h>
32 
33 #include <iostream>
34 
35 
36 /*---------------------------------------------------------------
37  Class
38  ---------------------------------------------------------------*/
39 namespace mrpt
40 {
41  namespace utils
42  {
43  /** Transparently opens a compressed "gz" file and reads uncompressed data from it.
44  * If the file is not a .gz file, it silently reads data from the file.
45  * This class requires compiling MRPT with wxWidgets. If wxWidgets is not available then the class is actually mapped to the standard CFileInputStream
46  *
47  * \sa CFileInputStream
48  * \ingroup mrpt_base_grp
49  */
51  {
52  protected:
53  /** Method responsible for reading from the stream.
54  */
55  size_t Read(void *Buffer, size_t Count);
56 
57  /** Method responsible for writing to the stream.
58  * Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.
59  */
60  size_t Write(const void *Buffer, size_t Count);
61 
62  // DECLARE_UNCOPIABLE( CFileGZInputStream )
63 
64  private:
65  void *m_f;
66  uint64_t m_file_size; //!< Compressed file size
67 
68  public:
69  /** Constructor without open
70  */
72 
73  /** Constructor and open
74  * \param fileName The file to be open in this stream
75  * \exception std::exception If there's an error opening the file.
76  */
77  CFileGZInputStream(const std::string &fileName );
78 
79  /** Destructor
80  */
81  virtual ~CFileGZInputStream();
82 
83  /** Opens the file for read.
84  * \param fileName The file to be open in this stream
85  * \return false if there's an error opening the file, true otherwise
86  */
87  bool open(const std::string &fileName );
88 
89  /** Closes the file */
90  void close();
91 
92  /** Says if file was open successfully or not.
93  */
94  bool fileOpenCorrectly();
95 
96  /** Will be true if EOF has been already reached.
97  */
98  bool checkEOF();
99 
100  /** Method for getting the total number of <b>compressed</b> bytes of in the file (the physical size of the compressed file).
101  */
102  uint64_t getTotalBytesCount();
103 
104  /** Method for getting the current cursor position in the <b>compressed</b>, where 0 is the first byte and TotalBytesCount-1 the last one.
105  */
106  uint64_t getPosition();
107 
108  /** This method is not implemented in this class */
109  uint64_t Seek(long Offset, CStream::TSeekOrigin Origin = sFromBeginning)
110  {
111  THROW_EXCEPTION("Seek is not implemented in this class");
112  }
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