diff --git a/deps/ox/src/ox/std/CMakeLists.txt b/deps/ox/src/ox/std/CMakeLists.txt index 7ecff378..c69cb042 100644 --- a/deps/ox/src/ox/std/CMakeLists.txt +++ b/deps/ox/src/ox/std/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8) add_library( OxStd assert.cpp + byteswap.cpp memops.cpp random.cpp strops.cpp diff --git a/deps/ox/src/ox/std/assert.cpp b/deps/ox/src/ox/std/assert.cpp index 5e5b107f..388e12a2 100644 --- a/deps/ox/src/ox/std/assert.cpp +++ b/deps/ox/src/ox/std/assert.cpp @@ -6,16 +6,20 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#if defined(OX_USE_STDLIB) -#include -#include -#endif +#include + +namespace ox { -void oxAssert(const char *file, int line, bool pass, const char *msg) { #if defined(OX_USE_STDLIB) +void _assert(const char *file, int line, bool pass, const char *msg) { if (!pass) { std::cerr << '(' << file << ':' << line << "): " << msg << std::endl; std::abort(); } -#endif +} +#else +void _assert(const char*, int, bool, const char*) { +} +#endif + } diff --git a/deps/ox/src/ox/std/assert.hpp b/deps/ox/src/ox/std/assert.hpp index 86d603a0..7163db79 100644 --- a/deps/ox/src/ox/std/assert.hpp +++ b/deps/ox/src/ox/std/assert.hpp @@ -8,10 +8,14 @@ #pragma once -void oxAssert(const char *file, int line, bool pass, const char *msg); +namespace ox { + +void _assert(const char *file, int line, bool pass, const char *msg); + +} #ifndef NDEBUG -#define ox_assert(pass, msg) oxAssert(__FILE__, __LINE__, pass, msg) +#define oxAssert(pass, msg) ox::_assert(__FILE__, __LINE__, pass, msg) #else -#define ox_assert(pass, msg) +#define oxAssert(pass, msg) #endif diff --git a/deps/ox/src/ox/std/byteswap.cpp b/deps/ox/src/ox/std/byteswap.cpp new file mode 100644 index 00000000..82353563 --- /dev/null +++ b/deps/ox/src/ox/std/byteswap.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2015 - 2018 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "byteswap.hpp" + +namespace ox { + +template +static constexpr bool testBigEndianAdapt(T i) { + return bigEndianAdapt(bigEndianAdapt(i)) == i; +} + +template +static constexpr bool testLittleEndian(T i) { + return LittleEndian(i) == i; +} + +template +static constexpr bool testBigEndian(T i) { + return BigEndian(i) == i; +} + +static_assert(testBigEndianAdapt(0x00ff), "Test bigEndianAdapt 0x00ff"); +static_assert(testBigEndianAdapt(0xff00), "Test bigEndianAdapt 0xff00"); + +static_assert(testBigEndianAdapt(0x000000ff), "Test bigEndianAdapt 0x000000ff"); +static_assert(testBigEndianAdapt(0x0000ff00), "Test bigEndianAdapt 0x0000ff00"); +static_assert(testBigEndianAdapt(0x00ff0000), "Test bigEndianAdapt 0x00ff0000"); +static_assert(testBigEndianAdapt(0xff000000), "Test bigEndianAdapt 0xff000000"); + +static_assert(testBigEndianAdapt(0x00000000000000ff), "Test bigEndianAdapt 0x00000000000000ff"); +static_assert(testBigEndianAdapt(0x000000000000ff00), "Test bigEndianAdapt 0x000000000000ff00"); +static_assert(testBigEndianAdapt(0x0000000000ff0000), "Test bigEndianAdapt 0x0000000000ff0000"); +static_assert(testBigEndianAdapt(0x00000000ff000000), "Test bigEndianAdapt 0x00000000ff000000"); +static_assert(testBigEndianAdapt(0x000000ff00000000), "Test bigEndianAdapt 0x000000ff00000000"); +static_assert(testBigEndianAdapt(0x0000ff0000000000), "Test bigEndianAdapt 0x0000ff0000000000"); +static_assert(testBigEndianAdapt(0x00ff000000000000), "Test bigEndianAdapt 0x00ff000000000000"); +static_assert(testBigEndianAdapt(0xff00000000000000), "Test bigEndianAdapt 0xff00000000000000"); + + +static_assert(testLittleEndian(0x00ff), "Test LittleEndian 0x00ff"); +static_assert(testLittleEndian(0xff00), "Test LittleEndian 0xff00"); + +static_assert(testLittleEndian(0x000000ff), "Test LittleEndian 0x000000ff"); +static_assert(testLittleEndian(0x0000ff00), "Test LittleEndian 0x0000ff00"); +static_assert(testLittleEndian(0x00ff0000), "Test LittleEndian 0x00ff0000"); +static_assert(testLittleEndian(0xff000000), "Test LittleEndian 0xff000000"); + +static_assert(testLittleEndian(0x00000000000000ff), "Test LittleEndian 0x00000000000000ff"); +static_assert(testLittleEndian(0x000000000000ff00), "Test LittleEndian 0x000000000000ff00"); +static_assert(testLittleEndian(0x0000000000ff0000), "Test LittleEndian 0x0000000000ff0000"); +static_assert(testLittleEndian(0x00000000ff000000), "Test LittleEndian 0x00000000ff000000"); +static_assert(testLittleEndian(0x000000ff00000000), "Test LittleEndian 0x000000ff00000000"); +static_assert(testLittleEndian(0x0000ff0000000000), "Test LittleEndian 0x0000ff0000000000"); +static_assert(testLittleEndian(0x00ff000000000000), "Test LittleEndian 0x00ff000000000000"); +static_assert(testLittleEndian(0xff00000000000000), "Test LittleEndian 0xff00000000000000"); + + +static_assert(testBigEndian(0x00ff), "Test BigEndian 0x00ff"); +static_assert(testBigEndian(0xff00), "Test BigEndian 0xff00"); + +static_assert(testBigEndian(0x000000ff), "Test BigEndian 0x000000ff"); +static_assert(testBigEndian(0x0000ff00), "Test BigEndian 0x0000ff00"); +static_assert(testBigEndian(0x00ff0000), "Test BigEndian 0x00ff0000"); +static_assert(testBigEndian(0xff000000), "Test BigEndian 0xff000000"); + +static_assert(testBigEndian(0x00000000000000ff), "Test BigEndian 0x00000000000000ff"); +static_assert(testBigEndian(0x000000000000ff00), "Test BigEndian 0x000000000000ff00"); +static_assert(testBigEndian(0x0000000000ff0000), "Test BigEndian 0x0000000000ff0000"); +static_assert(testBigEndian(0x00000000ff000000), "Test BigEndian 0x00000000ff000000"); +static_assert(testBigEndian(0x000000ff00000000), "Test BigEndian 0x000000ff00000000"); +static_assert(testBigEndian(0x0000ff0000000000), "Test BigEndian 0x0000ff0000000000"); +static_assert(testBigEndian(0x00ff000000000000), "Test BigEndian 0x00ff000000000000"); +static_assert(testBigEndian(0xff00000000000000), "Test BigEndian 0xff00000000000000"); + +} diff --git a/deps/ox/src/ox/std/byteswap.hpp b/deps/ox/src/ox/std/byteswap.hpp index 4d37f8aa..bf5cf80c 100644 --- a/deps/ox/src/ox/std/byteswap.hpp +++ b/deps/ox/src/ox/std/byteswap.hpp @@ -11,51 +11,30 @@ #include #include "types.hpp" +#include "typetraits.hpp" namespace ox { -constexpr inline int8_t byteSwap(int8_t i) { +template +constexpr inline T byteSwap(typename enable_if::type i) { return i; } -constexpr inline int16_t byteSwap(int16_t i) { +template +constexpr inline T byteSwap(typename enable_if::type i) { return (i << 8) | (i >> 8); } -constexpr inline int32_t byteSwap(int32_t i) { +template +constexpr inline T byteSwap(typename enable_if::type i) { return ((i >> 24) & 0x000000ff) | ((i >> 8) & 0x0000ff00) | ((i << 8) & 0x00ff0000) | ((i << 24) & 0xff000000); } -constexpr inline int64_t byteSwap(int64_t i) { - return ((i >> 56) & 0x00000000000000ff) | - ((i >> 40) & 0x000000000000ff00) | - ((i >> 24) & 0x0000000000ff0000) | - ((i >> 8) & 0x00000000ff000000) | - ((i << 8) & 0x000000ff00000000) | - ((i << 24) & 0x0000ff0000000000) | - ((i << 40) & 0x00ff000000000000) | - ((i << 56) & 0xff00000000000000); -} - -constexpr inline uint16_t byteSwap(uint8_t i) { - return i; -} - -constexpr inline uint16_t byteSwap(uint16_t i) { - return (i << 8) | (i >> 8); -} - -constexpr inline uint32_t byteSwap(uint32_t i) { - return ((i >> 24) & 0x000000ff) | - ((i >> 8) & 0x0000ff00) | - ((i << 8) & 0x00ff0000) | - ((i << 24) & 0xff000000); -} - -constexpr inline uint64_t byteSwap(uint64_t i) { +template +constexpr inline T byteSwap(typename enable_if::type i) { return ((i >> 56) & 0x00000000000000ff) | ((i >> 40) & 0x000000000000ff00) | ((i >> 24) & 0x0000000000ff0000) | @@ -68,74 +47,81 @@ constexpr inline uint64_t byteSwap(uint64_t i) { /** - * Takes an int and byte swaps if the platform is big endian. + * Takes an int and byte swaps if the platform is the given condition is true. */ -template -constexpr inline T bigEndianAdapt(T i) { - if constexpr(ox::defines::BigEndian) { - return byteSwap(i); +template +constexpr inline T conditionalByteSwap(T i) { + if constexpr(byteSwap) { + return ox::byteSwap(i); } else { return i; } } - +/** + * Takes an int and byte swaps if the platform is big endian. + */ template -class __attribute__((packed)) LittleEndian { +constexpr inline T bigEndianAdapt(T i) { + return conditionalByteSwap(i); +} + + +template +class __attribute__((packed)) ByteSwapInteger { private: T m_value; public: - constexpr inline LittleEndian() = default; + constexpr inline ByteSwapInteger() = default; - constexpr inline LittleEndian(const LittleEndian &other) { + constexpr inline ByteSwapInteger(const ByteSwapInteger &other) { m_value = other.m_value; } - constexpr inline LittleEndian(T value) { - m_value = ox::bigEndianAdapt(value); + constexpr inline ByteSwapInteger(T value): m_value(ox::conditionalByteSwap(value)) { } - constexpr inline const LittleEndian &operator=(const LittleEndian &other) { + constexpr inline const ByteSwapInteger &operator=(const ByteSwapInteger &other) { m_value = other.m_value; return *this; } template constexpr inline T operator=(I value) { - m_value = ox::bigEndianAdapt(value); + m_value = ox::conditionalByteSwap(value); return value; } constexpr inline operator T() const { - return ox::bigEndianAdapt(m_value); + return ox::conditionalByteSwap(m_value); } template constexpr inline T operator+=(I other) { auto newVal = *this + other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } template constexpr inline T operator-=(I other) { auto newVal = *this - other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } template constexpr inline T operator*=(I other) { auto newVal = *this * other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } template constexpr inline T operator/=(I other) { auto newVal = *this / other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } @@ -166,38 +152,44 @@ class __attribute__((packed)) LittleEndian { template constexpr inline T operator&=(I other) { auto newVal = *this & other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } template constexpr inline T operator|=(I other) { auto newVal = *this | other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } template constexpr inline T operator^=(I other) { auto newVal = *this ^ other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } template constexpr inline T operator>>=(I other) { auto newVal = *this >> other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } template constexpr inline T operator<<=(I other) { auto newVal = *this << other; - m_value = ox::bigEndianAdapt(newVal); + m_value = ox::conditionalByteSwap(newVal); return newVal; } }; +template +using LittleEndian = ByteSwapInteger; + +template +using BigEndian = ByteSwapInteger; + } diff --git a/deps/ox/src/ox/std/memops.cpp b/deps/ox/src/ox/std/memops.cpp index ca32f328..2f067ee7 100644 --- a/deps/ox/src/ox/std/memops.cpp +++ b/deps/ox/src/ox/std/memops.cpp @@ -1,3 +1,4 @@ + /* * Copyright 2015 - 2018 gtalent2@gmail.com * @@ -5,12 +6,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "memops.hpp" + +#include "types.hpp" int ox_memcmp(const void *ptr1, const void *ptr2, size_t size) { int retval = 0; - auto block1 = ((uint8_t*) ptr1); - auto block2 = ((uint8_t*) ptr2); + auto block1 = reinterpret_cast(ptr1); + auto block2 = reinterpret_cast(ptr2); for (size_t i = 0; i < size; i++) { if (block1[i] < block2[i]) { retval = -1; diff --git a/deps/ox/src/ox/std/strops.cpp b/deps/ox/src/ox/std/strops.cpp index 7675a1d0..45057d8f 100644 --- a/deps/ox/src/ox/std/strops.cpp +++ b/deps/ox/src/ox/std/strops.cpp @@ -6,110 +6,24 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "math.hpp" - #include "strops.hpp" -int ox_strcmp(const char *str1, const char *str2) { - auto retval = 0; - auto i = 0; - while (str1[i] || str2[i]) { - if (str1[i] < str2[i]) { - retval = -1; - break; - } else if (str1[i] > str2[i]) { - retval = 1; - break; - } - i++; - } - return retval; -} +static_assert(ox_strcmp("asdf", "hijk") < 0, "asdf < hijk"); +static_assert(ox_strcmp("hijk", "asdf") > 0, "hijk > asdf"); +static_assert(ox_strcmp("resize", "read") > 0, "resize > read"); +static_assert(ox_strcmp("read", "resize") < 0, "read < resize"); +static_assert(ox_strcmp("resize", "resize") == 0, "resize == resize"); +static_assert(ox_strcmp("", "") == 0, "\"\" == \"\""); -const char *ox_strchr(const char *str, int character, size_t maxLen) { - for (size_t i = 0; i <= maxLen; i++) { - if (str[i] == character) { - return &str[i]; - } else if (str[i] == 0) { - return nullptr; - } - } - return nullptr; -} +static_assert([] { + auto testStr = "asdf"; + return ox_strchr(testStr, 0, 4) == &testStr[4]; +}(), "ox_strchr 0"); -char *ox_strchr(char *str, int character, size_t maxLen) { - for (size_t i = 0; i < maxLen; i++) { - if (str[i] == character) { - return &str[i]; - } else if (str[i] == 0) { - return nullptr; - } - } - return nullptr; -} - -int ox_lastIndexOf(const char *str, int character, int maxLen) { - int retval = -1; - for (int i = 0; i < maxLen && str[i]; i++) { - if (str[i] == character) { - retval = i; - } - } - return retval; -} - -int ox_lastIndexOf(char *str, int character, int maxLen) { - int retval = -1; - for (int i = 0; i < maxLen && str[i]; i++) { - if (str[i] == character) { - retval = i; - } - } - return retval; -} - -int ox_atoi(const char *str) { - int total = 0; - int multiplier = 1; - - for (auto i = ox_strlen(str) - 1; i != -1; i--) { - total += (str[i] - '0') * multiplier; - multiplier *= 10; - } - - return total; -} - -char *ox_itoa(int64_t v, char *str) { - if (v) { - auto mod = 1000000000000000000; - constexpr auto base = 10; - auto it = 0; - if (v < 0) { - str[it] = '-'; - it++; - } - while (mod) { - auto digit = v / mod; - v %= mod; - mod /= base; - if (it or digit) { - int start; - if (digit < 10) { - start = '0'; - } else { - start = 'a'; - digit -= 10; - } - str[it] = start + digit; - it++; - } - } - str[it] = 0; - } else { - // 0 is a special case - str[0] = '0'; - str[1] = 0; - } - return str; -} +static_assert([] { + int retval = 0; + auto testStr = "aaaa"; + retval |= !(ox_lastIndexOf((char*) testStr, 'a', ox_strlen(testStr)) == 3); + retval |= !(ox_lastIndexOf((const char*) testStr, 'a', ox_strlen(testStr)) == 3); + return retval == 0; +}(), "ox_lastIndexOf aaaa a"); diff --git a/deps/ox/src/ox/std/strops.hpp b/deps/ox/src/ox/std/strops.hpp index 2cf2cdd9..0b62e37b 100644 --- a/deps/ox/src/ox/std/strops.hpp +++ b/deps/ox/src/ox/std/strops.hpp @@ -8,11 +8,10 @@ #pragma once +#include "math.hpp" #include "types.hpp" #include "typetraits.hpp" -int ox_strcmp(const char *str1, const char *str2); - constexpr int ox_strlen(const char *str1) { int len = 0; for (; str1[len]; len++); @@ -25,14 +24,104 @@ constexpr int ox_strlen(char *str1) { return len; } -const char *ox_strchr(const char *str, int character, size_t maxLen = 0xFFFFFFFF); +constexpr int ox_strcmp(const char *str1, const char *str2) { + auto retval = 0; + auto i = 0; + while (str1[i] || str2[i]) { + if (str1[i] < str2[i]) { + retval = -1; + break; + } else if (str1[i] > str2[i]) { + retval = 1; + break; + } + i++; + } + return retval; +} -char *ox_strchr(char *str, int character, size_t maxLen = 0xFFFFFFFF); +constexpr const char *ox_strchr(const char *str, int character, size_t maxLen = 0xFFFFFFFF) { + for (size_t i = 0; i <= maxLen; i++) { + if (str[i] == character) { + return &str[i]; + } else if (str[i] == 0) { + return nullptr; + } + } + return nullptr; +} -int ox_lastIndexOf(const char *str, int character, int maxLen = 0xFFFFFFFF); +constexpr char *ox_strchr(char *str, int character, size_t maxLen = 0xFFFFFFFF) { + for (size_t i = 0; i < maxLen; i++) { + if (str[i] == character) { + return &str[i]; + } else if (str[i] == 0) { + return nullptr; + } + } + return nullptr; +} -int ox_lastIndexOf(char *str, int character, int maxLen = 0xFFFFFFFF); +constexpr int ox_lastIndexOf(const char *str, int character, int maxLen = 0xFFFFFFFF) { + int retval = -1; + for (int i = 0; i < maxLen && str[i]; i++) { + if (str[i] == character) { + retval = i; + } + } + return retval; +} -int ox_atoi(const char *str); +constexpr int ox_lastIndexOf(char *str, int character, int maxLen = 0xFFFFFFFF) { + int retval = -1; + for (int i = 0; i < maxLen && str[i]; i++) { + if (str[i] == character) { + retval = i; + } + } + return retval; +} -char *ox_itoa(int64_t v, char *str); +constexpr int ox_atoi(const char *str) { + int total = 0; + int multiplier = 1; + + for (auto i = ox_strlen(str) - 1; i != -1; i--) { + total += (str[i] - '0') * multiplier; + multiplier *= 10; + } + + return total; +} + +constexpr char *ox_itoa(int64_t v, char *str) { + if (v) { + auto mod = 1000000000000000000; + constexpr auto base = 10; + auto it = 0; + if (v < 0) { + str[it] = '-'; + it++; + } + while (mod) { + auto digit = v / mod; + v %= mod; + mod /= base; + if (it or digit) { + int start = '0'; + if (digit >= 10) { + start = 'a'; + digit -= 10; + } + str[it] = start + digit; + it++; + } + } + str[it] = 0; + } else { + // 0 is a special case + str[0] = '0'; + str[1] = 0; + } + return str; +} diff --git a/deps/ox/src/ox/std/test/CMakeLists.txt b/deps/ox/src/ox/std/test/CMakeLists.txt index e3855936..79e18641 100644 --- a/deps/ox/src/ox/std/test/CMakeLists.txt +++ b/deps/ox/src/ox/std/test/CMakeLists.txt @@ -11,59 +11,3 @@ add_test("Test\\ ox_memcmp\\ ABCDEFG\\ !=\\ HIJKLMN" StdTest "ABCDEFG != HIJKLMN add_test("Test\\ ox_memcmp\\ HIJKLMN\\ !=\\ ABCDEFG" StdTest "HIJKLMN != ABCDEFG") add_test("Test\\ ox_memcmp\\ ABCDEFG\\ ==\\ ABCDEFG" StdTest "ABCDEFG == ABCDEFG") add_test("Test\\ ox_memcmp\\ ABCDEFGHI\\ ==\\ ABCDEFG" StdTest "ABCDEFGHI == ABCDEFG") - - -################################################################################ -# StrOps Tests - -add_executable( - StrOpsTest - strops_test.cpp -) - -target_link_libraries( - StrOpsTest - OxStd - OxTrace -) - -add_test("Test\\ ox_strcmp\\ asdf\\ !=\\ hijk" StrOpsTest "asdf < hijk") -add_test("Test\\ ox_strcmp\\ hijk\\ !=\\ asdf" StrOpsTest "hijk > asdf") -add_test("Test\\ ox_strcmp\\ read\\ !=\\ resize" StrOpsTest "read < resize") -add_test("Test\\ ox_strcmp\\ resize\\ !=\\ read" StrOpsTest "resize > read") -add_test("Test\\ ox_strcmp\\ resize\\ ==\\ resize" StrOpsTest "resize == resize") -add_test("Test\\ ox_strcmp\\ ''\\ ==\\ ''" StrOpsTest " == ") -add_test("Test\\ ox_strchr\\ 0" StrOpsTest "ox_strchr 0") -add_test("Test\\ ox_lastIndexOf\\ aaaa\\ a" StrOpsTest "ox_lastIndexOf aaaa a") - - -################################################################################ -# Byte Swap Tests - -add_executable( - ByteSwapTest - byteswap_test.cpp -) - -target_link_libraries( - ByteSwapTest - OxStd - OxTrace -) - -add_test("Test\\ bigEndianAdapt\\ 0x00ff" ByteSwapTest bigEndianAdapt 0x00ff) -add_test("Test\\ bigEndianAdapt\\ 0xff00" ByteSwapTest bigEndianAdapt 0xff00) - -add_test("Test\\ bigEndianAdapt\\ 0x000000ff" ByteSwapTest bigEndianAdapt 0x000000ff) -add_test("Test\\ bigEndianAdapt\\ 0x0000ff00" ByteSwapTest bigEndianAdapt 0x0000ff00) -add_test("Test\\ bigEndianAdapt\\ 0x00ff0000" ByteSwapTest bigEndianAdapt 0x00ff0000) -add_test("Test\\ bigEndianAdapt\\ 0xff000000" ByteSwapTest bigEndianAdapt 0xff000000) - -add_test("Test\\ bigEndianAdapt\\ 0x00000000000000ff" ByteSwapTest bigEndianAdapt 0x00000000000000ff) -add_test("Test\\ bigEndianAdapt\\ 0x000000000000ff00" ByteSwapTest bigEndianAdapt 0x000000000000ff00) -add_test("Test\\ bigEndianAdapt\\ 0x0000000000ff0000" ByteSwapTest bigEndianAdapt 0x0000000000ff0000) -add_test("Test\\ bigEndianAdapt\\ 0x00000000ff000000" ByteSwapTest bigEndianAdapt 0x00000000ff000000) -add_test("Test\\ bigEndianAdapt\\ 0x000000ff00000000" ByteSwapTest bigEndianAdapt 0x000000ff00000000) -add_test("Test\\ bigEndianAdapt\\ 0x0000ff0000000000" ByteSwapTest bigEndianAdapt 0x0000ff0000000000) -add_test("Test\\ bigEndianAdapt\\ 0x00ff000000000000" ByteSwapTest bigEndianAdapt 0x00ff000000000000) -add_test("Test\\ bigEndianAdapt\\ 0xff00000000000000" ByteSwapTest bigEndianAdapt 0xff00000000000000) diff --git a/deps/ox/src/ox/std/test/byteswap_test.cpp b/deps/ox/src/ox/std/test/byteswap_test.cpp deleted file mode 100644 index 7dcfaae5..00000000 --- a/deps/ox/src/ox/std/test/byteswap_test.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2015 - 2018 gtalent2@gmail.com - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -#include -#include -#include - -using namespace std; -using namespace ox; - -template -int testBigEndianAdapt(string str) { - auto i = (T) stoull(str, nullptr, 16); - return !(bigEndianAdapt(bigEndianAdapt(i)) == i); -} - -map tests = { - { - { "bigEndianAdapt", testBigEndianAdapt }, - { "bigEndianAdapt", testBigEndianAdapt }, - { "bigEndianAdapt", testBigEndianAdapt }, - }, -}; - -int main(int argc, const char **args) { - int retval = -1; - if (argc > 1) { - auto testName = args[1]; - string testArg = args[2]; - if (tests.find(testName) != tests.end()) { - retval = tests[testName](testArg); - } - } - return retval; -} diff --git a/deps/ox/src/ox/std/test/strops_test.cpp b/deps/ox/src/ox/std/test/strops_test.cpp deleted file mode 100644 index bef41312..00000000 --- a/deps/ox/src/ox/std/test/strops_test.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2015 - 2018 gtalent2@gmail.com - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -#include -#include -#include -#include - -using namespace std; - -map> tests = { - { - "asdf < hijk", - []() { - return !(ox_strcmp("asdf", "hijk") < 0); - } - }, - { - "hijk > asdf", - []() { - return !(ox_strcmp("hijk", "asdf") > 0); - } - }, - { - "resize > read", - []() { - return !(ox_strcmp("resize", "read") > 0); - } - }, - { - "read < resize", - []() { - return !(ox_strcmp("read", "resize") < 0); - } - }, - { - "resize == resize", - []() { - return !(ox_strcmp("resize", "resize") == 0); - } - }, - { - " == ", - []() { - return !(ox_strcmp("", "") == 0); - } - }, - { - "ox_strchr 0", - []() { - auto testStr = "asdf"; - return !(ox_strchr(testStr, 0, 4) == &testStr[4]); - } - }, - { - "ox_lastIndexOf aaaa a", - []() { - int retval = 0; - auto testStr = "aaaa"; - retval |= !(ox_lastIndexOf((char*) testStr, 'a', ox_strlen(testStr)) == 3); - retval |= !(ox_lastIndexOf((const char*) testStr, 'a', ox_strlen(testStr)) == 3); - return retval; - } - }, -}; - -int main(int argc, const char **args) { - if (argc > 1) { - auto testName = args[1]; - if (tests.find(testName) != tests.end()) { - return tests[testName](); - } - } - return -1; -} diff --git a/deps/ox/src/ox/std/types.hpp b/deps/ox/src/ox/std/types.hpp index 78c7b0e8..61c64125 100644 --- a/deps/ox/src/ox/std/types.hpp +++ b/deps/ox/src/ox/std/types.hpp @@ -29,7 +29,29 @@ typedef uint64_t uintmax_t; namespace ox { -typedef uint32_t Error; +using Error = uint32_t; + +template +struct ValErr { + T value; + Error error; + + inline constexpr ValErr() = default; + + inline constexpr ValErr(T value, Error error = 0) { + this->value = value; + this->error = error; + } + + inline constexpr operator T&() { + return value; + } + + inline constexpr bool ok() { + return error == 0; + } + +}; }