Main MRPT website > C++ reference for MRPT 1.9.9
CFileGZInputStream.cpp
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 
10 #include "io-precomp.h" // Precompiled headers
11 
13 #include <mrpt/system/filesystem.h>
14 #include <mrpt/core/exceptions.h>
15 
16 #include <zlib.h>
17 
18 using namespace mrpt::io;
19 using namespace std;
20 
21 static_assert(
24  "Copy Check");
25 
26 #define THE_GZFILE reinterpret_cast<gzFile>(m_f)
27 
28 CFileGZInputStream::CFileGZInputStream(const string& fileName) : m_f(nullptr)
29 {
31  open(fileName);
32  MRPT_END
33 }
34 
37 {
39 
40  if (m_f) gzclose(THE_GZFILE);
41 
42  // Get compressed file size:
44  if (m_file_size == uint64_t(-1))
45  THROW_EXCEPTION_FMT("Couldn't access the file '%s'", fileName.c_str());
46 
47  // Open gz stream:
48  m_f = gzopen(fileName.c_str(), "rb");
49  return m_f != nullptr;
50 
51  MRPT_END
52 }
53 
55 {
56  if (m_f)
57  {
58  gzclose(THE_GZFILE);
59  m_f = nullptr;
60  }
61 }
62 
64 size_t CFileGZInputStream::Read(void* Buffer, size_t Count)
65 {
66  if (!m_f)
67  {
68  THROW_EXCEPTION("File is not open.");
69  }
70 
71  return gzread(THE_GZFILE, Buffer, Count);
72 }
73 
74 size_t CFileGZInputStream::Write(const void* Buffer, size_t Count)
75 {
76  MRPT_UNUSED_PARAM(Buffer);
77  MRPT_UNUSED_PARAM(Count);
78  THROW_EXCEPTION("Trying to write to an input file stream.");
79 }
80 
82 {
83  if (!m_f)
84  {
85  THROW_EXCEPTION("File is not open.");
86  }
87  return m_file_size;
88 }
89 
91 {
92  if (!m_f)
93  {
94  THROW_EXCEPTION("File is not open.");
95  }
96  return gztell(THE_GZFILE);
97 }
98 
99 bool CFileGZInputStream::fileOpenCorrectly() const { return m_f != nullptr; }
101 {
102  if (!m_f)
103  return true;
104  else
105  return 0 != gzeof(THE_GZFILE);
106 }
107 
109 {
110  THROW_EXCEPTION("Method not available in this class.");
111 }
filesystem.h
mrpt::io::CStream::TSeekOrigin
TSeekOrigin
Used in CStream::Seek.
Definition: io/CStream.h:34
mrpt::io::CFileGZInputStream::CFileGZInputStream
CFileGZInputStream()
Constructor without open.
Definition: CFileGZInputStream.cpp:35
exceptions.h
mrpt::io
Definition: img/CImage.h:22
mrpt::io::CFileGZInputStream::m_f
void * m_f
Definition: io/CFileGZInputStream.h:29
mrpt::io::CFileGZInputStream::Write
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
Definition: CFileGZInputStream.cpp:74
MRPT_UNUSED_PARAM
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186
int64_t
__int64 int64_t
Definition: rptypes.h:49
THROW_EXCEPTION_FMT
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:43
THE_GZFILE
#define THE_GZFILE
Definition: CFileGZInputStream.cpp:26
mrpt::io::CFileGZInputStream::getTotalBytesCount
uint64_t getTotalBytesCount() const override
Method for getting the total number of compressed bytes of in the file (the physical size of the comp...
Definition: CFileGZInputStream.cpp:81
mrpt::io::CFileGZInputStream::~CFileGZInputStream
virtual ~CFileGZInputStream()
Dtor.
Definition: CFileGZInputStream.cpp:63
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
mrpt::io::CFileGZInputStream::Read
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
Definition: CFileGZInputStream.cpp:64
mrpt::io::CFileGZInputStream::Seek
uint64_t Seek(int64_t, CStream::TSeekOrigin=sFromBeginning) override
This method is not implemented in this class.
Definition: CFileGZInputStream.cpp:108
mrpt::io::CFileGZInputStream::open
bool open(const std::string &fileName)
Opens the file for read.
Definition: CFileGZInputStream.cpp:36
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::io::CFileGZInputStream::close
void close()
Closes the file.
Definition: CFileGZInputStream.cpp:54
uint64_t
unsigned __int64 uint64_t
Definition: rptypes.h:50
mrpt::io::CFileGZInputStream::m_file_size
uint64_t m_file_size
Compressed file size.
Definition: io/CFileGZInputStream.h:31
mrpt::io::CFileGZInputStream::getPosition
uint64_t getPosition() const override
Method for getting the current cursor position in the compressed, where 0 is the first byte and Total...
Definition: CFileGZInputStream.cpp:90
value
GLsizei const GLfloat * value
Definition: glext.h:4117
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
CFileGZInputStream.h
mrpt::io::CFileGZInputStream::checkEOF
bool checkEOF()
Will be true if EOF has been already reached.
Definition: CFileGZInputStream.cpp:100
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::io::CFileGZInputStream::fileOpenCorrectly
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
Definition: CFileGZInputStream.cpp:99
io-precomp.h
zlib.h
mrpt::system::getFileSize
uint64_t getFileSize(const std::string &fileName)
Return the size of the given file, or size_t(-1) if some error is found accessing that file.
Definition: filesystem.cpp:350



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