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
mrpt::io::CStream::TSeekOrigin
TSeekOrigin
Used in CStream::Seek.
Definition: io/CStream.h:34
mrpt::io::CFileOutputStream::close
void close()
Close the stream.
Definition: CFileOutputStream.cpp:43
mrpt::io::CFileOutputStream::Write
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
Definition: CFileOutputStream.cpp:56
mrpt::io::CFileOutputStream::open
bool open(const std::string &fileName, bool append=false)
Open the given file for write.
Definition: CFileOutputStream.cpp:31
mrpt::io::CFileOutputStream::~CFileOutputStream
virtual ~CFileOutputStream()
Destructor.
Definition: CFileOutputStream.cpp:48
mrpt::io::CFileOutputStream::getTotalBytesCount
uint64_t getTotalBytesCount() const override
Method for getting the total number of bytes writen to buffer.
Definition: CFileOutputStream.cpp:90
int64_t
__int64 int64_t
Definition: rptypes.h:49
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::io::CFileOutputStream::m_of
std::ofstream m_of
The actual output file stream.
Definition: io/CFileOutputStream.h:28
mrpt::io::CFileOutputStream::getPosition
uint64_t getPosition() const override
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the l...
Definition: CFileOutputStream.cpp:103
mrpt::io::CStream::sFromBeginning
@ sFromBeginning
Definition: io/CStream.h:36
uint64_t
unsigned __int64 uint64_t
Definition: rptypes.h:50
mrpt::io::CFileOutputStream::fileOpenCorrectly
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
Definition: CFileOutputStream.cpp:112
mrpt::io::CFileOutputStream::Seek
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.
Definition: CFileOutputStream.cpp:64
mrpt::io::CFileOutputStream::CFileOutputStream
CFileOutputStream()
Default constructor.
Definition: CFileOutputStream.cpp:30
mrpt::io::CFileOutputStream::operator=
CFileOutputStream & operator=(const CFileOutputStream &)=delete
CStream.h
mrpt::io::CFileOutputStream
This CStream derived class allow using a file as a write-only, binary stream.
Definition: io/CFileOutputStream.h:24
mrpt::io::CFileOutputStream::Read
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
Definition: CFileOutputStream.cpp:49
value
GLsizei const GLfloat * value
Definition: glext.h:4117
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::io::CFileOutputStream::is_open
bool is_open()
Returns true if the file was open without errors.
Definition: io/CFileOutputStream.h:65
mrpt::io::CStream
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: io/CStream.h:30



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST