25 #include "common/scummsys.h" 27 #include "common/type_traits.h" 42 #define IS_ALIGNED(value, alignment) \ 43 ((((size_t)value) & ((alignment) - 1)) == 0) 58 template<
typename T>
inline T
ABS(T x) {
return (x >= 0) ? x : -x; }
61 template<
typename T>
inline T
MIN(T a, T b) {
return (a < b) ? a : b; }
64 template<
typename T>
inline T
MAX(T a, T b) {
return (a > b) ? a : b; }
67 template<
typename T>
inline T
CLIP(T v, T amin, T amax)
69 #if !defined(RELEASE_BUILD) 76 if (v < amin)
return amin;
77 else if (v > amax)
return amax;
84 template<
typename T>
inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
87 static inline uint32 ROTATE_LEFT_32(
const uint32 x,
const uint32 r) {
88 return (x >> (32 - r)) | (x << r);
92 static inline uint32 ROTATE_RIGHT_32(
const uint32 x,
const uint32 r) {
93 return (x << (32 - r)) | (x >> r);
96 #if !defined(_MSC_VER) || _MSC_VER >= 1910 98 template<
typename... A> constexpr
size_t NUMARGS(A&&...) {
return sizeof...(A); }
101 using int_c_array =
int[];
102 #define NUMARGS(...) (sizeof(int_c_array{__VA_ARGS__})/sizeof(int)) 112 #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0]))) 117 #define ARRAYEND(x) ((x) + ARRAYSIZE((x))) 122 template<
typename T,
size_t N>
inline void ARRAYCLEAR(T (&array) [N],
const T &value = T()) {
132 #if defined(__GNUC__) 133 # define SCUMMVM_CURRENT_FUNCTION __PRETTY_FUNCTION__ 134 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) 135 # define SCUMMVM_CURRENT_FUNCTION __func__ 136 #elif defined(_MSC_VER) 137 # define SCUMMVM_CURRENT_FUNCTION __FUNCTION__ 139 # define SCUMMVM_CURRENT_FUNCTION "<unknown>" 158 constexpr remove_reference_t<T> &&
move(T &&t) noexcept {
159 return static_cast<remove_reference_t<T> &&
>(t);
163 constexpr T&& forward(remove_reference_t<T> &&t) noexcept {
164 return static_cast<T &&
>(t);
168 constexpr T&& forward(remove_reference_t<T> &t) noexcept {
169 return static_cast<T &&
>(t);
175 template<
class T1,
class T2>
183 Pair(
const Pair &other) : first(other.first), second(other.second) {
189 Pair(
const T1 &first_,
const T2 &second_) : first(first_), second(second_) {
195 Pair(T1 &&first_,
const T2 &second_) : first(
Common::move(first_)), second(second_) {
198 Pair(
const T1 &first_, T2 &&second_) : first(first_), second(
Common::move(second_)) {
201 Pair &operator=(
const Pair &other) {
202 this->first = other.first;
203 this->second = other.second;
223 extern void hexdump(
const byte * data,
int len,
int bytesPerLine = 16,
int startOffset = 0);
void ARRAYCLEAR(T(&array) [N], const T &value=T())
Definition: util.h:122
bool parseBool(const String &val, bool &valAsBool)
void SWAP(T &a, T &b)
Definition: util.h:84
T CLIP(T v, T amin, T amax)
Definition: util.h:67
void hexdump(const byte *data, int len, int bytesPerLine=16, int startOffset=0)
constexpr size_t NUMARGS(A &&...)
Definition: util.h:98
Definition: algorithm.h:29
Common::String getHumanReadableBytes(uint64 bytes, const char *&unitsOut)
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
T MIN(T a, T b)
Definition: util.h:61
T MAX(T a, T b)
Definition: util.h:64
T ABS(T x)
Definition: util.h:58