Main MRPT website > C++ reference for MRPT 1.5.7
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-2017, 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 namespace mrpt
17 {
18 namespace utils
19 {
20  /** This CStream derived class allow using a file as a write-only, binary stream.
21  *
22  * \sa CStream, CFileStream, CFileGZOutputStream
23  * \ingroup mrpt_base_grp
24  */
26  {
27  protected:
28  size_t Read(void *Buffer, size_t Count) MRPT_OVERRIDE;
29  size_t Write(const void *Buffer, size_t Count) MRPT_OVERRIDE;
30  private:
31  std::ofstream m_of; //!< The actual output file stream.
32 
33  public:
34  /** Constructor
35  * \param fileName The file to be open in this stream
36  * \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.
37  * \exception std::exception if the file cannot be opened.
38  */
40  const std::string &fileName,
41  bool append = false
42  );
43 
44  /** Default constructor */
46 
47  /** Open the given file for write
48  * \param fileName The file to be open in this stream
49  * \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.
50  * \sa fileOpenCorrectly
51  * \return true on success.
52  */
53  bool open(const std::string &fileName, bool append = false );
54 
55  /** Close the stream. */
56  void close();
57 
58  /** Destructor */
59  virtual ~CFileOutputStream();
60 
61  bool fileOpenCorrectly(); //!< Returns true if the file was open without errors.
62  bool is_open() { return fileOpenCorrectly(); } //!< Returns true if the file was open without errors.
63 
64  // See base class docs
65  uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning) MRPT_OVERRIDE;
66 
67  /** Method for getting the total number of bytes writen to buffer */
68  uint64_t getTotalBytesCount() MRPT_OVERRIDE;
69 
70  /** Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one */
71  uint64_t getPosition() MRPT_OVERRIDE;
72  }; // End of class def.
73  } // End of namespace
74 } // end of namespace
75 #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.
__int64 int64_t
Definition: rptypes.h:51
The base class of classes that cannot be copied: compile-time errors will be issued on any copy opera...
Definition: CUncopiable.h:30
GLsizei const GLchar ** string
Definition: glext.h:3919
unsigned __int64 uint64_t
Definition: rptypes.h:52
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.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019