Main MRPT website > C++ reference
MRPT logo
CFileOutputStream.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 CFileOutputStream_H
29 #define CFileOutputStream_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 write-only, binary stream.
43  *
44  * \sa CStream, CFileStream, CFileGZOutputStream
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  // DECLARE_UNCOPIABLE( CFileOutputStream )
60 
61  private:
62  std::ofstream m_of; //!< The actual output file stream.
63 
64  public:
65  /** Constructor
66  * \param fileName The file to be open in this stream
67  * \param append If set to true, the file will be opened for writing and the current cursor position set at the end of the file. Otherwise, previous contents will be lost.
68  * \exception std::exception if the file cannot be opened.
69  */
71  const std::string &fileName,
72  bool append = false
73  );
74 
75  /** Default constructor
76  */
78 
79  /** Open the given file for write
80  * \param fileName The file to be open in this stream
81  * \param append If set to true, the file will be opened for writing and the current cursor position set at the end of the file. Otherwise, previous contents will be lost.
82  * \sa fileOpenCorrectly
83  * \return true on success.
84  */
85  bool open(const std::string &fileName, bool append = false );
86 
87  /** Close the stream. */
88  void close();
89 
90  /** Destructor
91  */
92  virtual ~CFileOutputStream();
93 
94  /** Says if file was open successfully or not.
95  */
96  bool fileOpenCorrectly();
97 
98  /** Method for moving to a specified position in the streamed resource.
99  * See documentation of CStream::Seek
100  */
101  uint64_t Seek(long Offset, CStream::TSeekOrigin Origin = sFromBeginning);
102 
103  /** Method for getting the total number of bytes writen to buffer.
104  */
105  uint64_t getTotalBytesCount();
106 
107  /** Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
108  */
109  uint64_t getPosition();
110 
111 
112  }; // End of class def.
113 
114  } // End of namespace
115 } // end of namespace
116 #endif



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