Main MRPT website > C++ reference
MRPT logo
CFileGZOutputStream.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 CFileGZOutputStream_H
29 #define CFileGZOutputStream_H
30 
31 #include <mrpt/utils/CStream.h>
32 
33 /*---------------------------------------------------------------
34  Class
35  ---------------------------------------------------------------*/
36 namespace mrpt
37 {
38  namespace utils
39  {
40  /** Saves data to a file and transparently compress the data using the given compression level.
41  * The generated files are in gzip format ("file.gz").
42  * This class requires compiling MRPT with wxWidgets. If wxWidgets is not available then the class is actually mapped to the standard CFileOutputStream
43  *
44  * \sa CFileOutputStream
45  * \ingroup mrpt_base_grp
46  */
47 #if !MRPT_HAS_GZ_STREAMS
48  // We don't have wxwidgets:
49 # define CFileGZOutputStream CFileOutputStream
50 #else
51  class BASE_IMPEXP CFileGZOutputStream : public CStream, public CUncopiable
52  {
53  protected:
54  /** Method responsible for reading from the stream.
55  */
56  size_t Read(void *Buffer, size_t Count);
57 
58  /** Method responsible for writing to the stream.
59  * Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.
60  */
61  size_t Write(const void *Buffer, size_t Count);
62 
63  // DECLARE_UNCOPIABLE( CFileGZOutputStream )
64 
65  private:
66  void *m_f;
67 
68  public:
69  /** Constructor: opens an output file with compression level = 1 (minimum, fastest).
70  * \param fileName The file to be open in this stream
71  * \sa open
72  */
73  CFileGZOutputStream(const std::string &fileName);
74 
75  /** Constructor, without opening the file.
76  * \sa open
77  */
79 
80  /** Open a file for write, choosing the compression level
81  * \param fileName The file to be open in this stream
82  * \param compress_level 0:no compression, 1:fastest, 9:best
83  * \return true on success, false on any error.
84  */
85  bool open(const std::string &fileName, int compress_level = 1 );
86 
87  /** Close the file. */
88  void close();
89 
90  /** Destructor
91  */
92  virtual ~CFileGZOutputStream();
93 
94  /** Says if file was open successfully or not.
95  */
96  bool fileOpenCorrectly();
97 
98  /** Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
99  */
100  uint64_t getPosition();
101 
102  /** This method is not implemented in this class */
103  uint64_t Seek(long Offset, CStream::TSeekOrigin Origin = sFromBeginning)
104  {
105  THROW_EXCEPTION("Seek is not implemented in this class");
106  }
107 
108  /** This method is not implemented in this class */
109  uint64_t getTotalBytesCount()
110  {
111  THROW_EXCEPTION("getTotalBytesCount is not implemented in this class");
112  }
113 
114  }; // End of class def.
115 #endif
116 
117  } // End of namespace
118 } // end of namespace
119 #endif



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