Squashed 'deps/nostalgia/' changes from 6a523191..84205879
84205879 [olympic] Cleanup ItemMaker, remove unnecessary copy ebf3a696 [ox/std] Add String constructor that takes a StringLiteral dfd27afd [ox/std] Add implicit String constructor for str literals 6bfe1842 [ox/std] Remove unnecessary copying from HashMap::expand 700d7016 [nostalgia] Update for Ox changes 92232383 [ox] Cleanup 3b8d13dc [nostalgia,olympic] Fixes for Ox update a20d7fd9 [ox] Cleanup 2c0e0227 [ox/std] Add assert to AnyPtr::Wrap::copyTo to ensure sufficiently large buff e3c74637 [turbine] Make applicationData return const& 41e08d67 [turbine] Make keyEventHandler nodiscard 50f3479d [ox/std] Make AnyPtr constexpr 1616ca70 [turbine] Replace WrapPtr with ox::AnyPtr 3fa247e3 [ox/std] Add AnyPtr 27f1df8f [nostalgia,olympic] Further reduce use of applicationData a4f0c7cd [nostalgia/core/studio] Remove applicationData usages git-subtree-dir: deps/nostalgia git-subtree-split: 84205879d46610dfe08098d1265c0398f2215d3d
This commit is contained in:
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
@@ -105,6 +105,7 @@ install(
|
||||
heapmgr.hpp
|
||||
iterator.hpp
|
||||
math.hpp
|
||||
maybeview.hpp
|
||||
memops.hpp
|
||||
memory.hpp
|
||||
new.hpp
|
||||
|
102
deps/ox/src/ox/std/anyptr.hpp
vendored
Normal file
102
deps/ox/src/ox/std/anyptr.hpp
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "assert.hpp"
|
||||
#include "array.hpp"
|
||||
#include "def.hpp"
|
||||
#include "span.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
class AnyPtr {
|
||||
private:
|
||||
struct WrapBase {
|
||||
virtual constexpr ~WrapBase() = default;
|
||||
virtual constexpr WrapBase *copyTo(ox::Span<char> s) noexcept = 0;
|
||||
virtual constexpr operator bool() const noexcept = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Wrap: public WrapBase {
|
||||
T *data{};
|
||||
constexpr Wrap(T *pData) noexcept: data(pData) {
|
||||
}
|
||||
constexpr WrapBase *copyTo(ox::Span<char> s) noexcept override {
|
||||
oxAssert(s.size() >= sizeof(Wrap), "too small buffer");
|
||||
if (std::is_constant_evaluated()) {
|
||||
return new Wrap(data);
|
||||
} else {
|
||||
return new(s.data()) Wrap(data);
|
||||
}
|
||||
}
|
||||
constexpr operator bool() const noexcept override {
|
||||
return data != nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
WrapBase *m_wrapPtr{};
|
||||
ox::Array<char, sizeof(Wrap<void*>)> m_wrapData;
|
||||
|
||||
public:
|
||||
constexpr AnyPtr() noexcept = default;
|
||||
|
||||
template<typename T>
|
||||
constexpr AnyPtr(T *ptr) noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
m_wrapPtr = new Wrap(ptr);
|
||||
} else {
|
||||
m_wrapPtr = new(m_wrapData.data()) Wrap(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr AnyPtr(AnyPtr const&other) noexcept {
|
||||
if (other) {
|
||||
m_wrapPtr = other.m_wrapPtr->copyTo(m_wrapData);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr ~AnyPtr() noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr AnyPtr &operator=(T *ptr) noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
m_wrapPtr = new Wrap(ptr);
|
||||
} else {
|
||||
m_wrapPtr = new(m_wrapData.data()) Wrap(ptr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr AnyPtr &operator=(AnyPtr const&ptr) noexcept {
|
||||
if (this != &ptr) {
|
||||
if (ptr) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
m_wrapPtr = ptr.m_wrapPtr->copyTo(m_wrapData);
|
||||
} else {
|
||||
m_wrapPtr = nullptr;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr operator bool() const noexcept {
|
||||
return m_wrapPtr && *m_wrapPtr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]]
|
||||
constexpr T *get() const noexcept {
|
||||
#ifdef OX_BARE_METAL
|
||||
return static_cast<Wrap<T>*>(m_wrapPtr)->data;
|
||||
#else
|
||||
return dynamic_cast<Wrap<T>*>(m_wrapPtr)->data;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
}
|
1
deps/ox/src/ox/std/array.hpp
vendored
1
deps/ox/src/ox/std/array.hpp
vendored
@@ -13,7 +13,6 @@
|
||||
#include "initializerlist.hpp"
|
||||
#include "iterator.hpp"
|
||||
#include "math.hpp"
|
||||
#include "memory.hpp"
|
||||
#include "new.hpp"
|
||||
#include "types.hpp"
|
||||
#include "utility.hpp"
|
||||
|
2
deps/ox/src/ox/std/basestringview.hpp
vendored
2
deps/ox/src/ox/std/basestringview.hpp
vendored
@@ -131,7 +131,7 @@ class BaseStringView {
|
||||
|
||||
constexpr explicit BaseStringView(std::nullptr_t) noexcept {}
|
||||
|
||||
constexpr explicit BaseStringView(const char *str) noexcept: m_str(str), m_len(str ? ox_strlen(str) : 0) {}
|
||||
constexpr explicit BaseStringView(const char *str) noexcept: m_str(str), m_len(str ? ox::strlen(str) : 0) {}
|
||||
|
||||
constexpr explicit BaseStringView(const char *str, std::size_t len) noexcept: m_str(str), m_len(len) {}
|
||||
|
||||
|
2
deps/ox/src/ox/std/bit.hpp
vendored
2
deps/ox/src/ox/std/bit.hpp
vendored
@@ -34,7 +34,7 @@ namespace ox {
|
||||
template<typename To, typename From>
|
||||
constexpr typename enable_if<sizeof(To) == sizeof(From), To>::type cbit_cast(From src) noexcept {
|
||||
To dst = {};
|
||||
ox_memcpy(&dst, &src, sizeof(src));
|
||||
ox::memcpy(&dst, &src, sizeof(src));
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
18
deps/ox/src/ox/std/bstring.hpp
vendored
18
deps/ox/src/ox/std/bstring.hpp
vendored
@@ -109,7 +109,7 @@ constexpr BString<size>::BString(const char *str) noexcept: m_buff{{0}} {
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> &BString<size>::operator=(Integer_c auto i) noexcept {
|
||||
char str[65] = {};
|
||||
ox_itoa(i, str);
|
||||
ox::itoa(i, str);
|
||||
return this->operator=(str);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ constexpr BString<size> &BString<size>::operator=(ox::CRStringView str) noexcept
|
||||
if (cap() < strLen) {
|
||||
strLen = cap();
|
||||
}
|
||||
ox_memcpy(m_buff, str.data(), strLen);
|
||||
ox::memcpy(m_buff, str.data(), strLen);
|
||||
// make sure last element is a null terminator
|
||||
m_buff[strLen] = 0;
|
||||
return *this;
|
||||
@@ -127,11 +127,11 @@ constexpr BString<size> &BString<size>::operator=(ox::CRStringView str) noexcept
|
||||
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> &BString<size>::operator=(const char *str) noexcept {
|
||||
std::size_t strLen = ox_strlen(str) + 1;
|
||||
std::size_t strLen = ox::strlen(str) + 1;
|
||||
if (cap() < strLen) {
|
||||
strLen = cap();
|
||||
}
|
||||
ox_memcpy(m_buff, str, strLen);
|
||||
ox::memcpy(m_buff, str, strLen);
|
||||
// make sure last element is a null terminator
|
||||
m_buff[cap()] = 0;
|
||||
return *this;
|
||||
@@ -144,7 +144,7 @@ constexpr BString<size> &BString<size>::operator=(char *str) noexcept {
|
||||
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> &BString<size>::operator+=(const char *str) noexcept {
|
||||
std::size_t strLen = ox_strlen(str) + 1;
|
||||
std::size_t strLen = ox::strlen(str) + 1;
|
||||
oxIgnoreError(append(str, strLen));
|
||||
return *this;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ constexpr BString<size> &BString<size>::operator+=(char *str) noexcept {
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> &BString<size>::operator+=(Integer_c auto i) noexcept {
|
||||
char str[65] = {};
|
||||
ox_itoa(i, str);
|
||||
ox::itoa(i, str);
|
||||
return this->operator+=(str);
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ constexpr BString<size> &BString<size>::operator+=(StringView s) noexcept {
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> BString<size>::operator+(const char *str) const noexcept {
|
||||
auto out = *this;
|
||||
std::size_t strLen = ox_strlen(str) + 1;
|
||||
std::size_t strLen = ox::strlen(str) + 1;
|
||||
oxIgnoreError(out.append(str, strLen));
|
||||
return out;
|
||||
}
|
||||
@@ -184,7 +184,7 @@ constexpr BString<size> BString<size>::operator+(char *str) const noexcept {
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> BString<size>::operator+(Integer_c auto i) const noexcept {
|
||||
char str[65] = {};
|
||||
ox_itoa(i, str);
|
||||
ox::itoa(i, str);
|
||||
return this->operator+(str);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ constexpr Error BString<buffLen>::append(const char *str, std::size_t strLen) no
|
||||
strLen = cap() - currentLen;
|
||||
err = OxError(1, "Insufficient space for full string");
|
||||
}
|
||||
ox_strncpy(m_buff + currentLen, str, strLen);
|
||||
ox::strncpy(m_buff + currentLen, str, strLen);
|
||||
// make sure last element is a null terminator
|
||||
m_buff[currentLen + strLen] = 0;
|
||||
return err;
|
||||
|
2
deps/ox/src/ox/std/buffer.hpp
vendored
2
deps/ox/src/ox/std/buffer.hpp
vendored
@@ -192,7 +192,7 @@ class BufferReader {
|
||||
if (m_it + sz > m_size) [[unlikely]] {
|
||||
return OxError(1, "Read failed: Buffer overrun");
|
||||
}
|
||||
ox_memcpy(v, &m_buff[m_it], sz);
|
||||
ox::memcpy(v, &m_buff[m_it], sz);
|
||||
m_it += sz;
|
||||
return sz;
|
||||
}
|
||||
|
22
deps/ox/src/ox/std/cstrops.hpp
vendored
22
deps/ox/src/ox/std/cstrops.hpp
vendored
@@ -11,8 +11,10 @@
|
||||
#include "types.hpp"
|
||||
#include "typetraits.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
template<typename T1, typename T2>
|
||||
constexpr T1 ox_strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
constexpr T1 strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
using T1Type = typename ox::remove_reference<decltype(dest[0])>::type;
|
||||
std::size_t i = 0;
|
||||
while (i < maxLen && src[i]) {
|
||||
@@ -25,7 +27,7 @@ constexpr T1 ox_strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto ox_strnlen(const char *str1, std::size_t maxLen) noexcept {
|
||||
constexpr auto strnlen(const char *str1, std::size_t maxLen) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; len < maxLen && str1[len]; len++);
|
||||
return len;
|
||||
@@ -33,7 +35,7 @@ constexpr auto ox_strnlen(const char *str1, std::size_t maxLen) noexcept {
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]]
|
||||
constexpr auto ox_strlen(T const&str1) noexcept {
|
||||
constexpr auto strlen(T const&str1) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; str1[len]; len++);
|
||||
return len;
|
||||
@@ -41,7 +43,7 @@ constexpr auto ox_strlen(T const&str1) noexcept {
|
||||
|
||||
template<typename T1, typename T2>
|
||||
[[nodiscard]]
|
||||
constexpr int ox_strcmp(const T1 &str1, const T2 &str2) noexcept {
|
||||
constexpr int strcmp(const T1 &str1, const T2 &str2) noexcept {
|
||||
auto retval = 0;
|
||||
auto i = 0u;
|
||||
while (str1[i] || str2[i]) {
|
||||
@@ -59,7 +61,7 @@ constexpr int ox_strcmp(const T1 &str1, const T2 &str2) noexcept {
|
||||
|
||||
template<typename T1, typename T2>
|
||||
[[nodiscard]]
|
||||
constexpr int ox_strncmp(T1 const&str1, T2 const&str2, const std::size_t maxLen) noexcept {
|
||||
constexpr int strncmp(T1 const&str1, T2 const&str2, const std::size_t maxLen) noexcept {
|
||||
auto retval = 0;
|
||||
std::size_t i = 0;
|
||||
while (i < maxLen && (str1[i] || str2[i])) {
|
||||
@@ -76,7 +78,7 @@ constexpr int ox_strncmp(T1 const&str1, T2 const&str2, const std::size_t maxLen)
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const char *ox_strchr(const char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
constexpr const char *strchr(const char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
for (std::size_t i = 0; i <= maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
@@ -88,7 +90,7 @@ constexpr const char *ox_strchr(const char *str, int character, std::size_t maxL
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
constexpr char *strchr(char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
for (std::size_t i = 0; i < maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
@@ -100,7 +102,7 @@ constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFF
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int ox_lastIndexOf(const auto &str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
constexpr int lastIndexOf(const auto &str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
int retval = -1;
|
||||
for (std::size_t i = 0; i < maxLen && str[i]; i++) {
|
||||
if (str[i] == character) {
|
||||
@@ -111,7 +113,7 @@ constexpr int ox_lastIndexOf(const auto &str, int character, std::size_t maxLen
|
||||
}
|
||||
|
||||
template<typename Integer, typename T>
|
||||
constexpr T ox_itoa(Integer v, T str) noexcept {
|
||||
constexpr T itoa(Integer v, T str) noexcept {
|
||||
if (v) {
|
||||
ox::ResizedInt_t<Integer, 64> mod = 1000000000000000000;
|
||||
ox::ResizedInt_t<Integer, 64> val = v;
|
||||
@@ -143,3 +145,5 @@ constexpr T ox_itoa(Integer v, T str) noexcept {
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
|
6
deps/ox/src/ox/std/fmt.hpp
vendored
6
deps/ox/src/ox/std/fmt.hpp
vendored
@@ -81,7 +81,7 @@ class FmtArg {
|
||||
if constexpr(is_bool_v<T>) {
|
||||
return v ? "true" : "false";
|
||||
} else if constexpr(is_integer_v<T>) {
|
||||
return ox_itoa(v, dataStr);
|
||||
return ox::itoa(v, dataStr);
|
||||
} else {
|
||||
return toStringView(v);
|
||||
}
|
||||
@@ -126,11 +126,11 @@ struct FmtSegment {
|
||||
unsigned length = 0;
|
||||
|
||||
constexpr bool operator==(const FmtSegment &o) const noexcept {
|
||||
return length == o.length && ox_strncmp(str, o.str, length) == 0;
|
||||
return length == o.length && ox::strncmp(str, o.str, length) == 0;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const FmtSegment &o) const noexcept {
|
||||
return length != o.length || ox_strncmp(str, o.str, length) != 0;
|
||||
return length != o.length || ox::strncmp(str, o.str, length) != 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
22
deps/ox/src/ox/std/hashmap.hpp
vendored
22
deps/ox/src/ox/std/hashmap.hpp
vendored
@@ -45,16 +45,16 @@ class HashMap {
|
||||
|
||||
constexpr HashMap &operator=(HashMap &&other) noexcept;
|
||||
|
||||
constexpr T &operator[](MaybeSV_t<K> const&key);
|
||||
constexpr T &operator[](MaybeView_t<K> const&key);
|
||||
|
||||
constexpr Result<T*> at(MaybeSV_t<K> const&key) noexcept;
|
||||
constexpr Result<T*> at(MaybeView_t<K> const&key) noexcept;
|
||||
|
||||
constexpr Result<const T*> at(MaybeSV_t<K> const&key) const noexcept;
|
||||
constexpr Result<const T*> at(MaybeView_t<K> const&key) const noexcept;
|
||||
|
||||
constexpr void erase(MaybeSV_t<K> const&key);
|
||||
constexpr void erase(MaybeView_t<K> const&key);
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool contains(MaybeSV_t<K> const&key) const noexcept;
|
||||
constexpr bool contains(MaybeView_t<K> const&key) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t size() const noexcept;
|
||||
@@ -134,7 +134,7 @@ constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &&other) noexcep
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr T &HashMap<K, T>::operator[](MaybeSV_t<K> const&k) {
|
||||
constexpr T &HashMap<K, T>::operator[](MaybeView_t<K> const&k) {
|
||||
auto &p = access(m_pairs, k);
|
||||
if (p == nullptr) {
|
||||
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
||||
@@ -149,7 +149,7 @@ constexpr T &HashMap<K, T>::operator[](MaybeSV_t<K> const&k) {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr Result<T*> HashMap<K, T>::at(MaybeSV_t<K> const&k) noexcept {
|
||||
constexpr Result<T*> HashMap<K, T>::at(MaybeView_t<K> const&k) noexcept {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return {nullptr, OxError(1, "value not found for given key")};
|
||||
@@ -158,7 +158,7 @@ constexpr Result<T*> HashMap<K, T>::at(MaybeSV_t<K> const&k) noexcept {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr Result<const T*> HashMap<K, T>::at(MaybeSV_t<K> const&k) const noexcept {
|
||||
constexpr Result<const T*> HashMap<K, T>::at(MaybeView_t<K> const&k) const noexcept {
|
||||
auto p = access(m_pairs, k);
|
||||
if (!p) {
|
||||
return {nullptr, OxError(1, "value not found for given key")};
|
||||
@@ -167,7 +167,7 @@ constexpr Result<const T*> HashMap<K, T>::at(MaybeSV_t<K> const&k) const noexcep
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr void HashMap<K, T>::erase(MaybeSV_t<K> const&k) {
|
||||
constexpr void HashMap<K, T>::erase(MaybeView_t<K> const&k) {
|
||||
if (!contains(k)) {
|
||||
return;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ constexpr void HashMap<K, T>::erase(MaybeSV_t<K> const&k) {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr bool HashMap<K, T>::contains(MaybeSV_t<K> const&k) const noexcept {
|
||||
constexpr bool HashMap<K, T>::contains(MaybeView_t<K> const&k) const noexcept {
|
||||
return access(m_pairs, k) != nullptr;
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ template<typename K, typename T>
|
||||
constexpr void HashMap<K, T>::expand() {
|
||||
Vector<Pair*> r;
|
||||
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
||||
K k{m_keys[i]};
|
||||
auto const&k = m_keys[i];
|
||||
access(r, k) = std::move(access(m_pairs, k));
|
||||
}
|
||||
m_pairs = std::move(r);
|
||||
|
26
deps/ox/src/ox/std/maybeview.hpp
vendored
Normal file
26
deps/ox/src/ox/std/maybeview.hpp
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2015 - 2022 gary@drinkingtea.net
|
||||
*
|
||||
* 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 https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "typetraits.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
// Maybe StringView. If T is a string type, MaybeType::type/MaybeView_t is a
|
||||
// StringView. This avoids creating unnecessary Strings when taking a
|
||||
// StringView or C string as a function argument.
|
||||
template<typename T, bool isStr = isOxString_v<T>>
|
||||
struct MaybeView {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using MaybeView_t = typename MaybeView<T>::type;
|
||||
|
||||
}
|
53
deps/ox/src/ox/std/memops.cpp
vendored
53
deps/ox/src/ox/std/memops.cpp
vendored
@@ -6,6 +6,7 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "types.hpp"
|
||||
#include "memops.hpp"
|
||||
|
||||
@@ -16,15 +17,15 @@
|
||||
extern "C" {
|
||||
|
||||
void *ox_inhibit_loop_to_libcall memcpy(void *dest, const void *src, std::size_t size) {
|
||||
return ox_memcpy(dest, src, size);
|
||||
return ox::memcpy(dest, src, size);
|
||||
}
|
||||
|
||||
void *ox_inhibit_loop_to_libcall memmove(void *dest, const void *src, std::size_t size) {
|
||||
return ox_memcpy(dest, src, size);
|
||||
return ox::memcpy(dest, src, size);
|
||||
}
|
||||
|
||||
void *ox_inhibit_loop_to_libcall memset(void *ptr, int val, std::size_t size) {
|
||||
return ox_memset(ptr, val, size);
|
||||
return ox::memset(ptr, val, size);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +51,48 @@ int ox_inhibit_loop_to_libcall memcmp(const void *ptr1, const void *ptr2, std::s
|
||||
|
||||
#endif
|
||||
|
||||
int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept {
|
||||
return memcmp(ptr1, ptr2, size);
|
||||
namespace ox {
|
||||
|
||||
void *memmove(void *dest, const void *src, std::size_t size) noexcept {
|
||||
if constexpr(!ox::defines::UseStdLib) {
|
||||
auto srcBuf = static_cast<const char*>(src);
|
||||
auto dstBuf = static_cast<char*>(dest);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
dstBuf[i] = static_cast<char>(srcBuf[i]);
|
||||
}
|
||||
return dest;
|
||||
} else {
|
||||
return ::memmove(dest, src, size);
|
||||
}
|
||||
}
|
||||
|
||||
void *memset(void *ptr, int val, std::size_t size) noexcept {
|
||||
if constexpr(!ox::defines::UseStdLib) {
|
||||
auto buf = static_cast<uint8_t*>(ptr);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
buf[i] = static_cast<uint8_t>(val);
|
||||
}
|
||||
return ptr;
|
||||
} else {
|
||||
return ::memset(ptr, val, size);
|
||||
}
|
||||
}
|
||||
|
||||
void *memcpy(void *dest, const void *src, std::size_t size) noexcept {
|
||||
if constexpr(!ox::defines::UseStdLib) {
|
||||
auto srcBuf = static_cast<const char*>(src);
|
||||
auto dstBuf = static_cast<char*>(dest);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
dstBuf[i] = static_cast<char>(srcBuf[i]);
|
||||
}
|
||||
return dest;
|
||||
} else {
|
||||
return ::memcpy(dest, src, size);
|
||||
}
|
||||
}
|
||||
|
||||
int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept {
|
||||
return ::memcmp(ptr1, ptr2, size);
|
||||
}
|
||||
|
||||
}
|
||||
|
68
deps/ox/src/ox/std/memops.hpp
vendored
68
deps/ox/src/ox/std/memops.hpp
vendored
@@ -8,7 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "types.hpp"
|
||||
#include "typetraits.hpp"
|
||||
|
||||
@@ -28,63 +27,28 @@ int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept;
|
||||
|
||||
constexpr void *ox_memcpy(void *dest, const void *src, std::size_t size) noexcept {
|
||||
if (std::is_constant_evaluated() || !ox::defines::UseStdLib) {
|
||||
auto srcBuf = static_cast<const char*>(src);
|
||||
auto dstBuf = static_cast<char*>(dest);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
dstBuf[i] = static_cast<char>(srcBuf[i]);
|
||||
}
|
||||
return dest;
|
||||
} else {
|
||||
return memcpy(dest, src, size);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void *ox_memmove(void *dest, const void *src, std::size_t size) noexcept {
|
||||
if (std::is_constant_evaluated() || !ox::defines::UseStdLib) {
|
||||
auto srcBuf = static_cast<const char *>(src);
|
||||
auto dstBuf = static_cast<char *>(dest);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
dstBuf[i] = static_cast<char>(srcBuf[i]);
|
||||
}
|
||||
return dest;
|
||||
} else {
|
||||
return memmove(dest, src, size);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void *ox_memset(void *ptr, int val, std::size_t size) noexcept {
|
||||
if (std::is_constant_evaluated() || !ox::defines::UseStdLib) {
|
||||
auto buf = static_cast<uint8_t*>(ptr);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
buf[i] = static_cast<uint8_t>(val);
|
||||
}
|
||||
return ptr;
|
||||
} else {
|
||||
return memset(ptr, val, size);
|
||||
}
|
||||
}
|
||||
|
||||
namespace ox {
|
||||
|
||||
constexpr void *memmove(void *dest, const void *src, std::size_t size) {
|
||||
return ox_memmove(dest, src, size);
|
||||
template<typename T1, typename T2>
|
||||
constexpr T1 *listcpy(T1 *dest, T2 *src, std::size_t maxLen) noexcept {
|
||||
using T1Type = typename ox::remove_reference<decltype(dest[0])>::type;
|
||||
std::size_t i = 0;
|
||||
while (i < maxLen && src[i]) {
|
||||
dest[i] = static_cast<T1Type>(src[i]);
|
||||
++i;
|
||||
}
|
||||
// set null terminator
|
||||
dest[i] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
constexpr void *memset(void *ptr, int val, std::size_t size) noexcept {
|
||||
return ox_memset(ptr, val, size);
|
||||
}
|
||||
void *memmove(void *dest, const void *src, std::size_t size) noexcept;
|
||||
|
||||
constexpr void *memcpy(void *dest, const void *src, std::size_t size) noexcept {
|
||||
return ox_memcpy(dest, src, size);
|
||||
}
|
||||
void *memset(void *ptr, int val, std::size_t size) noexcept;
|
||||
|
||||
inline int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept {
|
||||
return ox_memcmp(ptr1, ptr2, size);
|
||||
}
|
||||
void *memcpy(void *dest, const void *src, std::size_t size) noexcept;
|
||||
|
||||
int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept;
|
||||
|
||||
template<typename T>
|
||||
void *memsetElements(T *ptr, T val, std::size_t elements) noexcept {
|
||||
|
1
deps/ox/src/ox/std/span.hpp
vendored
1
deps/ox/src/ox/std/span.hpp
vendored
@@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "array.hpp"
|
||||
#include "bit.hpp"
|
||||
#include "iterator.hpp"
|
||||
#include "vector.hpp"
|
||||
|
2
deps/ox/src/ox/std/std.hpp
vendored
2
deps/ox/src/ox/std/std.hpp
vendored
@@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "anyptr.hpp"
|
||||
#include "array.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "bit.hpp"
|
||||
@@ -27,6 +28,7 @@
|
||||
#include "heapmgr.hpp"
|
||||
#include "iterator.hpp"
|
||||
#include "math.hpp"
|
||||
#include "maybeview.hpp"
|
||||
#include "memops.hpp"
|
||||
#include "memory.hpp"
|
||||
#include "new.hpp"
|
||||
|
53
deps/ox/src/ox/std/string.hpp
vendored
53
deps/ox/src/ox/std/string.hpp
vendored
@@ -15,6 +15,7 @@
|
||||
#include "algorithm.hpp"
|
||||
#include "memops.hpp"
|
||||
#include "serialize.hpp"
|
||||
#include "stringliteral.hpp"
|
||||
#include "stringview.hpp"
|
||||
#include "strops.hpp"
|
||||
#include "vector.hpp"
|
||||
@@ -32,12 +33,17 @@ class BasicString {
|
||||
|
||||
constexpr explicit BasicString(std::size_t cap) noexcept;
|
||||
|
||||
template<size_t Sz>
|
||||
constexpr BasicString(char const (&str)[Sz]) noexcept;
|
||||
|
||||
constexpr explicit BasicString(const char *str) noexcept;
|
||||
|
||||
constexpr explicit BasicString(const char8_t *str) noexcept;
|
||||
|
||||
constexpr BasicString(const char *str, std::size_t size) noexcept;
|
||||
|
||||
constexpr explicit BasicString(StringLiteral const&str) noexcept;
|
||||
|
||||
constexpr explicit BasicString(CRStringView str) noexcept;
|
||||
|
||||
constexpr explicit BasicString(BasicString const&) noexcept;
|
||||
@@ -167,7 +173,7 @@ class BasicString {
|
||||
constexpr Error append(const char *str, std::size_t strLen) noexcept {
|
||||
auto currentLen = len();
|
||||
m_buff.resize(m_buff.size() + strLen);
|
||||
ox_memcpy(&m_buff[currentLen], str, strLen);
|
||||
ox::listcpy(&m_buff[currentLen], str, strLen);
|
||||
// make sure last element is a null terminator
|
||||
m_buff[currentLen + strLen] = 0;
|
||||
// this can't fail, but it returns an Error to match BString::append
|
||||
@@ -270,10 +276,15 @@ constexpr BasicString<SmallStringSize_v>::BasicString(const char8_t *str) noexce
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str, std::size_t size) noexcept {
|
||||
m_buff.resize(size + 1);
|
||||
memcpy(m_buff.data(), str, size);
|
||||
ox::listcpy(m_buff.data(), str, size);
|
||||
m_buff[size] = 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(StringLiteral const&str) noexcept:
|
||||
BasicString(StringView{str.data(), str.bytes()}) {
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(CRStringView str) noexcept {
|
||||
if (m_buff.empty()) {
|
||||
@@ -315,7 +326,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(int64_t i) noexcept {
|
||||
ox::Array<char, 65> str{};
|
||||
ox_itoa(i, str.data());
|
||||
ox::itoa(i, str.data());
|
||||
set(str.data());
|
||||
return *this;
|
||||
}
|
||||
@@ -323,7 +334,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(uint64_t i) noexcept {
|
||||
ox::Array<char, 65> str{};
|
||||
ox_itoa(i, str.data());
|
||||
ox::itoa(i, str.data());
|
||||
set(str.data());
|
||||
return *this;
|
||||
}
|
||||
@@ -352,7 +363,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(const char *str) noexcept {
|
||||
std::size_t strLen = ox_strlen(str);
|
||||
std::size_t strLen = ox::strlen(str);
|
||||
oxIgnoreError(append(str, strLen));
|
||||
return *this;
|
||||
}
|
||||
@@ -371,7 +382,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(Integer_c auto i) noexcept {
|
||||
char str[65] = {};
|
||||
ox_itoa(i, str);
|
||||
ox::itoa(i, str);
|
||||
return this->operator+=(str);
|
||||
}
|
||||
|
||||
@@ -390,12 +401,12 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(const char *str) const noexcept {
|
||||
const std::size_t strLen = ox_strlen(str);
|
||||
const std::size_t strLen = ox::strlen(str);
|
||||
const auto currentLen = len();
|
||||
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
||||
cpy.m_buff.resize(m_buff.size() + strLen);
|
||||
memcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||
memcpy(&cpy.m_buff[currentLen], str, strLen);
|
||||
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||
ox::listcpy(&cpy.m_buff[currentLen], str, strLen);
|
||||
// make sure last element is a null terminator
|
||||
cpy.m_buff[currentLen + strLen] = 0;
|
||||
return cpy;
|
||||
@@ -415,7 +426,7 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(Integer_c auto i) const noexcept {
|
||||
char str[65] = {};
|
||||
ox_itoa(i, str);
|
||||
ox::itoa(i, str);
|
||||
return *this + str;
|
||||
}
|
||||
|
||||
@@ -425,8 +436,8 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
const auto currentLen = len();
|
||||
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
||||
cpy.m_buff.resize(m_buff.size() + strLen);
|
||||
memcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||
memcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1);
|
||||
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||
ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1);
|
||||
return cpy;
|
||||
}
|
||||
|
||||
@@ -436,8 +447,8 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
const auto currentLen = len();
|
||||
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
||||
cpy.m_buff.resize(m_buff.size() + strLen);
|
||||
memcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||
memcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1);
|
||||
ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen);
|
||||
ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1);
|
||||
return cpy;
|
||||
}
|
||||
|
||||
@@ -470,22 +481,22 @@ constexpr bool BasicString<SmallStringSize_v>::operator!=(OxString_c auto const&
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator<(BasicString const&other) const noexcept {
|
||||
return ox_strcmp(c_str(), other.c_str()) < 0;
|
||||
return ox::strcmp(c_str(), other.c_str()) < 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator>(BasicString const&other) const noexcept {
|
||||
return ox_strcmp(c_str(), other.c_str()) > 0;
|
||||
return ox::strcmp(c_str(), other.c_str()) > 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator<=(BasicString const&other) const noexcept {
|
||||
return ox_strcmp(c_str(), other.c_str()) < 1;
|
||||
return ox::strcmp(c_str(), other.c_str()) < 1;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator>=(BasicString const&other) const noexcept {
|
||||
return ox_strcmp(c_str(), other.c_str()) > -1;
|
||||
return ox::strcmp(c_str(), other.c_str()) > -1;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
@@ -509,7 +520,7 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::substr(
|
||||
const auto size = end - begin;
|
||||
BasicString<SmallStringSize_v> out(size);
|
||||
const auto buff = out.data();
|
||||
memcpy(buff, src, size);
|
||||
ox::listcpy(buff, src, size);
|
||||
buff[size] = 0;
|
||||
return out;
|
||||
}
|
||||
@@ -548,9 +559,9 @@ constexpr void BasicString<SmallStringSize_v>::set(CRStringView str) noexcept {
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr void BasicString<SmallStringSize_v>::set(const char8_t *str) noexcept {
|
||||
std::size_t strBytes = ox_strlen(str) + 1;
|
||||
std::size_t strBytes = ox::strlen(str) + 1;
|
||||
m_buff.resize(strBytes);
|
||||
memcpy(m_buff.data(), str, strBytes);
|
||||
ox::listcpy(m_buff.data(), str, strBytes);
|
||||
*m_buff.back().value = 0;
|
||||
}
|
||||
|
||||
|
22
deps/ox/src/ox/std/stringview.hpp
vendored
22
deps/ox/src/ox/std/stringview.hpp
vendored
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "basestringview.hpp"
|
||||
#include "cstrops.hpp"
|
||||
#include "maybeview.hpp"
|
||||
#include "writer.hpp"
|
||||
|
||||
namespace ox {
|
||||
@@ -63,7 +64,7 @@ constexpr auto operator==(CRStringView s1, CRStringView s2) noexcept {
|
||||
if (s2.len() != s1.len()) {
|
||||
return false;
|
||||
}
|
||||
return ox_strncmp(s1.data(), s2.data(), s1.len()) == 0;
|
||||
return ox::strncmp(s1.data(), s2.data(), s1.len()) == 0;
|
||||
}
|
||||
|
||||
constexpr auto operator<=>(CRStringView s1, CRStringView s2) noexcept {
|
||||
@@ -97,24 +98,12 @@ constexpr auto toStdStringView(CRStringView sv) noexcept {
|
||||
#endif
|
||||
|
||||
|
||||
// Maybe StringView. If T is a string type, MaybeType::type/MaybeSV_t is a
|
||||
// StringView. This avoids creating unnecessary Strings when taking a
|
||||
// StringView or C string as a function argument.
|
||||
template<typename T, bool isStr = isOxString_v<T>>
|
||||
struct MaybeSV {
|
||||
using type = T;
|
||||
};
|
||||
template<typename T>
|
||||
struct MaybeSV<T, true> {
|
||||
struct MaybeView<T, true> {
|
||||
using type = ox::StringView;
|
||||
};
|
||||
template<typename T>
|
||||
using MaybeSV_t = typename MaybeSV<T>::type;
|
||||
|
||||
|
||||
}
|
||||
|
||||
constexpr ox::Result<int> ox_atoi(ox::CRStringView str) noexcept {
|
||||
constexpr ox::Result<int> atoi(ox::CRStringView str) noexcept {
|
||||
int total = 0;
|
||||
int multiplier = 1;
|
||||
for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) {
|
||||
@@ -129,3 +118,6 @@ constexpr ox::Result<int> ox_atoi(ox::CRStringView str) noexcept {
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
24
deps/ox/src/ox/std/strops.cpp
vendored
24
deps/ox/src/ox/std/strops.cpp
vendored
@@ -8,26 +8,26 @@
|
||||
|
||||
#include "strops.hpp"
|
||||
|
||||
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, "\"\" == \"\"");
|
||||
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, "\"\" == \"\"");
|
||||
|
||||
static_assert([] {
|
||||
auto testStr = "asdf";
|
||||
return ox_strchr(testStr, 0, 4) == &testStr[4];
|
||||
}(), "ox_strchr 0");
|
||||
return ox::strchr(testStr, 0, 4) == &testStr[4];
|
||||
}(), "ox::strchr 0");
|
||||
|
||||
static_assert([] {
|
||||
int retval = 0;
|
||||
auto testStr = "aaaa";
|
||||
// test the const and non-const versions of ox_lastIndexOf
|
||||
retval |= !(ox_lastIndexOf(const_cast<char*>(testStr), 'a', ox_strlen(testStr)) == 3);
|
||||
retval |= !(ox_lastIndexOf(testStr, 'a', ox_strlen(testStr)) == 3);
|
||||
// test the const and non-const versions of ox::lastIndexOf
|
||||
retval |= !(ox::lastIndexOf(const_cast<char*>(testStr), 'a', ox::strlen(testStr)) == 3);
|
||||
retval |= !(ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3);
|
||||
return retval == 0;
|
||||
}(), "ox_lastIndexOf aaaa a");
|
||||
}(), "ox::lastIndexOf aaaa a");
|
||||
|
||||
#ifndef OX_USE_STDLIB
|
||||
|
||||
|
6
deps/ox/src/ox/std/strops.hpp
vendored
6
deps/ox/src/ox/std/strops.hpp
vendored
@@ -37,7 +37,7 @@ constexpr ox::StringView substr(Str const&str, std::size_t start, std::size_t en
|
||||
}
|
||||
|
||||
template<typename Integer>
|
||||
constexpr ox::Error itoa(Integer v, ox::Writer_c auto &writer) noexcept {
|
||||
constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept {
|
||||
if (v) {
|
||||
ox::ResizedInt_t<Integer, 64> mod = 1000000000000000000;
|
||||
ox::ResizedInt_t<Integer, 64> val = v;
|
||||
@@ -71,13 +71,13 @@ constexpr ox::Error itoa(Integer v, ox::Writer_c auto &writer) noexcept {
|
||||
[[nodiscard]]
|
||||
constexpr bool beginsWith(CRStringView base, CRStringView beginning) noexcept {
|
||||
const auto beginningLen = ox::min(beginning.len(), base.len());
|
||||
return base.len() >= beginning.len() && ox_strncmp(base.data(), beginning, beginningLen) == 0;
|
||||
return base.len() >= beginning.len() && ox::strncmp(base.data(), beginning, beginningLen) == 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept {
|
||||
const auto endingLen = ending.len();
|
||||
return base.len() >= endingLen && ox_strcmp(base.data() + (base.len() - endingLen), ending) == 0;
|
||||
return base.len() >= endingLen && ox::strcmp(base.data() + (base.len() - endingLen), ending) == 0;
|
||||
}
|
||||
|
||||
constexpr std::size_t find(CRStringView str, char search) noexcept {
|
||||
|
14
deps/ox/src/ox/std/test/tests.cpp
vendored
14
deps/ox/src/ox/std/test/tests.cpp
vendored
@@ -30,13 +30,13 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
[]() {
|
||||
ox::Array<char, 10> buff;
|
||||
ox::CharBuffWriter bw(buff);
|
||||
oxAssert(ox::itoa(5, bw), "ox::itoa returned Error");
|
||||
oxAssert(ox::writeItoa(5, bw), "ox::writeItoa returned Error");
|
||||
oxExpect(ox::StringView(buff.data()), ox::StringView("5"));
|
||||
oxReturnError(bw.seekp(0));
|
||||
oxAssert(ox::itoa(50, bw), "ox::itoa returned Error");
|
||||
oxAssert(ox::writeItoa(50, bw), "ox::writeItoa returned Error");
|
||||
oxExpect(ox::StringView(buff.data()), ox::StringView("50"));
|
||||
oxReturnError(bw.seekp(0));
|
||||
oxAssert(ox::itoa(500, bw), "ox::itoa returned Error");
|
||||
oxAssert(ox::writeItoa(500, bw), "ox::writeItoa returned Error");
|
||||
oxExpect(ox::StringView(buff.data()), ox::StringView("500"));
|
||||
return ox::Error{};
|
||||
}
|
||||
@@ -44,25 +44,25 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
{
|
||||
"ABCDEFG != HIJKLMN",
|
||||
[]() {
|
||||
return OxError(ox_memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
|
||||
return OxError(ox::memcmp("ABCDEFG", "HIJKLMN", 7) >= 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
"HIJKLMN != ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox_memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
|
||||
return OxError(ox::memcmp("HIJKLMN", "ABCDEFG", 7) <= 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
"ABCDEFG == ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox_memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
|
||||
return OxError(ox::memcmp("ABCDEFG", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
"ABCDEFGHI == ABCDEFG",
|
||||
[]() {
|
||||
return OxError(ox_memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||
return OxError(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
20
deps/ox/src/ox/std/tracehook.cpp
vendored
20
deps/ox/src/ox/std/tracehook.cpp
vendored
@@ -42,7 +42,7 @@ enum LogChan {
|
||||
template<LogChan chan>
|
||||
static void log(ox::CRStringView str) {
|
||||
const auto sz = ox::min<std::size_t>(0x100, str.bytes());
|
||||
ox_strncpy(REG_MGBA_DEBUG_STRING, str.data(), sz);
|
||||
ox::strncpy(REG_MGBA_DEBUG_STRING, str.data(), sz);
|
||||
REG_MGBA_DEBUG_FLAGS = chan | 0x100;
|
||||
}
|
||||
|
||||
@@ -69,30 +69,30 @@ void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line,
|
||||
std::cout << std::setw(53) << std::left << ch << "| ";
|
||||
std::cout << std::setw(65) << std::left << msg << '|';
|
||||
std::cout << " " << file << ':' << line << "\n";
|
||||
} else if (ox_strcmp(ch, "debug") == 0 || ox_strcmp(ch, "info") == 0) {
|
||||
} else if (ox::strcmp(ch, "debug") == 0 || ox::strcmp(ch, "info") == 0) {
|
||||
printf("%s\n", msg);
|
||||
fflush(stdout);
|
||||
} else if (ox_strcmp(ch, "stdout") == 0) {
|
||||
} else if (ox::strcmp(ch, "stdout") == 0) {
|
||||
printf("%s", msg);
|
||||
fflush(stdout);
|
||||
} else if (ox_strcmp(ch, "stderr") == 0) {
|
||||
} else if (ox::strcmp(ch, "stderr") == 0) {
|
||||
printf("%s", msg);
|
||||
fflush(stdout);
|
||||
} else if (ox_strcmp(ch, "error") == 0) {
|
||||
} else if (ox::strcmp(ch, "error") == 0) {
|
||||
//std::cerr << "\033[31;1;1mERROR:\033[0m (" << file << ':' << line << "): " << msg << '\n';
|
||||
fprintf(stderr, "\033[31;1;1mERROR:\033[0m (%s:%d): %s\n", file, line, msg);
|
||||
fflush(stderr);
|
||||
}
|
||||
#else
|
||||
if (ox_strcmp(ch, "info") == 0) {
|
||||
if (ox::strcmp(ch, "info") == 0) {
|
||||
infoLog(msg);
|
||||
} else if (ox_strcmp(ch, "debug") == 0) {
|
||||
} else if (ox::strcmp(ch, "debug") == 0) {
|
||||
debugLog(msg);
|
||||
} else if (ox_strcmp(ch, "stdout") == 0) {
|
||||
} else if (ox::strcmp(ch, "stdout") == 0) {
|
||||
infoLog(msg);
|
||||
} else if (ox_strcmp(ch, "stderr") == 0) {
|
||||
} else if (ox::strcmp(ch, "stderr") == 0) {
|
||||
errorLog(msg);
|
||||
} else if (ox_strcmp(ch, "error") == 0) {
|
||||
} else if (ox::strcmp(ch, "error") == 0) {
|
||||
errorLog(msg);
|
||||
}
|
||||
#endif
|
||||
|
16
deps/ox/src/ox/std/vector.hpp
vendored
16
deps/ox/src/ox/std/vector.hpp
vendored
@@ -263,12 +263,12 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool contains(MaybeSV_t<T> const&) const noexcept(useNoexcept);
|
||||
constexpr bool contains(MaybeView_t<T> const&) const noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(
|
||||
std::size_t pos, std::size_t cnt, MaybeSV_t<T> const&val) noexcept(useNoexcept);
|
||||
std::size_t pos, std::size_t cnt, MaybeView_t<T> const&val) noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, MaybeSV_t<T> const&val) noexcept(useNoexcept);
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, MaybeView_t<T> const&val) noexcept(useNoexcept);
|
||||
|
||||
template<typename... Args>
|
||||
constexpr iterator<T&, T*, false> emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept);
|
||||
@@ -278,7 +278,7 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
|
||||
constexpr void push_back(T &&item) noexcept(useNoexcept);
|
||||
|
||||
constexpr void push_back(MaybeSV_t<T> const&item) noexcept(useNoexcept);
|
||||
constexpr void push_back(MaybeView_t<T> const&item) noexcept(useNoexcept);
|
||||
|
||||
constexpr void pop_back() noexcept(useNoexcept);
|
||||
|
||||
@@ -516,7 +516,7 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::resize(std::size_t size) n
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeSV_t<T> const&v) const noexcept(useNoexcept) {
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeView_t<T> const&v) const noexcept(useNoexcept) {
|
||||
for (std::size_t i = 0; i < m_size; i++) {
|
||||
if (m_items[i] == v) {
|
||||
return true;
|
||||
@@ -528,7 +528,7 @@ constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeSV_t<T> cons
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
std::size_t pos, std::size_t cnt, MaybeSV_t<T> const&val) noexcept(useNoexcept) {
|
||||
std::size_t pos, std::size_t cnt, MaybeView_t<T> const&val) noexcept(useNoexcept) {
|
||||
if (m_size + cnt > m_cap) {
|
||||
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
|
||||
if (pos < m_size) {
|
||||
@@ -556,7 +556,7 @@ Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, MaybeSV_t<T> const&val) noexcept(useNoexcept) {
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, MaybeView_t<T> const&val) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
|
||||
if (pos < m_size) {
|
||||
@@ -622,7 +622,7 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(T &&item) noexce
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(MaybeSV_t<T> const&item) noexcept(useNoexcept) {
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(MaybeView_t<T> const&item) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserve(m_cap ? m_cap * 2 : initialCap);
|
||||
}
|
||||
|
Reference in New Issue
Block a user