[ox/std] Fix OxError for release builds and fix ox::Error assignment operator

This commit is contained in:
Gary Talent 2020-04-16 22:19:27 -05:00
parent ed0bf268ba
commit 8753d39b66
2 changed files with 27 additions and 10 deletions

View File

@ -8,15 +8,12 @@
#pragma once #pragma once
#include "defines.hpp"
#include "strongint.hpp" #include "strongint.hpp"
#include "typetraits.hpp" #include "typetraits.hpp"
#include "utility.hpp" #include "utility.hpp"
#ifdef DEBUG
#define OxError(...) ox::_error(__FILE__, __LINE__, __VA_ARGS__) #define OxError(...) ox::_error(__FILE__, __LINE__, __VA_ARGS__)
#else
#define OxError(...) static_cast<ox::Error>(__VA_ARGS__)
#endif
namespace ox { namespace ox {
@ -33,15 +30,22 @@ struct BaseError {
line = o.line; line = o.line;
} }
constexpr BaseError operator=(const BaseError &o) noexcept {
msg = o.msg;
file = o.file;
line = o.line;
return *this;
}
}; };
using Error = Integer<uint64_t, BaseError>; using Error = Integer<uint64_t, BaseError>;
static constexpr Error _error(const char *file, uint32_t line, uint64_t errCode, const char *msg = nullptr) { static constexpr Error _error(const char *file, uint32_t line, uint64_t errCode, const char *msg = nullptr) {
Error err = static_cast<ox::Error>(errCode); Error err = static_cast<ox::Error>(errCode);
err.file = file; err.file = file;
err.line = line; err.line = line;
err.msg = msg; err.msg = msg;
return err; return err;
} }

View File

@ -12,13 +12,24 @@
namespace ox { namespace ox {
class BaseInteger {}; struct BaseInteger {
constexpr BaseInteger() = default;
constexpr BaseInteger(const BaseInteger&) {
}
constexpr BaseInteger operator=(const BaseInteger&) {
return *this;
}
};
/** /**
* Integer is a strongly typed integer wrapper used to create strongly typed * Integer is a strongly typed integer wrapper used to create strongly typed
* integers. * integers.
*/ */
template<typename T, class Base = BaseInteger> template<typename T, typename Base = BaseInteger>
class Integer: public Base { class Integer: public Base {
private: private:
T m_i; T m_i;
@ -115,7 +126,9 @@ constexpr Integer<T, Base>::Integer(const Integer<T, Base> &i) noexcept: Base(i)
template<typename T, class Base> template<typename T, class Base>
constexpr Integer<T, Base> Integer<T, Base>::operator=(Integer<T, Base> i) noexcept { constexpr Integer<T, Base> Integer<T, Base>::operator=(Integer<T, Base> i) noexcept {
return Integer<T, Base>(m_i = i.m_i); Base::operator=(i);
m_i = i.m_i;
return *this;
} }
template<typename T, class Base> template<typename T, class Base>