[ox/std] Add optional file/line information to ox::Error

This commit is contained in:
Gary Talent 2018-05-26 10:08:11 -05:00
parent d49f35f0f3
commit 0da80081f3
3 changed files with 46 additions and 7 deletions

View File

@ -8,8 +8,6 @@
#pragma once
#include "types.hpp"
namespace ox {
template<typename T>
@ -18,4 +16,13 @@ inline constexpr T rotateLeft(T i, int shift) {
return (i << shift) | (i >> (bits - shift));
}
template<typename T>
constexpr T onMask(int bits) {
T out = 0;
for (auto i = 0; i < bits; i++) {
out |= 1 << i;
}
return out;
}
}

View File

@ -8,15 +8,13 @@
#pragma once
uint64_t ox_rand();
#include "types.hpp"
namespace ox {
typedef uint64_t RandomSeed[2];
using RandomSeed = uint64_t[2];
class Random {
public:
private:
RandomSeed m_seed;

View File

@ -8,6 +8,8 @@
#pragma once
#include "bitops.hpp"
#if OX_USE_STDLIB
#include <cstdint>
@ -52,7 +54,39 @@ typedef uint32_t uintptr_t;
namespace ox {
using Error = uint32_t;
using Error = uint64_t;
struct ErrorInfo {
const char *file = nullptr;
int line = -1;
Error errCode = 0;
ErrorInfo() = default;
ErrorInfo(Error err) {
this->file = reinterpret_cast<const char*>(err & onMask<Error>(48));
this->line = static_cast<int>((err >> 48) & onMask<Error>(5));
this->errCode = (err >> 59) & onMask<Error>(11);
}
};
constexpr Error ErrorTags(Error line, Error errCode) {
line &= onMask<Error>(5);
line <<= 48;
errCode &= onMask<Error>(11);
errCode <<= 59;
return errCode | line;
}
}
#ifdef DEBUG
#define OxError(x) reinterpret_cast<uint64_t>(__FILE__) | ErrorTags(__LINE__, x)
#else
#define OxError(x) x
#endif
namespace ox {
template<typename T>
struct ValErr {