-
Notifications
You must be signed in to change notification settings - Fork 1
/
pch.h
175 lines (147 loc) · 4.67 KB
/
pch.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// Created by code4love on 23-9-23.
//
#ifndef ZPODS_PCH_H
#define ZPODS_PCH_H
#include "spdlog/spdlog.h"
#include <filesystem>
#include <unordered_set>
#include <type_traits>
#include <cstdint>
#include <utility>
#include <string>
#include <vector>
#include <ranges>
#include <span>
#include <numeric>
#include <fstream>
#include <cassert>
#include <queue>
#include <stack>
#include <random>
// enums
namespace zpods {
enum class Status : std::uint8_t {
OK,
ERROR,
PATH_NOT_EXIST,
PASSWORD_NEEDED,
NOT_ZPODS_FILE,
CHECKSUM_ERROR,
USER_ALREADY_EXISTS,
USER_NOT_EXISTS,
WRONG_PASSWORD,
NOT_FOUND,
EMPTY,
NO_NEW_TO_ARCHIVE,
};
// enum class FileType : std::uint8_t {
// DIRECTORY = 1 << 0,
// REGULAR_FILE = 1 << 1,
// SYMLINK = 1 << 2,
// PIPE = 1 << 3,
// SOCKET = 1 << 4,
// CHARACTER_DEVICE = 1 << 5,
// BLOCK_DEVICE = 1 << 6,
// UNKNOWN = 1 << 7
// };
}
#ifndef PROJECT_PATH
// do not use this macro directly!
#define PROJECT_PATH "macro PROJECT_PATH needed"
#endif
#ifndef TEST_DATA_PATH
// do not use this macro directly!
#define TEST_DATA_PATH "macro TEST_DATA_PATH needed"
#endif
#ifndef TEMP_PATH
// do not use this macro directly!
#define TEMP_PATH "macro TEMP_PATH needed"
#endif
#define ZPODS_ASSERT(x) \
do { \
if (!(x)) { \
fprintf(stderr, "Assertion failed: `%s`\n", #x); \
exit(1); \
} \
} while (0)
#define ZPODS_ASSERT_MSG(expr, format, ...) \
do { \
if (!(expr)) { \
fprintf(stderr, format, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
exit(1); \
} \
} while (0)
#define let const auto
#define let_ref const auto&
#define let_mut auto
#define let_mut_ref auto&
#define CHECK_STATUS(status) \
if (status != zpods::Status::OK) { \
return status; \
}
namespace zpods {
// template<typename T>
// using ref = const std::remove_cvref_t<T> &;
//
// template<typename T>
// using ref_mut = std::remove_cvref_t<T> &;
// static_assert(std::is_same_v<ref<int>, const int &>);
// static_assert(std::is_same_v<ref<int &>, const int &>);
// static_assert(std::is_same_v<ref<int &&>, const int &>);
// static_assert(std::is_same_v<ref<const int>, const int &>);
// static_assert(std::is_same_v<ref<const int &>, const int &>);
// static_assert(std::is_same_v<ref<const int &&>, const int &>);
// static_assert(std::is_same_v<ref_mut<int>, int &>);
// static_assert(std::is_same_v<ref_mut<int &>, int &>);
// static_assert(std::is_same_v<ref_mut<int &&>, int &>);
// static_assert(std::is_same_v<ref_mut<const int>, int &>);
// static_assert(std::is_same_v<ref_mut<const int &>, int &>);
// static_assert(std::is_same_v<ref_mut<const int &&>, int &>);
using byte = unsigned char;
using p_cbyte = const byte *;
using p_byte = byte *;
inline auto as_p_byte(auto* p) {
return (byte*)(p);
}
constexpr auto BYTE_BITS = 8;
inline constexpr const char *project_path() {
return PROJECT_PATH;
}
inline constexpr const char *test_data_path() {
return TEST_DATA_PATH;
}
inline constexpr const char *temp_path() {
return TEMP_PATH;
}
constexpr auto ceil_div(auto a, auto b) {
return (a + b - 1) / b;
}
constexpr size_t mask(size_t bits) {
return (1 << bits) - 1;
}
constexpr size_t bits_part(size_t bits, size_t offset, size_t cnt) {
return (mask(cnt) & bits) << offset;
}
template<typename T>
constexpr auto enabled(T bits, auto opt) {
return (bits & static_cast<T>(opt)) != 0;
}
template<typename T>
void print_map(const T &map) {
spdlog::debug("[MAP] map size: {}", map.size());
for (let_ref[key, val]: map) {
spdlog::debug("key: {}, value: {}", key, val);
}
}
template<typename T>
auto as_c_str(T &&str) {
return reinterpret_cast<const char *>(&str);
}
template<typename T>
auto as_c_str(T *str) {
return reinterpret_cast<const char *>(str);
}
}
#endif //ZPODS_PCH_H