Main MRPT website > C++ reference for MRPT 1.9.9
CFileGZOutputStream.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/core/exceptions.h>
14 
15 #include <zlib.h>
16 
17 #define THE_GZFILE reinterpret_cast<gzFile>(m_f)
18 
19 using namespace mrpt::io;
20 using namespace std;
21 
22 CFileGZOutputStream::CFileGZOutputStream(const string& fileName) : m_f(nullptr)
23 {
25  if (!open(fileName))
27  "Error trying to open file: '%s'", fileName.c_str());
28  MRPT_END
29 }
30 
32 bool CFileGZOutputStream::open(const string& fileName, int compress_level)
33 {
35 
36  if (m_f) gzclose(THE_GZFILE);
37 
38  // Open gz stream:
39  m_f = gzopen(fileName.c_str(), format("wb%i", compress_level).c_str());
40  return m_f != nullptr;
41 
42  MRPT_END
43 }
44 
47 {
48  if (m_f)
49  {
50  gzclose(THE_GZFILE);
51  m_f = nullptr;
52  }
53 }
54 
55 size_t CFileGZOutputStream::Read(void*, size_t)
56 {
57  THROW_EXCEPTION("Trying to read from an output file stream.");
58 }
59 
60 size_t CFileGZOutputStream::Write(const void* Buffer, size_t Count)
61 {
62  if (!m_f)
63  {
64  THROW_EXCEPTION("File is not open.");
65  }
66  return gzwrite(THE_GZFILE, const_cast<void*>(Buffer), Count);
67 }
68 
70 {
71  if (!m_f)
72  {
73  THROW_EXCEPTION("File is not open.");
74  }
75  return gztell(THE_GZFILE);
76 }
77 
78 bool CFileGZOutputStream::fileOpenCorrectly() const { return m_f != nullptr; }
80 {
81  THROW_EXCEPTION("Method not available in this class.");
82 }
83 
85 {
86  THROW_EXCEPTION("Method not available in this class.");
87 }
mrpt::io::CStream::TSeekOrigin
TSeekOrigin
Used in CStream::Seek.
Definition: io/CStream.h:34
format
GLenum GLsizei GLenum format
Definition: glext.h:3531
exceptions.h
mrpt::io
Definition: img/CImage.h:22
CFileGZOutputStream.h
mrpt::io::CFileGZOutputStream::Write
size_t Write(const void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for writing to the stream.
Definition: CFileGZOutputStream.cpp:60
mrpt::io::CFileGZOutputStream::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: CFileGZOutputStream.cpp:69
int64_t
__int64 int64_t
Definition: rptypes.h:49
THROW_EXCEPTION_FMT
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:43
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
mrpt::io::CFileGZOutputStream::m_f
void * m_f
Definition: io/CFileGZOutputStream.h:29
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::io::CFileGZOutputStream::CFileGZOutputStream
CFileGZOutputStream()
Constructor, without opening the file.
Definition: CFileGZOutputStream.cpp:31
uint64_t
unsigned __int64 uint64_t
Definition: rptypes.h:50
mrpt::io::CFileGZOutputStream::~CFileGZOutputStream
virtual ~CFileGZOutputStream()
Destructor.
Definition: CFileGZOutputStream.cpp:45
mrpt::io::CFileGZOutputStream::getTotalBytesCount
uint64_t getTotalBytesCount() const override
This method is not implemented in this class.
Definition: CFileGZOutputStream.cpp:84
THE_GZFILE
#define THE_GZFILE
Definition: CFileGZOutputStream.cpp:17
mrpt::io::CFileGZOutputStream::fileOpenCorrectly
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
Definition: CFileGZOutputStream.cpp:78
mrpt::io::CFileGZOutputStream::close
void close()
Close the file.
Definition: CFileGZOutputStream.cpp:46
mrpt::io::CFileGZOutputStream::open
bool open(const std::string &fileName, int compress_level=1)
Open a file for write, choosing the compression level.
Definition: CFileGZOutputStream.cpp:32
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
mrpt::io::CFileGZOutputStream::Seek
uint64_t Seek(int64_t, CStream::TSeekOrigin=sFromBeginning) override
This method is not implemented in this class.
Definition: CFileGZOutputStream.cpp:79
mrpt::io::CFileGZOutputStream::Read
size_t Read(void *Buffer, size_t Count) override
Introduces a pure virtual method responsible for reading from the stream.
Definition: CFileGZOutputStream.cpp:55
io-precomp.h
zlib.h



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