nlib
ZlibOutputStream.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_ZLIBOUTPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_ZLIBOUTPUTSTREAM_H_
5 
6 #include "nn/nlib/Platform.h"
7 #ifdef NLIB_HAS_ZLIB
8 
10 
11 NLIB_NAMESPACE_BEGIN
12 
13 class OutputStream;
14 
16  typedef void* (*ReallocFunc)(void* p, size_t n);
17  void* buf_in;
18  void* buf_out;
19  size_t buffer_size;
20  int level;
21  ReallocFunc realloc_func;
22 
23  public:
25  buf_out(NULL),
26  buffer_size(64 * 1024),
27  level(-1),
28  realloc_func(::nlib_realloc) {}
29  NLIB_CEXPR ZlibOutputStreamSettings(void* buf_in_, void* buf_out_, size_t buffer_size_,
30  int level_) NLIB_NOEXCEPT : buf_in(buf_in_),
31  buf_out(buf_out_),
32  buffer_size(buffer_size_),
33  level(level_),
34  realloc_func(::nlib_realloc) {}
35  NLIB_CEXPR ZlibOutputStreamSettings(void* buf_in_, void* buf_out_, size_t buffer_size_,
36  int level_, ReallocFunc realloc_func_) NLIB_NOEXCEPT
37  : buf_in(buf_in_),
38  buf_out(buf_out_),
39  buffer_size(buffer_size_),
40  level(level_),
41  realloc_func(realloc_func_) {}
42 };
43 
45  public:
46  ZlibOutputStream() NLIB_NOEXCEPT : prv_(NULL) {}
50  return this->Init(settings);
51  }
52  errno_t Init(const ZlibOutputStreamSettings& settings) NLIB_NOEXCEPT;
53 
54  private:
55  struct ZlibOutputStreamPrivate;
56  ZlibOutputStreamPrivate* prv_;
58 };
59 
60 NLIB_NAMESPACE_END
61 
62 #endif
63 #endif // INCLUDE_NN_NLIB_ZLIBOUTPUTSTREAM_H_
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:210
errno_t Init() noexcept
Initializes using the default settings.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:145
ZlibOutputStream() noexcept
Instantiates the object with default parameters (default constructor).
void * buf_out
The buffer set for z_stream::next_out.
C-based declaration of the basic API.
void * buf_in
The buffer set for z_stream::next_in.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:61
size_t buffer_size
The size of ZlibOutputStreamSettings::buf_in and ZlibOutputStreamSettings::buf_out.
ReallocFunc realloc_func
The realloc function or its equivalent that ZlibOutputStream uses internally.
The base class for classes that act internally like OutputStream to convert data. ...
constexpr ZlibOutputStreamSettings() noexcept
Instantiates the object with default parameters (default constructor). Sets the default values...
constexpr ZlibOutputStreamSettings(void *buf_in_, void *buf_out_, size_t buffer_size_, int level_) noexcept
Sets the individual data members.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:86
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:80
NLIB_CHECK_RESULT void * nlib_realloc(void *ptr, size_t size)
A weak function that calls the C standard function realloc. nlib calls realloc via this function...
The structure that stores the various ZlibOutputStream settings. At construction time, the default settings are stored.
The class that uses zlib to decompress data and write the data to a stream.
int level
The compression setting to pass to the deflateInit2 function of zlib.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:211
constexpr ZlibOutputStreamSettings(void *buf_in_, void *buf_out_, size_t buffer_size_, int level_, ReallocFunc realloc_func_) noexcept
Sets the individual data members.
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24