Main MRPT website > C++ reference for MRPT 1.9.9
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
21  * stream.
22  *
23  * \sa CStream, CFileStream, CFileGZOutputStream
24  * \ingroup mrpt_base_grp
25  */
26 class CFileOutputStream : public CStream
27 {
28  protected:
29  size_t Read(void* Buffer, size_t Count) override;
30  size_t Write(const void* Buffer, size_t Count) override;
31 
32  private:
33  /** The actual output file stream. */
34  std::ofstream m_of;
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
40  * current cursor position set at the end of the file. Otherwise, previous
41  * contents will be lost.
42  * \exception std::exception if the file cannot be opened.
43  */
44  CFileOutputStream(const std::string& fileName, bool append = false);
45 
46  /** Default constructor */
48 
49  CFileOutputStream(const CFileOutputStream&) = delete;
51 
52  /** Open the given file for write
53  * \param fileName The file to be open in this stream
54  * \param append If set to true, the file will be opened for writing and the
55  * current cursor position set at the end of the file. Otherwise, previous
56  * contents will be lost.
57  * \sa fileOpenCorrectly
58  * \return true on success.
59  */
60  bool open(const std::string& fileName, bool append = false);
61 
62  /** Close the stream. */
63  void close();
64 
65  /** Destructor */
66  virtual ~CFileOutputStream();
67 
68  /** Returns true if the file was open without errors. */
69  bool fileOpenCorrectly();
70  /** Returns true if the file was open without errors. */
71  bool is_open() { return fileOpenCorrectly(); }
72  // See base class docs
73  uint64_t Seek(
74  uint64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning) override;
75 
76  /** Method for getting the total number of bytes writen to buffer */
77  uint64_t getTotalBytesCount() override;
78 
79  /** Method for getting the current cursor position, where 0 is the first
80  * byte and TotalBytesCount-1 the last one */
81  uint64_t getPosition() override;
82 }; // End of class def.
83 static_assert(
86  "Copy Check");
87 } // End of namespace
88 } // end of namespace
89 #endif
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
bool fileOpenCorrectly()
Returns true if the file was open without errors.
void close()
Close the stream.
uint64_t Seek(uint64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
TSeekOrigin
Used in CStream::Seek.
Definition: CStream.h:45
bool open(const std::string &fileName, bool append=false)
Open the given file for write.
std::ofstream m_of
The actual output file stream.
uint64_t getPosition() override
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the l...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
This CStream derived class allow using a file as a write-only, binary stream.
GLsizei const GLchar ** string
Definition: glext.h:4101
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CFileOutputStream()
Default constructor.
GLsizei const GLfloat * value
Definition: glext.h:4117
CFileOutputStream & operator=(const CFileOutputStream &)=delete
bool is_open()
Returns true if the file was open without errors.
virtual ~CFileOutputStream()
Destructor.
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
uint64_t getTotalBytesCount() override
Method for getting the total number of bytes writen to buffer.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019