-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathtypes.hpp
More file actions
396 lines (316 loc) · 7.98 KB
/
Copy pathtypes.hpp
File metadata and controls
396 lines (316 loc) · 7.98 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/**
* @file liblava/core/types.hpp
* @brief Basic types
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/core/def.hpp"
#include <cstdint>
#include <functional>
#include <map>
#include <string>
#include <string_view>
#include <vector>
namespace lava {
/// 8 bit integer
using int8 = std::int8_t;
/// @see int8
using i8 = int8;
/// 8 bit unsigned integer
using uint8 = std::uint8_t;
/// @see uint8
using ui8 = uint8;
/// 16 bit integer
using int16 = std::int16_t;
/// @see int16
using i16 = int16;
/// 16 bit unsigned integer
using uint16 = std::uint16_t;
/// @see uint16
using ui16 = uint16;
/// 32 bit integer
using int32 = std::int32_t;
/// @see int32
using i32 = int32;
/// 32 bit unsigned integer
using uint32 = std::uint32_t;
/// @see uint32
using ui32 = uint32;
/// 64 bit integer
using int64 = std::int64_t;
/// @see int64
using i64 = int64;
/// 64 bit unsigned integer
using uint64 = std::uint64_t;
/// @see uint64
using ui64 = uint64;
/// 8 bit char
using char8 = std::int_fast8_t;
/// @see char8
using c8 = char8;
/// 8 bit unsigened char
using uchar8 = std::uint_fast8_t;
/// @see uchar8
using uc8 = uchar8;
/// 16 bit char
using char16 = int16;
/// @see char16
using c16 = char16;
/// 16 bit unsigned char
using uchar16 = uint16;
/// @see uchar16
using uc16 = uchar16;
/// 32 bit char
using char32 = int32;
/// @see char32
using c32 = char32;
/// 32 bit unsigned char
using uchar32 = uint32;
/// @see uchar32
using uc32 = uchar32;
/// Size
using size_t = std::size_t;
/// Unsigned char
using uchar = unsigned char;
/// Single-precision floating-point
using r32 = float;
/// Double-precision floating-point
using r64 = double;
/// Real number
using real = r64;
/// Delta
using delta = r32;
/// Void pointer
using void_ptr = void*;
/// Const void pointer
using void_c_ptr = void const*;
/// Undefined value
constexpr i32 const undef = -1;
/// Flag
using flag = ui32;
/// Index
using index = ui32;
/// No index
constexpr index const no_index = 0xffffffff;
/// List of indices
using index_list = std::vector<index>;
/// Map of indices
using index_map = std::map<index, index>;
/// String
using string = std::string;
/// Reference to string
using string_ref = string const&;
/// List of strings
using string_list = std::vector<string>;
/// Reference to list of strings
using string_list_ref = string_list const&;
/// String view
using string_view = std::string_view;
/// Map of strings
using string_map = std::map<string, string>;
/// Reference to map of strings
using string_map_ref = string_map const&;
/// Name
using name = char const*;
/// Reference to name
using name_ref = char const&;
/// List of names
using names = std::vector<name>;
/// Reference to list of names
using names_ref = names const&;
/// lava
constexpr name _lava_ = "lava";
/// liblava
constexpr name _liblava_ = "liblava";
/// default
constexpr name _default_ = "default";
/**
* @brief Get c-string representation of string
* @param value Source string
* @return name C-string representation
*/
inline name str(string_ref value) {
return value.c_str();
}
/**
* @brief Convert to r32
* @param value Source value
* @return r32 Converted value
*/
inline r32 to_r32(auto value) {
return static_cast<r32>(value);
}
/**
* @brief Convert to r64
* @param value Source value
* @return r64 Converted value
*/
inline r64 to_r64(auto value) {
return static_cast<r64>(value);
}
/**
* @brief Convert to i32
* @param value Source value
* @return i32 Converted value
*/
inline i32 to_i32(auto value) {
return static_cast<i32>(value);
}
/**
* @brief Convert to i64
* @param value Source value
* @return i64 Converted value
*/
inline i64 to_i64(auto value) {
return static_cast<i64>(value);
}
/**
* @brief Convert to ui32
* @param value Source value
* @return ui32 Converted value
*/
inline ui32 to_ui32(auto value) {
return static_cast<ui32>(value);
}
/**
* @brief Convert to ui64
* @param value Source value
* @return ui64 Converted value
*/
inline ui64 to_ui64(auto value) {
return static_cast<ui64>(value);
}
/**
* @brief Convert to size_t
* @param value Source value
* @return size_t Converted value
*/
inline size_t to_size_t(auto value) {
return static_cast<size_t>(value);
}
/**
* @brief Convert to index
* @param value Source value
* @return index Converted value
*/
inline index to_index(auto value) {
return static_cast<index>(value);
}
/**
* @brief Convert to pointer const char
* @param value Source value
* @return char const* Converted value
*/
inline char const* to_char(auto value) {
return (char const*)value;
}
/**
* @brief No copy and no move object
*/
struct no_copy_no_move {
/**
* @brief Construct a new object
*/
no_copy_no_move() = default;
/**
* @brief No copy
*/
no_copy_no_move(no_copy_no_move const&) = delete;
/**
* @brief No move
*/
void operator=(no_copy_no_move const&) = delete;
};
/**
* @brief Interface
*/
struct interface {
/**
* @brief Destroy the interface
*/
virtual ~interface() = default;
};
/**
* @brief Combine hash seed with value - from boost (functional/hash)
* @see https://www.boost.org/doc/libs/1_77_0/doc/html/hash/combine.html
* @tparam T Type of value
* @param seed Seed to combine
* @param val Value to combine
*/
template <typename T>
inline void hash_combine(size_t& seed,
T const& val) {
seed ^= std::hash<T>()(val) + 0x9e3779b9
+ (seed << 6) + (seed >> 2);
}
/**
* @brief Auxiliary generic functions to create a hash value using a seed
* @tparam T Type of value
* @param seed Seed for hash
* @param val Hash value
*/
template <typename T>
inline void hash_value(size_t& seed,
T const& val) {
hash_combine(seed, val);
}
/**
* @see hash_value<T>()
*/
template <typename T, typename... Types>
inline void hash_value(size_t& seed,
T const& val,
Types const&... args) {
hash_combine(seed, val);
hash_value(seed, args...);
}
/**
* @see hash_value<T>()
*/
template <typename... Types>
inline size_t hash_value(Types const&... args) {
size_t seed = 0;
hash_value(seed, args...);
return seed;
}
/**
* @brief Pair hash
*/
struct pair_hash {
/**
* @brief Hash operator
* @tparam T1 Type of first
* @tparam T2 Type of second
* @param p Hash pair
* @return size_t Hash value
*/
template <class T1, class T2>
size_t operator()(std::pair<T1, T2> const& p) const {
return hash_value(p.first, p.second);
}
};
/// Enum flag operators
#define ENUM_FLAG_OPERATORS(T) \
inline T operator~(T a) { \
return static_cast<T>(~static_cast<std::underlying_type<T>::type>(a)); \
} \
inline T operator|(T a, T b) { \
return static_cast<T>(static_cast<std::underlying_type<T>::type>(a) | static_cast<std::underlying_type<T>::type>(b)); \
} \
inline T operator&(T a, T b) { \
return static_cast<T>(static_cast<std::underlying_type<T>::type>(a) & static_cast<std::underlying_type<T>::type>(b)); \
} \
inline T operator^(T a, T b) { \
return static_cast<T>(static_cast<std::underlying_type<T>::type>(a) ^ static_cast<std::underlying_type<T>::type>(b)); \
} \
inline T& operator|=(T& a, T b) { \
return reinterpret_cast<T&>(reinterpret_cast<std::underlying_type<T>::type&>(a) |= static_cast<std::underlying_type<T>::type>(b)); \
} \
inline T& operator&=(T& a, T b) { \
return reinterpret_cast<T&>(reinterpret_cast<std::underlying_type<T>::type&>(a) &= static_cast<std::underlying_type<T>::type>(b)); \
} \
inline T& operator^=(T& a, T b) { \
return reinterpret_cast<T&>(reinterpret_cast<std::underlying_type<T>::type&>(a) ^= static_cast<std::underlying_type<T>::type>(b)); \
}
} // namespace lava