extlzham 0.0.1.PROTOTYPE

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +27 -0
  3. data/README.md +21 -0
  4. data/Rakefile +143 -0
  5. data/contrib/lzham/LICENSE +22 -0
  6. data/contrib/lzham/README.md +209 -0
  7. data/contrib/lzham/include/lzham.h +781 -0
  8. data/contrib/lzham/lzhamcomp/lzham_comp.h +38 -0
  9. data/contrib/lzham/lzhamcomp/lzham_lzbase.cpp +244 -0
  10. data/contrib/lzham/lzhamcomp/lzham_lzbase.h +45 -0
  11. data/contrib/lzham/lzhamcomp/lzham_lzcomp.cpp +608 -0
  12. data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.cpp +1966 -0
  13. data/contrib/lzham/lzhamcomp/lzham_lzcomp_internal.h +472 -0
  14. data/contrib/lzham/lzhamcomp/lzham_lzcomp_state.cpp +1413 -0
  15. data/contrib/lzham/lzhamcomp/lzham_match_accel.cpp +562 -0
  16. data/contrib/lzham/lzhamcomp/lzham_match_accel.h +146 -0
  17. data/contrib/lzham/lzhamcomp/lzham_null_threading.h +97 -0
  18. data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.cpp +229 -0
  19. data/contrib/lzham/lzhamcomp/lzham_pthreads_threading.h +520 -0
  20. data/contrib/lzham/lzhamcomp/lzham_threading.h +12 -0
  21. data/contrib/lzham/lzhamcomp/lzham_win32_threading.cpp +220 -0
  22. data/contrib/lzham/lzhamcomp/lzham_win32_threading.h +368 -0
  23. data/contrib/lzham/lzhamdecomp/lzham_assert.cpp +66 -0
  24. data/contrib/lzham/lzhamdecomp/lzham_assert.h +40 -0
  25. data/contrib/lzham/lzhamdecomp/lzham_checksum.cpp +73 -0
  26. data/contrib/lzham/lzhamdecomp/lzham_checksum.h +13 -0
  27. data/contrib/lzham/lzhamdecomp/lzham_config.h +23 -0
  28. data/contrib/lzham/lzhamdecomp/lzham_core.h +264 -0
  29. data/contrib/lzham/lzhamdecomp/lzham_decomp.h +37 -0
  30. data/contrib/lzham/lzhamdecomp/lzham_helpers.h +54 -0
  31. data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.cpp +262 -0
  32. data/contrib/lzham/lzhamdecomp/lzham_huffman_codes.h +14 -0
  33. data/contrib/lzham/lzhamdecomp/lzham_lzdecomp.cpp +1527 -0
  34. data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.cpp +131 -0
  35. data/contrib/lzham/lzhamdecomp/lzham_lzdecompbase.h +89 -0
  36. data/contrib/lzham/lzhamdecomp/lzham_math.h +142 -0
  37. data/contrib/lzham/lzhamdecomp/lzham_mem.cpp +284 -0
  38. data/contrib/lzham/lzhamdecomp/lzham_mem.h +112 -0
  39. data/contrib/lzham/lzhamdecomp/lzham_platform.cpp +157 -0
  40. data/contrib/lzham/lzhamdecomp/lzham_platform.h +284 -0
  41. data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.cpp +351 -0
  42. data/contrib/lzham/lzhamdecomp/lzham_prefix_coding.h +146 -0
  43. data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.cpp +1484 -0
  44. data/contrib/lzham/lzhamdecomp/lzham_symbol_codec.h +556 -0
  45. data/contrib/lzham/lzhamdecomp/lzham_timer.cpp +147 -0
  46. data/contrib/lzham/lzhamdecomp/lzham_timer.h +99 -0
  47. data/contrib/lzham/lzhamdecomp/lzham_traits.h +141 -0
  48. data/contrib/lzham/lzhamdecomp/lzham_types.h +97 -0
  49. data/contrib/lzham/lzhamdecomp/lzham_utils.h +58 -0
  50. data/contrib/lzham/lzhamdecomp/lzham_vector.cpp +75 -0
  51. data/contrib/lzham/lzhamdecomp/lzham_vector.h +588 -0
  52. data/contrib/lzham/lzhamlib/lzham_lib.cpp +179 -0
  53. data/examples/basic.rb +48 -0
  54. data/ext/extconf.rb +26 -0
  55. data/ext/extlzham.c +741 -0
  56. data/gemstub.rb +22 -0
  57. data/lib/extlzham/version.rb +5 -0
  58. data/lib/extlzham.rb +153 -0
  59. metadata +135 -0
@@ -0,0 +1,73 @@
1
+ // File: lzham_checksum.cpp
2
+ #include "lzham_core.h"
3
+ #include "lzham_checksum.h"
4
+
5
+ namespace lzham
6
+ {
7
+ // Originally from the public domain stb.h header.
8
+ uint adler32(const void* pBuf, size_t buflen, uint adler32)
9
+ {
10
+ if (!pBuf)
11
+ return cInitAdler32;
12
+
13
+ const uint8* buffer = static_cast<const uint8*>(pBuf);
14
+
15
+ const unsigned long ADLER_MOD = 65521;
16
+ unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16;
17
+ size_t blocklen;
18
+ unsigned long i;
19
+
20
+ blocklen = buflen % 5552;
21
+ while (buflen)
22
+ {
23
+ for (i=0; i + 7 < blocklen; i += 8)
24
+ {
25
+ s1 += buffer[0], s2 += s1;
26
+ s1 += buffer[1], s2 += s1;
27
+ s1 += buffer[2], s2 += s1;
28
+ s1 += buffer[3], s2 += s1;
29
+ s1 += buffer[4], s2 += s1;
30
+ s1 += buffer[5], s2 += s1;
31
+ s1 += buffer[6], s2 += s1;
32
+ s1 += buffer[7], s2 += s1;
33
+
34
+ buffer += 8;
35
+ }
36
+
37
+ for (; i < blocklen; ++i)
38
+ s1 += *buffer++, s2 += s1;
39
+
40
+ s1 %= ADLER_MOD, s2 %= ADLER_MOD;
41
+ buflen -= blocklen;
42
+ blocklen = 5552;
43
+ }
44
+ return static_cast<uint>((s2 << 16) + s1);
45
+ }
46
+
47
+ // Karl Malbrain's compact CRC-32, with pre and post conditioning.
48
+ // See "A compact CCITT crc16 and crc32 C implementation that balances processor cache usage against speed":
49
+ // http://www.geocities.com/malbrain/
50
+ static const lzham_uint32 s_crc32[16] =
51
+ {
52
+ 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
53
+ 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
54
+ };
55
+
56
+ uint crc32(uint crc, const lzham_uint8 *ptr, size_t buf_len)
57
+ {
58
+ if (!ptr)
59
+ return cInitCRC32;
60
+
61
+ crc = ~crc;
62
+ while (buf_len--)
63
+ {
64
+ lzham_uint8 b = *ptr++;
65
+ crc = (crc >> 4) ^ s_crc32[(crc & 0xF) ^ (b & 0xF)];
66
+ crc = (crc >> 4) ^ s_crc32[(crc & 0xF) ^ (b >> 4)];
67
+ }
68
+ return ~crc;
69
+ }
70
+
71
+
72
+ } // namespace lzham
73
+
@@ -0,0 +1,13 @@
1
+ // File: lzham_checksum.h
2
+ // See Copyright Notice and license at the end of include/lzham.h
3
+ #pragma once
4
+
5
+ namespace lzham
6
+ {
7
+ const uint cInitAdler32 = 1U;
8
+ uint adler32(const void* pBuf, size_t buflen, uint adler32 = cInitAdler32);
9
+
10
+ const uint cInitCRC32 = 0U;
11
+ uint crc32(uint crc, const lzham_uint8 *ptr, size_t buf_len);
12
+
13
+ } // namespace lzham
@@ -0,0 +1,23 @@
1
+ // File: lzham_config.h
2
+ // See Copyright Notice and license at the end of include/lzham.h
3
+ #pragma once
4
+
5
+ #if defined(_DEBUG) || defined(DEBUG)
6
+ #define LZHAM_BUILD_DEBUG
7
+
8
+ #ifndef DEBUG
9
+ #define DEBUG
10
+ #endif
11
+ #else
12
+ #define LZHAM_BUILD_RELEASE
13
+
14
+ #ifndef NDEBUG
15
+ #define NDEBUG
16
+ #endif
17
+
18
+ #ifdef DEBUG
19
+ #error DEBUG cannot be defined in LZHAM_BUILD_RELEASE
20
+ #endif
21
+ #endif
22
+ #define LZHAM_BUFFERED_PRINTF 0
23
+ #define LZHAM_PERF_SECTIONS 0
@@ -0,0 +1,264 @@
1
+ // File: lzham_core.h
2
+ // See Copyright Notice and license at the end of include/lzham.h
3
+ #pragma once
4
+
5
+ #if defined(_MSC_VER)
6
+ #pragma warning (disable: 4127) // conditional expression is constant
7
+ #endif
8
+
9
+ // Enable this when first porting to new platforms - disables all threading and atomic ops in compressor:
10
+ //#define LZHAM_ANSI_CPLUSPLUS 1
11
+
12
+ #if defined(__FreeBSD__) || defined(__NetBSD__)
13
+ // TODO: I haven't compiled/tested on these platforms yet, let's play it safe for now.
14
+ #define LZHAM_ANSI_CPLUSPLUS 1
15
+ #endif
16
+
17
+ #if defined(__APPLE__) && defined(__MACH__)
18
+ // Apple OSX and iOS
19
+ #include <TargetConditionals.h>
20
+ #endif
21
+
22
+ #if defined(_XBOX) && !defined(LZHAM_ANSI_CPLUSPLUS)
23
+ // --- X360 - This hasn't been tested since early an alpha.
24
+ #include <xtl.h>
25
+ #define _HAS_EXCEPTIONS 0
26
+ #define NOMINMAX
27
+
28
+ #define LZHAM_PLATFORM_X360 1
29
+ #define LZHAM_USE_WIN32_API 1
30
+ #define LZHAM_USE_WIN32_ATOMIC_FUNCTIONS 1
31
+ #define LZHAM_64BIT_POINTERS 0
32
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 1
33
+ #define LZHAM_BIG_ENDIAN_CPU 1
34
+ #define LZHAM_USE_UNALIGNED_INT_LOADS 1
35
+ #define LZHAM_RESTRICT __restrict
36
+ #define LZHAM_FORCE_INLINE __forceinline
37
+ #define LZHAM_NOTE_UNUSED(x) (void)x
38
+
39
+ #elif defined(WIN32) && !defined(LZHAM_ANSI_CPLUSPLUS)
40
+ // --- Windows: MSVC or MinGW, x86 or x64, Win32 API's for threading and Win32 Interlocked API's or GCC built-ins for atomic ops.
41
+ #ifdef NDEBUG
42
+ // Ensure checked iterators are disabled.
43
+ #define _SECURE_SCL 0
44
+ #define _HAS_ITERATOR_DEBUGGING 0
45
+ #endif
46
+ #ifndef _DLL
47
+ // If we're using the DLL form of the run-time libs, we're also going to be enabling exceptions because we'll be building CLR apps.
48
+ // Otherwise, we disable exceptions for a small speed boost.
49
+ #define _HAS_EXCEPTIONS 0
50
+ #endif
51
+ #define NOMINMAX
52
+
53
+ #ifndef _WIN32_WINNT
54
+ #define _WIN32_WINNT 0x500
55
+ #endif
56
+
57
+ #ifndef WIN32_LEAN_AND_MEAN
58
+ #define WIN32_LEAN_AND_MEAN
59
+ #endif
60
+
61
+ #include <windows.h>
62
+
63
+ #define LZHAM_USE_WIN32_API 1
64
+
65
+ #if defined(__MINGW32__) || defined(__MINGW64__)
66
+ #define LZHAM_USE_GCC_ATOMIC_BUILTINS 1
67
+ #else
68
+ #define LZHAM_USE_WIN32_ATOMIC_FUNCTIONS 1
69
+ #endif
70
+
71
+ #define LZHAM_PLATFORM_PC 1
72
+
73
+ #ifdef _WIN64
74
+ #define LZHAM_PLATFORM_PC_X64 1
75
+ #define LZHAM_64BIT_POINTERS 1
76
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 1
77
+ #define LZHAM_LITTLE_ENDIAN_CPU 1
78
+ #else
79
+ #define LZHAM_PLATFORM_PC_X86 1
80
+ #define LZHAM_64BIT_POINTERS 0
81
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 0
82
+ #define LZHAM_LITTLE_ENDIAN_CPU 1
83
+ #endif
84
+
85
+ #define LZHAM_USE_UNALIGNED_INT_LOADS 1
86
+ #define LZHAM_RESTRICT __restrict
87
+ #define LZHAM_FORCE_INLINE __forceinline
88
+
89
+ #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
90
+ #define LZHAM_USE_MSVC_INTRINSICS 1
91
+ #endif
92
+
93
+ #define LZHAM_NOTE_UNUSED(x) (void)x
94
+
95
+ #elif defined(__APPLE__) && !defined(LZHAM_ANSI_CPLUSPLUS)
96
+ // --- Apple: iOS or OSX
97
+ #if (TARGET_IPHONE_SIMULATOR == 1) || (TARGET_OS_IPHONE == 1)
98
+ #define LZHAM_PLATFORM_PC 0
99
+
100
+ #if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
101
+ #define LZHAM_PLATFORM_PC_X64 0
102
+ #define LZHAM_64BIT_POINTERS 1
103
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 1
104
+ #else
105
+ #define LZHAM_PLATFORM_PC_X86 0
106
+ #define LZHAM_64BIT_POINTERS 0
107
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 0
108
+ #endif
109
+
110
+ #define LZHAM_USE_UNALIGNED_INT_LOADS 0
111
+
112
+ #if __BIG_ENDIAN__
113
+ #define LZHAM_BIG_ENDIAN_CPU 1
114
+ #else
115
+ #define LZHAM_LITTLE_ENDIAN_CPU 1
116
+ #endif
117
+
118
+ #define LZHAM_USE_PTHREADS_API 1
119
+ #define LZHAM_USE_GCC_ATOMIC_BUILTINS 1
120
+
121
+ #define LZHAM_RESTRICT
122
+
123
+ #if defined(__clang__)
124
+ #define LZHAM_FORCE_INLINE inline
125
+ #else
126
+ #define LZHAM_FORCE_INLINE inline __attribute__((__always_inline__,__gnu_inline__))
127
+ #endif
128
+
129
+ #define LZHAM_NOTE_UNUSED(x) (void)x
130
+
131
+ #elif (TARGET_OS_MAC == 1)
132
+ #define LZHAM_PLATFORM_PC 1
133
+
134
+ #if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
135
+ #define LZHAM_PLATFORM_PC_X64 1
136
+ #define LZHAM_64BIT_POINTERS 1
137
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 1
138
+ #else
139
+ #define LZHAM_PLATFORM_PC_X86 1
140
+ #define LZHAM_64BIT_POINTERS 0
141
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 0
142
+ #endif
143
+
144
+ #define LZHAM_USE_UNALIGNED_INT_LOADS 1
145
+
146
+ #if __BIG_ENDIAN__
147
+ #define LZHAM_BIG_ENDIAN_CPU 1
148
+ #else
149
+ #define LZHAM_LITTLE_ENDIAN_CPU 1
150
+ #endif
151
+
152
+ #define LZHAM_USE_PTHREADS_API 1
153
+ #define LZHAM_USE_GCC_ATOMIC_BUILTINS 1
154
+
155
+ #define LZHAM_RESTRICT
156
+
157
+ #if defined(__clang__)
158
+ #define LZHAM_FORCE_INLINE inline
159
+ #else
160
+ #define LZHAM_FORCE_INLINE inline __attribute__((__always_inline__,__gnu_inline__))
161
+ #endif
162
+
163
+ #define LZHAM_NOTE_UNUSED(x) (void)x
164
+ #elif
165
+ #error TODO: Unknown Apple target
166
+ #endif
167
+
168
+ #elif defined(__linux__) && (defined(__i386__) || defined(__x86_64__)) && !defined(LZHAM_ANSI_CPLUSPLUS)
169
+ // --- Generic GCC/clang path for x86/x64, clang or GCC, Linux, OSX, FreeBSD or NetBSD, pthreads for threading, GCC built-ins for atomic ops.
170
+ #define LZHAM_PLATFORM_PC 1
171
+
172
+ #if defined(_LP64) || defined(__LP64__) || defined(__x86_64__)
173
+ // 64-bit build assumes pointers are always 64-bit
174
+ #define LZHAM_PLATFORM_PC_X64 1
175
+ #define LZHAM_64BIT_POINTERS 1
176
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 1
177
+ #else
178
+ #define LZHAM_PLATFORM_PC_X86 1
179
+ #define LZHAM_64BIT_POINTERS 0
180
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 0
181
+ #endif
182
+
183
+ #define LZHAM_USE_UNALIGNED_INT_LOADS 1
184
+
185
+ #if __BIG_ENDIAN__
186
+ #define LZHAM_BIG_ENDIAN_CPU 1
187
+ #else
188
+ #define LZHAM_LITTLE_ENDIAN_CPU 1
189
+ #endif
190
+
191
+ #define LZHAM_USE_PTHREADS_API 1
192
+ #define LZHAM_USE_GCC_ATOMIC_BUILTINS 1
193
+
194
+ #define LZHAM_RESTRICT
195
+
196
+ #if defined(__clang__)
197
+ #define LZHAM_FORCE_INLINE inline
198
+ #else
199
+ #define LZHAM_FORCE_INLINE inline __attribute__((__always_inline__,__gnu_inline__))
200
+ #endif
201
+
202
+ #define LZHAM_NOTE_UNUSED(x) (void)x
203
+ #else
204
+ #warning Building as vanilla ANSI-C/C++, multi-threaded compression is disabled! Please configure lzhamdecomp/lzham_core.h.
205
+
206
+ // --- Vanilla ANSI-C/C++
207
+ // No threading support, unaligned loads are NOT okay, no atomic ops.
208
+ #if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
209
+ #define LZHAM_64BIT_POINTERS 1
210
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 1
211
+ #else
212
+ #define LZHAM_64BIT_POINTERS 0
213
+ #define LZHAM_CPU_HAS_64BIT_REGISTERS 0
214
+ #endif
215
+
216
+ #define LZHAM_USE_UNALIGNED_INT_LOADS 0
217
+
218
+ #if __BIG_ENDIAN__
219
+ #define LZHAM_BIG_ENDIAN_CPU 1
220
+ #else
221
+ #define LZHAM_LITTLE_ENDIAN_CPU 1
222
+ #endif
223
+
224
+ #define LZHAM_USE_GCC_ATOMIC_BUILTINS 0
225
+ #define LZHAM_USE_WIN32_ATOMIC_FUNCTIONS 0
226
+
227
+ #define LZHAM_RESTRICT
228
+ #define LZHAM_FORCE_INLINE inline
229
+
230
+ #define LZHAM_NOTE_UNUSED(x) (void)x
231
+ #endif
232
+
233
+ #if LZHAM_LITTLE_ENDIAN_CPU
234
+ const bool c_lzham_little_endian_platform = true;
235
+ #else
236
+ const bool c_lzham_little_endian_platform = false;
237
+ #endif
238
+
239
+ const bool c_lzham_big_endian_platform = !c_lzham_little_endian_platform;
240
+
241
+ #include <stdlib.h>
242
+ #include <stdio.h>
243
+ #include <math.h>
244
+ #if !defined(__APPLE__) && !defined(__FreeBSD__)
245
+ #include <malloc.h>
246
+ #endif
247
+ #include <stdarg.h>
248
+ #include <memory.h>
249
+ #include <limits.h>
250
+ #include <algorithm>
251
+ #include <errno.h>
252
+
253
+ #include "lzham.h"
254
+ #include "lzham_config.h"
255
+ #include "lzham_types.h"
256
+ #include "lzham_assert.h"
257
+ #include "lzham_platform.h"
258
+
259
+ #include "lzham_helpers.h"
260
+ #include "lzham_traits.h"
261
+ #include "lzham_mem.h"
262
+ #include "lzham_math.h"
263
+ #include "lzham_utils.h"
264
+ #include "lzham_vector.h"
@@ -0,0 +1,37 @@
1
+ // File: lzham_decomp.h
2
+ // See Copyright Notice and license at the end of include/lzham.h
3
+ #pragma once
4
+ #include "lzham.h"
5
+
6
+ namespace lzham
7
+ {
8
+ void LZHAM_CDECL lzham_lib_set_memory_callbacks(lzham_realloc_func pRealloc, lzham_msize_func pMSize, void* pUser_data);
9
+
10
+ lzham_decompress_state_ptr LZHAM_CDECL lzham_lib_decompress_init(const lzham_decompress_params *pParams);
11
+
12
+ lzham_decompress_state_ptr LZHAM_CDECL lzham_lib_decompress_reinit(lzham_decompress_state_ptr pState, const lzham_decompress_params *pParams);
13
+
14
+ lzham_uint32 LZHAM_CDECL lzham_lib_decompress_deinit(lzham_decompress_state_ptr pState);
15
+
16
+ lzham_decompress_status_t LZHAM_CDECL lzham_lib_decompress(
17
+ lzham_decompress_state_ptr pState,
18
+ const lzham_uint8 *pIn_buf, size_t *pIn_buf_size,
19
+ lzham_uint8 *pOut_buf, size_t *pOut_buf_size,
20
+ lzham_bool no_more_input_bytes_flag);
21
+
22
+ lzham_decompress_status_t LZHAM_CDECL lzham_lib_decompress_memory(const lzham_decompress_params *pParams,
23
+ lzham_uint8* pDst_buf, size_t *pDst_len,
24
+ const lzham_uint8* pSrc_buf, size_t src_len, lzham_uint32 *pAdler32);
25
+
26
+ int LZHAM_CDECL lzham_lib_z_inflateInit2(lzham_z_streamp pStream, int window_bits);
27
+ int LZHAM_CDECL lzham_lib_z_inflateInit(lzham_z_streamp pStream);
28
+ int LZHAM_CDECL lzham_lib_z_inflateReset(lzham_z_streamp pStream);
29
+ int LZHAM_CDECL lzham_lib_z_inflate(lzham_z_streamp pStream, int flush);
30
+ int LZHAM_CDECL lzham_lib_z_inflateEnd(lzham_z_streamp pStream);
31
+ int LZHAM_CDECL lzham_lib_z_uncompress(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len);
32
+
33
+ const char * LZHAM_CDECL lzham_lib_z_error(int err);
34
+ lzham_z_ulong lzham_lib_z_adler32(lzham_z_ulong adler, const unsigned char *ptr, size_t buf_len);
35
+ lzham_z_ulong LZHAM_CDECL lzham_lib_z_crc32(lzham_z_ulong crc, const lzham_uint8 *ptr, size_t buf_len);
36
+
37
+ } // namespace lzham
@@ -0,0 +1,54 @@
1
+ // File: lzham_helpers.h
2
+ // See Copyright Notice and license at the end of include/lzham.h
3
+ #pragma once
4
+
5
+ #define LZHAM_NO_COPY_OR_ASSIGNMENT_OP(c) c(const c&); c& operator= (const c&);
6
+
7
+ namespace lzham
8
+ {
9
+ namespace helpers
10
+ {
11
+ template<typename T> struct rel_ops
12
+ {
13
+ friend inline bool operator!=(const T& x, const T& y) { return (!(x == y)); }
14
+ friend inline bool operator> (const T& x, const T& y) { return (y < x); }
15
+ friend inline bool operator<=(const T& x, const T& y) { return (!(y < x)); }
16
+ friend inline bool operator>=(const T& x, const T& y) { return (!(x < y)); }
17
+ };
18
+
19
+ template <typename T>
20
+ inline T* construct(T* p)
21
+ {
22
+ return new (static_cast<void*>(p)) T;
23
+ }
24
+
25
+ template <typename T, typename U>
26
+ inline T* construct(T* p, const U& init)
27
+ {
28
+ return new (static_cast<void*>(p)) T(init);
29
+ }
30
+
31
+ template <typename T>
32
+ inline void construct_array(T* p, uint n);
33
+
34
+ template <typename T, typename U>
35
+ inline void construct_array(T* p, uint n, const U& init)
36
+ {
37
+ T* q = p + n;
38
+ for ( ; p != q; ++p)
39
+ new (static_cast<void*>(p)) T(init);
40
+ }
41
+
42
+ template <typename T>
43
+ inline void destruct(T* p)
44
+ {
45
+ LZHAM_NOTE_UNUSED(p);
46
+ p->~T();
47
+ }
48
+
49
+ template <typename T>
50
+ inline void destruct_array(T* p, uint n);
51
+
52
+ } // namespace helpers
53
+
54
+ } // namespace lzham