Main MRPT website > C++ reference for 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
15 {
16 namespace io
17 {
18 /** This CStream derived class allow using a file as a write-only, binary
19  * stream.
20  *
21  * \sa CStream, CFileStream, CFileGZOutputStream
22  * \ingroup mrpt_io_grp
23  */
24 class CFileOutputStream : public CStream
25 {
26  private:
27  /** The actual output file stream. */
28  std::ofstream m_of;
29 
30  public:
31  /** Constructor
32  * \param fileName The file to be open in this stream
33  * \param append If set to true, the file will be opened for writing and the
34  * current cursor position set at the end of the file. Otherwise, previous
35  * contents will be lost.
36  * \exception std::exception if the file cannot be opened.
37  */
38  CFileOutputStream(const std::string& fileName, bool append = false);
39 
40  /** Default constructor */
42 
43  CFileOutputStream(const CFileOutputStream&) = delete;
45 
46  /** Open the given file for write
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
49  * current cursor position set at the end of the file. Otherwise, previous
50  * contents will be lost.
51  * \sa fileOpenCorrectly
52  * \return true on success.
53  */
54  bool open(const std::string& fileName, bool append = false);
55 
56  /** Close the stream. */
57  void close();
58 
59  /** Destructor */
60  virtual ~CFileOutputStream();
61 
62  /** Returns true if the file was open without errors. */
63  bool fileOpenCorrectly() const;
64  /** Returns true if the file was open without errors. */
65  bool is_open() { return fileOpenCorrectly(); }
66  // See base class docs
67  uint64_t Seek(
68  int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning) override;
69 
70  /** Method for getting the total number of bytes writen to buffer */
71  uint64_t getTotalBytesCount() const override;
72 
73  /** Method for getting the current cursor position, where 0 is the first
74  * byte and TotalBytesCount-1 the last one */
75  uint64_t getPosition() const override;
76 
77  size_t Read(void* Buffer, size_t Count) override;
78  size_t Write(const void* Buffer, size_t Count) override;
79 }; // End of class def.
80 static_assert(
83  "Copy Check");
84 } // End of namespace
85 } // end of namespace
TSeekOrigin
Used in CStream::Seek.
Definition: io/CStream.h:34
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:30
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
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019