Main MRPT website > C++ reference for MRPT 1.3.2
CFileOutputStream.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 CFileOutputStream_H
10 #define CFileOutputStream_H
11 
12 #include <mrpt/utils/CStream.h>
13 
14 #include <fstream>
15 
16 /*---------------------------------------------------------------
17  Class
18  ---------------------------------------------------------------*/
19 namespace mrpt
20 {
21 namespace utils
22 {
23  /** This CStream derived class allow using a file as a write-only, binary stream.
24  *
25  * \sa CStream, CFileStream, CFileGZOutputStream
26  * \ingroup mrpt_base_grp
27  */
29  {
30  protected:
31  /** Method responsible for reading from the stream.
32  */
33  size_t Read(void *Buffer, size_t Count);
34 
35  /** Method responsible for writing to the stream.
36  * Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.
37  */
38  size_t Write(const void *Buffer, size_t Count);
39 
40  // DECLARE_UNCOPIABLE( CFileOutputStream )
41 
42  private:
43  std::ofstream m_of; //!< The actual output file stream.
44 
45  public:
46  /** Constructor
47  * \param fileName The file to be open in this stream
48  * \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.
49  * \exception std::exception if the file cannot be opened.
50  */
52  const std::string &fileName,
53  bool append = false
54  );
55 
56  /** Default constructor
57  */
59 
60  /** Open the given file for write
61  * \param fileName The file to be open in this stream
62  * \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.
63  * \sa fileOpenCorrectly
64  * \return true on success.
65  */
66  bool open(const std::string &fileName, bool append = false );
67 
68  /** Close the stream. */
69  void close();
70 
71  /** Destructor
72  */
73  virtual ~CFileOutputStream();
74 
75  /** Says if file was open successfully or not.
76  */
77  bool fileOpenCorrectly();
78 
79  /** Method for moving to a specified position in the streamed resource.
80  * See documentation of CStream::Seek
81  */
82  uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning);
83 
84  /** Method for getting the total number of bytes writen to buffer.
85  */
86  uint64_t getTotalBytesCount();
87 
88  /** Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
89  */
90  uint64_t getPosition();
91 
92 
93  }; // End of class def.
94 
95  } // End of namespace
96 } // end of namespace
97 #endif
TSeekOrigin
Used in CStream::Seek.
Definition: CStream.h:42
std::ofstream m_of
The actual output file stream.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
This CStream derived class allow using a file as a write-only, binary stream.
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.



Page generated by Doxygen 1.8.12 for MRPT 1.3.2 SVN: at Thu Nov 10 13:22:34 UTC 2016