This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nxzutil.h
105 lines (81 loc) · 1.81 KB
/
nxzutil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* A Simple Utility Header-File Only Lib for NXZIP
* 2019-04-07
*/
#ifndef __NXZIP_UTILITY_H
#define __NXZIP_UTILITY_H
#include <iostream>
#include <cstring>
#include <cstdio>
namespace NXZIP::utility
{
/* variable length buffer class for RLE/Huffman */
class VLBUFF
{
public:
/* variable length buffer class for RLE/Huffman */
uint8_t* uptr;
uint32_t ulength;
VLBUFF(uint32_t n)
{
if(n == 0u) { return ; }
ulength = n; uptr = new uint8_t[ulength]{0u}; posbuff = 0u;
}
VLBUFF(VLBUFF& x, uint32_t begin, uint32_t end)
{
ulength = begin - end;
uptr = new uint8_t[ulength];
std::copy(x.uptr+begin, x.uptr+end, uptr);
}
VLBUFF(uint8_t* src, uint32_t size)
{
ulength = size;
uptr = new uint8_t[ulength];
std::copy(src, src+size, uptr);
}
VLBUFF()
{
uptr = nullptr; ulength = 0u; posbuff = 0u;
}
~VLBUFF(void)
{
delete[] uptr; ulength = 0u; posbuff = 0u;
}
int8_t allocate(uint32_t n)
{
if(n == 0u) { return -1; }
if(n == ulength) { posbuff = 0u; return 0u; }
if(uptr != nullptr) { delete[] uptr; }
ulength = n; uptr = new uint8_t[ulength]{0u}; posbuff = 0u;
return 0u;
}
void allocate(void)
{
if(!is_null()) { return ; }
uptr = new uint8_t[ulength]{0u};
}
void vlcopy(void* begin, uint32_t n)
{
std::memcpy((void*)(uptr+posbuff), begin, n);
posbuff += n;
}
void flush(void)
{
if(is_null() || empty()) { return ; }
for(uint32_t i = 0; i < ulength; i++) { uptr[i] = 0u; }
}
bool empty(void) { return ulength == 0u; }
bool is_null(void) { return uptr == nullptr; }
uint8_t& operator[](uint32_t n) { return uptr[n]; }
private:
uint32_t posbuff;
};
/* Command-line options Structure */
struct CLIOPS
{
bool isLogging;
bool isRemoveFile;
};
}
#endif /*__NXZIP_UTILITY_H*/
/* End of File */