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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020