forked from winnerspiros/UnleashedRecomp_Android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframework.h
More file actions
58 lines (44 loc) · 1.15 KB
/
Copy pathframework.h
File metadata and controls
58 lines (44 loc) · 1.15 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
#pragma once
#define STR(x) #x
template<typename T>
inline T RoundUp(const T& in_rValue, uint32_t in_round)
{
return (in_rValue + in_round - 1) & ~(in_round - 1);
}
template<typename T>
inline T RoundDown(const T& in_rValue, uint32_t in_round)
{
return in_rValue & ~(in_round - 1);
}
inline size_t StringHash(const std::string_view& str)
{
return XXH3_64bits(str.data(), str.size());
}
template<typename TValue>
constexpr size_t FirstBitLow(TValue value)
{
constexpr size_t nbits = sizeof(TValue) * 8;
constexpr auto zero = TValue{};
constexpr auto one = static_cast<TValue>(1);
for (size_t i = 0; i < nbits; i++)
{
if ((value & (one << i)) != zero)
{
return i;
}
}
return 0;
}
inline std::unique_ptr<uint8_t[]> ReadAllBytes(const char* filePath, size_t& fileSize)
{
FILE* file = fopen(filePath, "rb");
if (!file)
return std::make_unique<uint8_t[]>(0);
fseek(file, 0, SEEK_END);
fileSize = ftell(file);
fseek(file, 0, SEEK_SET);
auto data = std::make_unique<uint8_t[]>(fileSize);
fread(data.get(), 1, fileSize, file);
fclose(file);
return data;
}