MRPT
2.0.4
mrpt
io
io/CFileInputStream.h
Go to the documentation of this file.
1
/* +------------------------------------------------------------------------+
2
| Mobile Robot Programming Toolkit (MRPT) |
3
| https://www.mrpt.org/ |
4
| |
5
| Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6
| See: https://www.mrpt.org/Authors - All rights reserved. |
7
| Released under BSD License. See: https://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 read-only, binary stream.
17
*
18
* \sa CStream, CFileStream, CFileGZInputStream
19
* \ingroup mrpt_io_grp
20
*/
21
class
CFileInputStream
:
public
CStream
22
{
23
private
:
24
/** The actual input file stream. */
25
std::ifstream
m_if
;
26
27
public
:
28
/** Constructor
29
* \param fileName The file to be open in this stream
30
* \exception std::exception On error trying to open the file.
31
*/
32
CFileInputStream
(
const
std::string& fileName);
33
/** Default constructor */
34
CFileInputStream
();
35
36
CFileInputStream
(
const
CFileInputStream
&) =
delete
;
37
CFileInputStream
&
operator=
(
const
CFileInputStream
&) =
delete
;
38
39
~CFileInputStream
()
override
;
40
41
/** Open a file for reading
42
* \param fileName The file to be open in this stream
43
* \return true on success.
44
*/
45
bool
open
(
const
std::string& fileName);
46
/** Close the stream */
47
void
close
();
48
/** Returns true if the file was open without errors. */
49
bool
fileOpenCorrectly
()
const
;
50
/** Returns true if the file was open without errors. */
51
bool
is_open
() {
return
fileOpenCorrectly
(); }
52
/** Will be true if EOF has been already reached. */
53
bool
checkEOF
();
54
/** Resets stream error status bits (e.g. after an EOF) */
55
void
clearError
();
56
57
// See docs in base class
58
uint64_t
Seek
(
59
int64_t off,
CStream::TSeekOrigin
Origin =
sFromBeginning
)
override
;
60
// See docs in base class
61
uint64_t
getTotalBytesCount
()
const override
;
62
// See docs in base class
63
uint64_t
getPosition
()
const override
;
64
65
/** Reads one string line from the file (until a new-line character)
66
* \return true if a line has been read, false on EOF or error. */
67
bool
readLine
(std::string& str);
68
69
size_t
Read
(
void
* Buffer,
size_t
Count)
override
;
70
size_t
Write
(
const
void
* Buffer,
size_t
Count)
override
;
71
};
// End of class def.
72
}
// namespace mrpt::io
mrpt::io::CStream::TSeekOrigin
TSeekOrigin
Used in CStream::Seek.
Definition:
io/CStream.h:32
mrpt::io::CFileInputStream::close
void close()
Close the stream.
Definition:
CFileInputStream.cpp:54
mrpt::io::CFileInputStream::checkEOF
bool checkEOF()
Will be true if EOF has been already reached.
Definition:
CFileInputStream.cpp:164
mrpt::io::CFileInputStream::open
bool open(const std::string &fileName)
Open a file for reading.
Definition:
CFileInputStream.cpp:43
mrpt::io::CFileInputStream::Write
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
Definition:
CFileInputStream.cpp:79
mrpt::io::CStream::sFromBeginning
Definition:
io/CStream.h:34
mrpt::io::CFileInputStream::clearError
void clearError()
Resets stream error status bits (e.g.
Definition:
CFileInputStream.cpp:170
mrpt::io::CFileInputStream::Seek
uint64_t Seek(int64_t off, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
Definition:
CFileInputStream.cpp:90
mrpt::io::CFileInputStream::is_open
bool is_open()
Returns true if the file was open without errors.
Definition:
io/CFileInputStream.h:51
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:28
mrpt::io::CFileInputStream
This CStream derived class allow using a file as a read-only, binary stream.
Definition:
io/CFileInputStream.h:21
mrpt::io::CFileInputStream::Read
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
Definition:
CFileInputStream.cpp:67
mrpt::io::CFileInputStream::readLine
bool readLine(std::string &str)
Reads one string line from the file (until a new-line character)
Definition:
CFileInputStream.cpp:152
CStream.h
mrpt::io::CFileInputStream::m_if
std::ifstream m_if
The actual input file stream.
Definition:
io/CFileInputStream.h:25
mrpt::io::CFileInputStream::operator=
CFileInputStream & operator=(const CFileInputStream &)=delete
mrpt::io::CFileInputStream::~CFileInputStream
~CFileInputStream() override
Definition:
CFileInputStream.cpp:62
mrpt::io
Definition:
img/CImage.h:24
mrpt::io::CFileInputStream::getTotalBytesCount
uint64_t getTotalBytesCount() const override
Returns the total amount of bytes in the stream.
Definition:
CFileInputStream.cpp:120
mrpt::io::CFileInputStream::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:
CFileInputStream.cpp:136
mrpt::io::CFileInputStream::CFileInputStream
CFileInputStream()
Default constructor.
Definition:
CFileInputStream.cpp:39
mrpt::io::CFileInputStream::fileOpenCorrectly
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
Definition:
CFileInputStream.cpp:148
Page generated by
Doxygen 1.8.14
for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020