-
Notifications
You must be signed in to change notification settings - Fork 75
/
utils.h
57 lines (45 loc) · 1.21 KB
/
utils.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
#ifndef UTILS_H_
#define UTILS_H_
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
extern int depth;
extern bool is_verbose;
#ifdef _MSC_VER
#define BSWAP32(x) _byteswap_ulong(x)
#elif defined __GNUC__
#define BSWAP32(x) __builtin_bswap32(x)
#else
#define BSWAP32(x) _bswap(x)
#endif
#ifdef _MSC_VER
#define PACK(...) __pragma(pack(push, 1)) __VA_ARGS__ __pragma(pack(pop))
#elif defined __GNUC__
#define PACK(...) __VA_ARGS__ __attribute__((__packed__))
#endif
void UTF16toMBS(const wchar_t* u, size_t srclen, char* mbs, size_t dstlen);
void PrintFileName(const std::string& name);
std::string ShrinkSpace(const char* value);
template <typename T>
void VerbosePrint(const T& t) {
if (!is_verbose)
return;
std::cout << t << std::endl;
}
template <typename T, typename... Args>
void VerbosePrint(const T& t, const Args&... args) {
if (!is_verbose)
return;
std::cout << t;
VerbosePrint(args...);
}
// Divide |x| by |y| and round up to the nearest integer.
constexpr uint64_t DivRoundUp(uint64_t x, uint64_t y) {
return (x + y - 1) / y;
}
// Round |x| up to be a multiple of |y|.
constexpr uint64_t RoundUp(uint64_t x, uint64_t y) {
return DivRoundUp(x, y) * y;
}
#endif // UTILS_H_