From 142387aa042c6cca88343723d8d85625437fd161 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 28 Jul 2019 00:57:19 -0500 Subject: [PATCH] [ox/std] Improve ability to create unique int types, regardless of underlying type --- deps/ox/src/ox/std/error.hpp | 4 +- deps/ox/src/ox/std/strongint.hpp | 266 ++++++++++++++++--------------- deps/ox/src/ox/std/trace.hpp | 10 +- 3 files changed, 142 insertions(+), 138 deletions(-) diff --git a/deps/ox/src/ox/std/error.hpp b/deps/ox/src/ox/std/error.hpp index 48d85bd8..aed7b914 100644 --- a/deps/ox/src/ox/std/error.hpp +++ b/deps/ox/src/ox/std/error.hpp @@ -22,7 +22,9 @@ namespace ox { -using Error = Uint64; +class BaseError {}; + +using Error = Integer; constexpr Error errCode(Error err) { return (err >> 59) & onMask(5); diff --git a/deps/ox/src/ox/std/strongint.hpp b/deps/ox/src/ox/std/strongint.hpp index 03316ce4..4e2101f5 100644 --- a/deps/ox/src/ox/std/strongint.hpp +++ b/deps/ox/src/ox/std/strongint.hpp @@ -12,12 +12,14 @@ namespace ox { +class BaseInteger {}; + /** * Integer is a strongly typed integer wrapper used to create strongly typed * integers. */ -template -class Integer { +template +class Integer: Base { private: T m_i; @@ -26,71 +28,71 @@ class Integer { constexpr explicit Integer(T i) noexcept; - constexpr Integer operator=(Integer i) noexcept; + constexpr Integer operator=(Integer i) noexcept; - constexpr Integer operator==(Integer i) const noexcept; + constexpr Integer operator==(Integer i) const noexcept; - constexpr Integer operator!=(Integer i) const noexcept; + constexpr Integer operator!=(Integer i) const noexcept; - constexpr Integer operator<(Integer i) const noexcept; + constexpr Integer operator<(Integer i) const noexcept; - constexpr Integer operator>(Integer i) const noexcept; + constexpr Integer operator>(Integer i) const noexcept; - constexpr Integer operator<=(Integer i) const noexcept; + constexpr Integer operator<=(Integer i) const noexcept; - constexpr Integer operator>=(Integer i) const noexcept; + constexpr Integer operator>=(Integer i) const noexcept; - constexpr Integer operator+(Integer i) const noexcept; + constexpr Integer operator+(Integer i) const noexcept; - constexpr Integer operator+=(Integer i) noexcept; + constexpr Integer operator+=(Integer i) noexcept; - constexpr Integer operator-(Integer i) const noexcept; + constexpr Integer operator-(Integer i) const noexcept; - constexpr Integer operator-=(Integer i) noexcept; + constexpr Integer operator-=(Integer i) noexcept; - constexpr Integer operator*(Integer i) const noexcept; + constexpr Integer operator*(Integer i) const noexcept; - constexpr Integer operator*=(Integer i) noexcept; + constexpr Integer operator*=(Integer i) noexcept; - constexpr Integer operator/(Integer i) const noexcept; + constexpr Integer operator/(Integer i) const noexcept; - constexpr Integer operator/=(Integer i) noexcept; + constexpr Integer operator/=(Integer i) noexcept; - constexpr Integer operator%(Integer i) const noexcept; + constexpr Integer operator%(Integer i) const noexcept; - constexpr Integer operator%=(Integer i) noexcept; + constexpr Integer operator%=(Integer i) noexcept; - constexpr Integer operator>>(int i) const noexcept; + constexpr Integer operator>>(int i) const noexcept; - constexpr Integer operator>>=(int i) noexcept; + constexpr Integer operator>>=(int i) noexcept; - constexpr Integer operator<<(int i) const noexcept; + constexpr Integer operator<<(int i) const noexcept; - constexpr Integer operator<<=(int i) noexcept; + constexpr Integer operator<<=(int i) noexcept; - constexpr Integer operator|(Integer i) const noexcept; + constexpr Integer operator|(Integer i) const noexcept; - constexpr Integer operator|=(Integer i) noexcept; + constexpr Integer operator|=(Integer i) noexcept; - constexpr Integer operator&(Integer i) const noexcept; + constexpr Integer operator&(Integer i) const noexcept; - constexpr Integer operator&=(Integer i) noexcept; + constexpr Integer operator&=(Integer i) noexcept; - constexpr Integer operator^(Integer i) const noexcept; + constexpr Integer operator^(Integer i) const noexcept; - constexpr Integer operator^=(Integer i) noexcept; + constexpr Integer operator^=(Integer i) noexcept; // Prefix increment - constexpr Integer operator++() noexcept; + constexpr Integer operator++() noexcept; // Postfix increment - constexpr Integer operator++(int) noexcept; + constexpr Integer operator++(int) noexcept; // Prefix decrement - constexpr Integer operator--() noexcept; + constexpr Integer operator--() noexcept; // Postfix decrement - constexpr Integer operator--(int) noexcept; + constexpr Integer operator--(int) noexcept; constexpr explicit operator T() const noexcept; @@ -98,177 +100,177 @@ class Integer { }; -template -constexpr Integer::Integer(T i) noexcept { +template +constexpr Integer::Integer(T i) noexcept { m_i = i; } -template -constexpr Integer Integer::operator=(Integer i) noexcept { - return Integer(m_i = i.m_i); +template +constexpr Integer Integer::operator=(Integer i) noexcept { + return Integer(m_i = i.m_i); } -template -constexpr Integer Integer::operator==(Integer i) const noexcept { - return Integer(m_i == i.m_i); +template +constexpr Integer Integer::operator==(Integer i) const noexcept { + return Integer(m_i == i.m_i); } -template -constexpr Integer Integer::operator!=(Integer i) const noexcept { - return Integer(m_i != i.m_i); +template +constexpr Integer Integer::operator!=(Integer i) const noexcept { + return Integer(m_i != i.m_i); } -template -constexpr Integer Integer::operator<(Integer i) const noexcept { - return Integer(m_i < i.m_i); +template +constexpr Integer Integer::operator<(Integer i) const noexcept { + return Integer(m_i < i.m_i); } -template -constexpr Integer Integer::operator>(Integer i) const noexcept { - return Integer(m_i > i.m_i); +template +constexpr Integer Integer::operator>(Integer i) const noexcept { + return Integer(m_i > i.m_i); } -template -constexpr Integer Integer::operator<=(Integer i) const noexcept { - return Integer(m_i <= i.m_i); +template +constexpr Integer Integer::operator<=(Integer i) const noexcept { + return Integer(m_i <= i.m_i); } -template -constexpr Integer Integer::operator>=(Integer i) const noexcept { - return Integer(m_i >= i.m_i); +template +constexpr Integer Integer::operator>=(Integer i) const noexcept { + return Integer(m_i >= i.m_i); } -template -constexpr Integer Integer::operator+(Integer i) const noexcept { - return Integer(m_i + i.m_i); +template +constexpr Integer Integer::operator+(Integer i) const noexcept { + return Integer(m_i + i.m_i); } -template -constexpr Integer Integer::operator+=(Integer i) noexcept { - return Integer(m_i += i.m_i); +template +constexpr Integer Integer::operator+=(Integer i) noexcept { + return Integer(m_i += i.m_i); } -template -constexpr Integer Integer::operator-(Integer i) const noexcept { - return Integer(m_i - i.m_i); +template +constexpr Integer Integer::operator-(Integer i) const noexcept { + return Integer(m_i - i.m_i); } -template -constexpr Integer Integer::operator-=(Integer i) noexcept { - return Integer(m_i -= i.m_i); +template +constexpr Integer Integer::operator-=(Integer i) noexcept { + return Integer(m_i -= i.m_i); } -template -constexpr Integer Integer::operator*(Integer i) const noexcept { - return Integer(m_i * i.m_i); +template +constexpr Integer Integer::operator*(Integer i) const noexcept { + return Integer(m_i * i.m_i); } -template -constexpr Integer Integer::operator*=(Integer i) noexcept { - return Integer(m_i *= i.m_i); +template +constexpr Integer Integer::operator*=(Integer i) noexcept { + return Integer(m_i *= i.m_i); } -template -constexpr Integer Integer::operator/(Integer i) const noexcept { - return Integer(m_i / i.m_i); +template +constexpr Integer Integer::operator/(Integer i) const noexcept { + return Integer(m_i / i.m_i); } -template -constexpr Integer Integer::operator/=(Integer i) noexcept { - return Integer(m_i /= i.m_i); +template +constexpr Integer Integer::operator/=(Integer i) noexcept { + return Integer(m_i /= i.m_i); } -template -constexpr Integer Integer::operator%(Integer i) const noexcept { - return Integer(m_i % i.m_i); +template +constexpr Integer Integer::operator%(Integer i) const noexcept { + return Integer(m_i % i.m_i); } -template -constexpr Integer Integer::operator%=(Integer i) noexcept { - return Integer(m_i %= i.m_i); +template +constexpr Integer Integer::operator%=(Integer i) noexcept { + return Integer(m_i %= i.m_i); } -template -constexpr Integer Integer::operator>>(int i) const noexcept { - return Integer(m_i >> i); +template +constexpr Integer Integer::operator>>(int i) const noexcept { + return Integer(m_i >> i); } -template -constexpr Integer Integer::operator>>=(int i) noexcept { - return Integer(m_i >>= i); +template +constexpr Integer Integer::operator>>=(int i) noexcept { + return Integer(m_i >>= i); } -template -constexpr Integer Integer::operator<<(int i) const noexcept { - return Integer(m_i << i); +template +constexpr Integer Integer::operator<<(int i) const noexcept { + return Integer(m_i << i); } -template -constexpr Integer Integer::operator<<=(int i) noexcept { - return Integer(m_i <<= i); +template +constexpr Integer Integer::operator<<=(int i) noexcept { + return Integer(m_i <<= i); } -template -constexpr Integer Integer::operator|(Integer i) const noexcept { - return Integer(m_i | i.m_i); +template +constexpr Integer Integer::operator|(Integer i) const noexcept { + return Integer(m_i | i.m_i); } -template -constexpr Integer Integer::operator|=(Integer i) noexcept { - return Integer(m_i |= i.m_i); +template +constexpr Integer Integer::operator|=(Integer i) noexcept { + return Integer(m_i |= i.m_i); } -template -constexpr Integer Integer::operator&(Integer i) const noexcept { - return Integer(m_i & i.m_i); +template +constexpr Integer Integer::operator&(Integer i) const noexcept { + return Integer(m_i & i.m_i); } -template -constexpr Integer Integer::operator&=(Integer i) noexcept { - return Integer(m_i &= i.m_i); +template +constexpr Integer Integer::operator&=(Integer i) noexcept { + return Integer(m_i &= i.m_i); } -template -constexpr Integer Integer::operator^(Integer i) const noexcept { - return Integer(m_i ^ i.m_i); +template +constexpr Integer Integer::operator^(Integer i) const noexcept { + return Integer(m_i ^ i.m_i); } -template -constexpr Integer Integer::operator^=(Integer i) noexcept { - return Integer(m_i ^= i.m_i); +template +constexpr Integer Integer::operator^=(Integer i) noexcept { + return Integer(m_i ^= i.m_i); } // Prefix increment -template -constexpr inline Integer Integer::operator++() noexcept { - return Integer(++m_i); +template +constexpr inline Integer Integer::operator++() noexcept { + return Integer(++m_i); } // Postfix increment -template -constexpr inline Integer Integer::operator++(int) noexcept { - return Integer(m_i++); +template +constexpr inline Integer Integer::operator++(int) noexcept { + return Integer(m_i++); } // Prefix decrement -template -constexpr inline Integer Integer::operator--() noexcept { - return Integer(--m_i); +template +constexpr inline Integer Integer::operator--() noexcept { + return Integer(--m_i); } // Postfix decrement -template -constexpr inline Integer Integer::operator--(int) noexcept { - return Integer(m_i--); +template +constexpr inline Integer Integer::operator--(int) noexcept { + return Integer(m_i--); } -template -constexpr Integer::operator T() const noexcept { +template +constexpr Integer::operator T() const noexcept { return m_i; } -template -constexpr Integer::operator bool() const noexcept { +template +constexpr Integer::operator bool() const noexcept { return m_i; } diff --git a/deps/ox/src/ox/std/trace.hpp b/deps/ox/src/ox/std/trace.hpp index 33e10dd1..174b97ac 100644 --- a/deps/ox/src/ox/std/trace.hpp +++ b/deps/ox/src/ox/std/trace.hpp @@ -22,12 +22,12 @@ struct TraceMsg { template Error model(T *io, ox::trace::TraceMsg *obj) { - Error err = 0; + auto err = OxError(0); io->setTypeInfo("ox::trace::TraceMsg", 5); - err |= io->field("file", &obj->file); - err |= io->field("line", &obj->line); - err |= io->field("time", &obj->time); - err |= io->field("msg", &obj->msg); + oxReturnError(io->field("file", &obj->file)); + oxReturnError(io->field("line", &obj->line)); + oxReturnError(io->field("time", &obj->time)); + oxReturnError(io->field("msg", &obj->msg)); return err; }