Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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  size_t Read(void *Buffer, size_t Count) MRPT_OVERRIDE;
32  size_t Write(const void *Buffer, size_t Count) MRPT_OVERRIDE;
33  private:
34  std::ofstream m_of; //!< The actual output file stream.
35 
36  public:
37  /** Constructor
38  * \param fileName The file to be open in this stream
39  * \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.
40  * \exception std::exception if the file cannot be opened.
41  */
43  const std::string &fileName,
44  bool append = false
45  );
46 
47  /** Default constructor */
49 
50  /** Open the given file for write
51  * \param fileName The file to be open in this stream
52  * \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.
53  * \sa fileOpenCorrectly
54  * \return true on success.
55  */
56  bool open(const std::string &fileName, bool append = false );
57 
58  /** Close the stream. */
59  void close();
60 
61  /** Destructor */
62  virtual ~CFileOutputStream();
63 
64  bool fileOpenCorrectly(); //!< Returns true if the file was open without errors.
65  bool is_open() { return fileOpenCorrectly(); } //!< Returns true if the file was open without errors.
66 
67  // See base class docs
68  uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning) MRPT_OVERRIDE;
69 
70  /** Method for getting the total number of bytes writen to buffer */
71  uint64_t getTotalBytesCount() MRPT_OVERRIDE;
72 
73  /** Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one */
74  uint64_t getPosition() MRPT_OVERRIDE;
75  }; // End of class def.
76  } // End of namespace
77 } // end of namespace
78 #endif
TSeekOrigin
Used in CStream::Seek.
Definition: CStream.h:42
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
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.
bool is_open()
Returns true if the file was open without errors.



Page generated by Doxygen 1.8.11 for MRPT 1.4.0 SVN:Unversioned directory at Mon May 30 18:20:32 UTC 2016