nlib
Lz4OutputStream.h
[詳解]
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_OSS_LZ4INPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_OSS_LZ4INPUTSTREAM_H_
5 
6 #include "lz4frame.h"
7 #include "nn/nlib/Config.h"
8 #include "nn/nlib/OutputStream.h"
10 
11 #if defined(_MSC_VER) && defined(nx_oss_lz4_EXPORTS)
12 #undef NLIB_VIS_PUBLIC
13 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
14 #endif
15 
16 NLIB_NAMESPACE_BEGIN
17 namespace oss {
18 
19 class Lz4OutputTransform;
21  public:
23  nlib_memset(&pref_, 0, sizeof(pref_));
24  pref_.autoFlush = 1;
25  pref_.frameInfo.blockMode = LZ4F_blockLinked;
26  pref_.compressionLevel = 9; // hc
27  }
28  void SetContentSize(uint64_t size) NLIB_NOEXCEPT { pref_.frameInfo.contentSize = size; }
29  uint64_t GetContentSize() const NLIB_NOEXCEPT { return pref_.frameInfo.contentSize; }
31  if (level < 0)
32  level = 0;
33  else if (level > 16)
34  level = 16;
35  pref_.compressionLevel = level;
36  }
37  int GetCompressionLevel() NLIB_NOEXCEPT { return pref_.compressionLevel; }
38  void SetMaxBlockSize(LZ4F_blockSizeID_t max_block_size) NLIB_NOEXCEPT {
39  pref_.frameInfo.blockSizeID = max_block_size;
40  }
41  LZ4F_blockSizeID_t GetMaxBlockSize() const NLIB_NOEXCEPT { return pref_.frameInfo.blockSizeID; }
42  void SetBlockIndependence(bool independence) NLIB_NOEXCEPT {
43  pref_.frameInfo.blockMode = independence ? LZ4F_blockIndependent : LZ4F_blockLinked;
44  }
46  return (pref_.frameInfo.blockMode != LZ4F_blockLinked);
47  }
48 
49  private:
50  LZ4F_preferences_t pref_;
51  friend class Lz4OutputTransform;
52 };
53 
55  public:
59  Lz4OutputStreamSettings settings;
60  return this->Init(settings);
61  }
62  errno_t Init(const Lz4OutputStreamSettings& settings) NLIB_NOEXCEPT;
63 
64  private:
65  struct Lz4OutputStreamPrivate;
66  Lz4OutputStreamPrivate* prv_;
68 };
69 
70 } // namespace oss
71 NLIB_NAMESPACE_END
72 
73 #if defined(_MSC_VER) && defined(nx_oss_lz4_EXPORTS)
74 #undef NLIB_VIS_PUBLIC
75 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
76 #endif
77 
78 #endif // INCLUDE_NN_NLIB_OSS_LZ4INPUTSTREAM_H_
Lz4OutputStreamSettings() noexcept
デフォルトコンストラクタです。
#define NLIB_OVERRIDE
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
Definition: Config.h:249
uint64_t GetContentSize() const noexcept
SetContentSize()で設定された値を取得します。デフォルトは0です。
static errno_t nlib_memset(void *buf, int ch, size_t n)
内部でmemset(buf, ch, n)相当の関数を呼び出します。
Definition: Platform.h:2544
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:183
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
void SetMaxBlockSize(LZ4F_blockSizeID_t max_block_size) noexcept
データブロックの最大サイズを設定します。大きいほど高速ですがメモリを必要とします。 ...
void SetContentSize(uint64_t size) noexcept
圧縮前のデータサイズをLZ4で圧縮されたデータに含めることができます。
Lz4OutputStreamの設定情報の取得と設定を行うクラスです。
内部でデータ変換を行うOutputStreamのように振る舞うクラスの基底です。
bool GetBlockIndependence() const noexcept
SetBlockIndependence()で設定された値を取得します。デフォルトはfalseです。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:111
開発環境別の設定が書かれるファイルです。
void SetBlockIndependence(bool independence) noexcept
圧縮されたデータブロックが独立して解凍可能かどうかを設定します。
LZ4F_blockSizeID_t GetMaxBlockSize() const noexcept
SetMaxBlockSize()で設定された値を取得します。デフォルトはLZ4F_defaultです。
LZ4のフレームフォーマットに従ったデータを書きこむためのストリームクラスです。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:250
出力ストリームの基底クラスを定義しています。
constexpr Lz4OutputStream() noexcept
デフォルトコンストラクタです。実行後Init()による初期化を必要とします。
int GetCompressionLevel() noexcept
SetCompressionLevel()で設定された値を取得します。デフォルトは9です。
void SetCompressionLevel(int level) noexcept
圧縮レベルを設定します。0-16の整数で数値が大きいほど圧縮率が高くなります。
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37