Compare commits
5 Commits
46a7331754
...
5e1698a321
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e1698a321 | |||
| 3e95bc0842 | |||
| 58e19fad48 | |||
| a3a56b24e8 | |||
| 7681830ca6 |
4
deps/ox/src/ox/fs/test/tests.cpp
vendored
4
deps/ox/src/ox/fs/test/tests.cpp
vendored
@@ -175,8 +175,8 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
|||||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||||
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
|
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
|
||||||
ox::FileStore32 fileStore(list, buffLen);
|
ox::FileStore32 fileStore(list, buffLen);
|
||||||
oxAssert(fileStore.write(4, const_cast<char*>(str1), str1Len, 1), "FileStore::write 1 failed.");
|
oxAssert(fileStore.write(4, str1, str1Len, 1), "FileStore::write 1 failed.");
|
||||||
oxAssert(fileStore.write(5, const_cast<char*>(str2), str2Len, 1), "FileStore::write 2 failed.");
|
oxAssert(fileStore.write(5, str2, str2Len, 1), "FileStore::write 2 failed.");
|
||||||
|
|
||||||
char str1Read[str1Len];
|
char str1Read[str1Len];
|
||||||
size_t str1ReadSize = 0;
|
size_t str1ReadSize = 0;
|
||||||
|
|||||||
1
deps/ox/src/ox/mc/CMakeLists.txt
vendored
1
deps/ox/src/ox/mc/CMakeLists.txt
vendored
@@ -1,6 +1,5 @@
|
|||||||
add_library(
|
add_library(
|
||||||
OxMetalClaw
|
OxMetalClaw
|
||||||
presenceindicator.cpp
|
|
||||||
read.cpp
|
read.cpp
|
||||||
write.cpp
|
write.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
17
deps/ox/src/ox/mc/presenceindicator.cpp
vendored
17
deps/ox/src/ox/mc/presenceindicator.cpp
vendored
@@ -1,17 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 - 2025 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/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "err.hpp"
|
|
||||||
#include "presenceindicator.hpp"
|
|
||||||
|
|
||||||
namespace ox {
|
|
||||||
|
|
||||||
template class FieldBitmapWriterBase<uint8_t>;
|
|
||||||
template class FieldBitmapWriterBase<uint8_t const>;
|
|
||||||
|
|
||||||
}
|
|
||||||
222
deps/ox/src/ox/mc/presenceindicator.hpp
vendored
222
deps/ox/src/ox/mc/presenceindicator.hpp
vendored
@@ -22,145 +22,101 @@ namespace ox {
|
|||||||
template<Reader_c Reader>
|
template<Reader_c Reader>
|
||||||
class FieldBitmapReader {
|
class FieldBitmapReader {
|
||||||
protected:
|
protected:
|
||||||
mutable size_t m_mapBlockIdx = ~size_t{0};
|
mutable size_t m_mapBlockIdx = ~size_t{};
|
||||||
mutable uint64_t m_mapBlock = 0;
|
mutable uint64_t m_mapBlock{};
|
||||||
size_t m_mapStart = 0;
|
size_t m_mapStart{};
|
||||||
Reader &m_reader;
|
Reader &m_reader;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit constexpr FieldBitmapReader(Reader &reader) noexcept;
|
explicit constexpr FieldBitmapReader(Reader &reader) noexcept:
|
||||||
|
m_mapStart(reader.tellg()),
|
||||||
|
m_reader(reader) {
|
||||||
|
}
|
||||||
|
|
||||||
constexpr Result<bool> get(size_t idx) const noexcept;
|
constexpr Result<bool> get(size_t idx) const noexcept {
|
||||||
|
constexpr auto blockBits = sizeof(m_mapBlock);
|
||||||
|
auto const blockIdx = idx / blockBits;
|
||||||
|
if (m_mapBlockIdx != blockIdx) [[unlikely]] {
|
||||||
|
OX_RETURN_ERROR(loadMapBlock(blockIdx));
|
||||||
|
}
|
||||||
|
idx %= blockBits;
|
||||||
|
return (m_mapBlock >> idx) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr Error loadMapBlock(size_t idx) const noexcept;
|
constexpr Error loadMapBlock(size_t const idx) const noexcept {
|
||||||
|
OX_REQUIRE(g, m_reader.tellg());
|
||||||
};
|
OX_RETURN_ERROR(m_reader.seekg(static_cast<int>(m_mapStart + idx), ox::ios_base::beg));
|
||||||
|
Array<char, sizeof(m_mapBlock)> mapBlock{};
|
||||||
template<Reader_c Reader>
|
OX_RETURN_ERROR(m_reader.read(mapBlock.data(), sizeof(m_mapBlock)));
|
||||||
constexpr FieldBitmapReader<Reader>::FieldBitmapReader(Reader &reader) noexcept:
|
// Warning: narrow-conv
|
||||||
m_mapStart(reader.tellg()),
|
OX_RETURN_ERROR(m_reader.seekg(static_cast<int>(g), ox::ios_base::beg));
|
||||||
m_reader(reader) {
|
m_mapBlock = 0;
|
||||||
}
|
for (uint64_t i{}; auto b : mapBlock) {
|
||||||
|
m_mapBlock |= static_cast<uint64_t>(std::bit_cast<uint8_t>(b)) << i;
|
||||||
template<Reader_c Reader>
|
i += 8;
|
||||||
constexpr Result<bool> FieldBitmapReader<Reader>::get(size_t idx) const noexcept {
|
}
|
||||||
constexpr auto blockBits = sizeof(m_mapBlock);
|
m_mapBlockIdx = idx;
|
||||||
auto const blockIdx = idx / blockBits;
|
return {};
|
||||||
if (m_mapBlockIdx != blockIdx) [[unlikely]] {
|
|
||||||
OX_RETURN_ERROR(loadMapBlock(blockIdx));
|
|
||||||
}
|
|
||||||
idx %= blockBits;
|
|
||||||
return (m_mapBlock >> idx) & 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Reader_c Reader>
|
|
||||||
constexpr Error FieldBitmapReader<Reader>::loadMapBlock(size_t const idx) const noexcept {
|
|
||||||
OX_REQUIRE(g, m_reader.tellg());
|
|
||||||
OX_RETURN_ERROR(m_reader.seekg(static_cast<int>(m_mapStart + idx), ox::ios_base::beg));
|
|
||||||
Array<char, sizeof(m_mapBlock)> mapBlock{};
|
|
||||||
OX_RETURN_ERROR(m_reader.read(mapBlock.data(), sizeof(m_mapBlock)));
|
|
||||||
// Warning: narrow-conv
|
|
||||||
OX_RETURN_ERROR(m_reader.seekg(static_cast<int>(g), ox::ios_base::beg));
|
|
||||||
m_mapBlock = 0;
|
|
||||||
for (uint64_t i{}; auto b : mapBlock) {
|
|
||||||
m_mapBlock |= static_cast<uint64_t>(std::bit_cast<uint8_t>(b)) << i;
|
|
||||||
i += 8;
|
|
||||||
}
|
|
||||||
m_mapBlockIdx = idx;
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class FieldBitmapWriterBase {
|
|
||||||
protected:
|
|
||||||
Span<T> m_map;
|
|
||||||
size_t m_mapLen = 0;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit constexpr FieldBitmapWriterBase(Span<T> map) noexcept;
|
|
||||||
|
|
||||||
constexpr auto setBuffer(Span<T> map) noexcept;
|
|
||||||
|
|
||||||
constexpr Result<bool> get(size_t i) const noexcept;
|
|
||||||
|
|
||||||
constexpr Error setFields(int) noexcept;
|
|
||||||
|
|
||||||
constexpr void setMaxLen(int) noexcept;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
constexpr int64_t getMaxLen() const noexcept;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr FieldBitmapWriterBase<T>::FieldBitmapWriterBase(Span<T> map) noexcept:
|
|
||||||
m_map(map),
|
|
||||||
m_mapLen(m_map.size()) {
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr auto FieldBitmapWriterBase<T>::setBuffer(Span<T> map) noexcept {
|
|
||||||
m_map = map;
|
|
||||||
m_mapLen = map.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr Result<bool> FieldBitmapWriterBase<T>::get(size_t const i) const noexcept {
|
|
||||||
if (i / 8 < m_mapLen) {
|
|
||||||
return (m_map[i / 8] >> (i % 8)) & 1;
|
|
||||||
} else {
|
|
||||||
return Error{McPresenceMapOverflow};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr Error FieldBitmapWriterBase<T>::setFields(int const fields) noexcept {
|
|
||||||
m_mapLen = static_cast<size_t>((fields / 8 + 1) - (fields % 8 == 0));
|
|
||||||
if (m_mapLen > m_map.size()) [[unlikely]] {
|
|
||||||
return Error{McPresenceMapOverflow};
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr void FieldBitmapWriterBase<T>::setMaxLen(int const maxLen) noexcept {
|
|
||||||
m_mapLen = static_cast<size_t>(maxLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr int64_t FieldBitmapWriterBase<T>::getMaxLen() const noexcept {
|
|
||||||
return static_cast<int64_t>(m_mapLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern template class FieldBitmapWriterBase<uint8_t>;
|
|
||||||
extern template class FieldBitmapWriterBase<uint8_t const>;
|
|
||||||
|
|
||||||
class FieldBitmap: public FieldBitmapWriterBase<uint8_t> {
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit constexpr FieldBitmap(Span<uint8_t> map) noexcept;
|
|
||||||
|
|
||||||
constexpr Error set(size_t i, bool on) noexcept;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr FieldBitmap::FieldBitmap(Span<uint8_t> map) noexcept:
|
|
||||||
FieldBitmapWriterBase(map) {
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Error FieldBitmap::set(size_t const i, bool const on) noexcept {
|
|
||||||
if (i / 8 < m_mapLen) {
|
|
||||||
if (on) {
|
|
||||||
m_map[i / 8] |= 1 << (i % 8);
|
|
||||||
} else {
|
|
||||||
m_map[i / 8] &= ~static_cast<uint8_t>(1 << (i % 8));
|
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
} else {
|
};
|
||||||
return Error(McPresenceMapOverflow);
|
|
||||||
}
|
|
||||||
}
|
class FieldBitmapWriter {
|
||||||
|
protected:
|
||||||
|
Span<char> m_map;
|
||||||
|
size_t m_mapLen{};
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit constexpr FieldBitmapWriter(Span<char> const &map) noexcept:
|
||||||
|
m_map(map),
|
||||||
|
m_mapLen(m_map.size()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr auto setBuffer(Span<char> const &map) noexcept {
|
||||||
|
m_map = map;
|
||||||
|
m_mapLen = map.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Result<bool> get(size_t const i) const noexcept {
|
||||||
|
if (i / 8 < m_mapLen) {
|
||||||
|
return (std::bit_cast<uint8_t>(m_map[i / 8]) >> (i % 8)) & 1;
|
||||||
|
}
|
||||||
|
return Error{McPresenceMapOverflow};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Error setFields(int const fields) noexcept {
|
||||||
|
m_mapLen = static_cast<size_t>((fields / 8 + 1) - (fields % 8 == 0));
|
||||||
|
if (m_mapLen > m_map.size()) [[unlikely]] {
|
||||||
|
return Error{McPresenceMapOverflow};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void setMaxLen(int const maxLen) noexcept {
|
||||||
|
m_mapLen = static_cast<size_t>(maxLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr int64_t getMaxLen() const noexcept {
|
||||||
|
return static_cast<int64_t>(m_mapLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Error set(size_t const i, bool const on) noexcept {
|
||||||
|
if (i / 8 < m_mapLen) {
|
||||||
|
char &actual = m_map[i / 8];
|
||||||
|
uint8_t v = std::bit_cast<uint8_t>(actual);
|
||||||
|
if (on) {
|
||||||
|
v |= 1 << (i % 8);
|
||||||
|
} else {
|
||||||
|
v &= ~static_cast<uint8_t>(1 << (i % 8));
|
||||||
|
}
|
||||||
|
actual = std::bit_cast<char>(v);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return Error{McPresenceMapOverflow};
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
49
deps/ox/src/ox/mc/write.hpp
vendored
49
deps/ox/src/ox/mc/write.hpp
vendored
@@ -29,12 +29,12 @@
|
|||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
template<Writer_c Writer>
|
template<Writer_c Writer>
|
||||||
class MetalClawWriter {
|
class MetalClawWriter: public ModelHandlerBase<MetalClawWriter<Writer>, OpType::Write> {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<uint8_t, 16> m_presenceMapBuff{};
|
Vector<char, 16> m_presenceMapBuff{};
|
||||||
FieldBitmap m_fieldPresence;
|
FieldBitmapWriter m_fieldPresence{m_presenceMapBuff};
|
||||||
int m_field = 0;
|
int m_field{};
|
||||||
Optional<int> m_unionIdx;
|
Optional<int> m_unionIdx;
|
||||||
size_t m_writerBeginP{};
|
size_t m_writerBeginP{};
|
||||||
Writer &m_writer;
|
Writer &m_writer;
|
||||||
@@ -105,12 +105,7 @@ class MetalClawWriter {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
constexpr Error finalize() noexcept;
|
||||||
static constexpr auto opType() noexcept {
|
|
||||||
return OpType::Write;
|
|
||||||
}
|
|
||||||
|
|
||||||
Error finalize() noexcept;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr Error appendInteger(Integer_c auto val) noexcept {
|
constexpr Error appendInteger(Integer_c auto val) noexcept {
|
||||||
@@ -132,7 +127,6 @@ extern template class ModelHandlerInterface<MetalClawWriter<CharBuffWriter>>;
|
|||||||
|
|
||||||
template<Writer_c Writer>
|
template<Writer_c Writer>
|
||||||
constexpr MetalClawWriter<Writer>::MetalClawWriter(Writer &writer, Optional<int> const &unionIdx) noexcept:
|
constexpr MetalClawWriter<Writer>::MetalClawWriter(Writer &writer, Optional<int> const &unionIdx) noexcept:
|
||||||
m_fieldPresence(m_presenceMapBuff),
|
|
||||||
m_unionIdx(unionIdx),
|
m_unionIdx(unionIdx),
|
||||||
m_writerBeginP(writer.tellp()),
|
m_writerBeginP(writer.tellp()),
|
||||||
m_writer(writer) {
|
m_writer(writer) {
|
||||||
@@ -267,9 +261,8 @@ constexpr Error MetalClawWriter<Writer>::field(CString, T const *val) noexcept {
|
|||||||
bool fieldSet = false;
|
bool fieldSet = false;
|
||||||
if (val && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (val && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
auto const writeIdx = m_writer.tellp();
|
auto const writeIdx = m_writer.tellp();
|
||||||
MetalClawWriter<Writer> writer(m_writer);
|
MetalClawWriter writer(m_writer);
|
||||||
ModelHandlerInterface<MetalClawWriter<Writer>> handler{writer};
|
OX_RETURN_ERROR(model(writer.interface(), val));
|
||||||
OX_RETURN_ERROR(model(&handler, val));
|
|
||||||
OX_RETURN_ERROR(writer.finalize());
|
OX_RETURN_ERROR(writer.finalize());
|
||||||
fieldSet = writeIdx != m_writer.tellp();
|
fieldSet = writeIdx != m_writer.tellp();
|
||||||
}
|
}
|
||||||
@@ -285,9 +278,8 @@ constexpr Error MetalClawWriter<Writer>::field(CString, UnionView<U, force> val)
|
|||||||
bool fieldSet = false;
|
bool fieldSet = false;
|
||||||
if (val.get() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (val.get() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
auto const writeIdx = m_writer.tellp();
|
auto const writeIdx = m_writer.tellp();
|
||||||
MetalClawWriter<Writer> writer(m_writer, Optional<int>(in_place, val.idx()));
|
MetalClawWriter writer(m_writer, Optional<int>(in_place, val.idx()));
|
||||||
ModelHandlerInterface handler{writer};
|
OX_RETURN_ERROR(model(writer.interface(), val.get()));
|
||||||
OX_RETURN_ERROR(model(&handler, val.get()));
|
|
||||||
OX_RETURN_ERROR(writer.finalize());
|
OX_RETURN_ERROR(writer.finalize());
|
||||||
fieldSet = writeIdx != m_writer.tellp();
|
fieldSet = writeIdx != m_writer.tellp();
|
||||||
}
|
}
|
||||||
@@ -305,13 +297,12 @@ constexpr Error MetalClawWriter<Writer>::field(CString, T const *val, size_t con
|
|||||||
auto const arrLen = mc::encodeInteger(len);
|
auto const arrLen = mc::encodeInteger(len);
|
||||||
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<CString>(arrLen.data.data()), arrLen.length));
|
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<CString>(arrLen.data.data()), arrLen.length));
|
||||||
auto const writeIdx = m_writer.tellp();
|
auto const writeIdx = m_writer.tellp();
|
||||||
MetalClawWriter<Writer> writer(m_writer);
|
MetalClawWriter writer(m_writer);
|
||||||
ModelHandlerInterface handler{writer};
|
OX_RETURN_ERROR(writer.interface()->template setTypeInfo<T>("List", 0, {}, static_cast<size_t>(len)));
|
||||||
OX_RETURN_ERROR(handler.template setTypeInfo<T>("List", 0, {}, static_cast<size_t>(len)));
|
|
||||||
// write the array
|
// write the array
|
||||||
for (size_t i{}; i < len; ++i) {
|
for (size_t i{}; i < len; ++i) {
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
OX_RETURN_ERROR(handler.field("", &val[i]));
|
OX_RETURN_ERROR(writer.interface()->field("", &val[i]));
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
OX_RETURN_ERROR(writer.finalize());
|
OX_RETURN_ERROR(writer.finalize());
|
||||||
@@ -333,10 +324,9 @@ constexpr Error MetalClawWriter<Writer>::field(CString, HashMap<String, T> const
|
|||||||
auto const arrLen = mc::encodeInteger(len);
|
auto const arrLen = mc::encodeInteger(len);
|
||||||
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<CString>(arrLen.data.data()), arrLen.length));
|
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<CString>(arrLen.data.data()), arrLen.length));
|
||||||
// write map
|
// write map
|
||||||
MetalClawWriter<Writer> writer(m_writer);
|
MetalClawWriter writer(m_writer);
|
||||||
ModelHandlerInterface handler{writer};
|
|
||||||
// double len for both key and value
|
// double len for both key and value
|
||||||
OX_RETURN_ERROR(handler.setTypeInfo("Map", 0, {}, len * 2));
|
OX_RETURN_ERROR(writer.interface()->setTypeInfo("Map", 0, {}, len * 2));
|
||||||
// this loop body needs to be in a lambda because of the potential alloca call
|
// this loop body needs to be in a lambda because of the potential alloca call
|
||||||
constexpr auto loopBody = [](auto &handler, auto const &key, auto const &val) -> Error {
|
constexpr auto loopBody = [](auto &handler, auto const &key, auto const &val) -> Error {
|
||||||
auto const keyLen = key.size();
|
auto const keyLen = key.size();
|
||||||
@@ -349,7 +339,7 @@ constexpr Error MetalClawWriter<Writer>::field(CString, HashMap<String, T> const
|
|||||||
// write the array
|
// write the array
|
||||||
for (size_t i{}; i < len; ++i) {
|
for (size_t i{}; i < len; ++i) {
|
||||||
auto const &key = keys[i];
|
auto const &key = keys[i];
|
||||||
OX_RETURN_ERROR(loopBody(handler, key, *val));
|
OX_RETURN_ERROR(loopBody(*writer.interface(), key, *val));
|
||||||
}
|
}
|
||||||
OX_RETURN_ERROR(writer.finalize());
|
OX_RETURN_ERROR(writer.finalize());
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
@@ -374,20 +364,19 @@ constexpr Error MetalClawWriter<Writer>::setTypeInfo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<Writer_c Writer>
|
template<Writer_c Writer>
|
||||||
Error MetalClawWriter<Writer>::finalize() noexcept {
|
constexpr Error MetalClawWriter<Writer>::finalize() noexcept {
|
||||||
auto const end = m_writer.tellp();
|
auto const end = m_writer.tellp();
|
||||||
OX_RETURN_ERROR(m_writer.seekp(m_writerBeginP));
|
OX_RETURN_ERROR(m_writer.seekp(m_writerBeginP));
|
||||||
OX_RETURN_ERROR(m_writer.write(
|
OX_RETURN_ERROR(m_writer.write(
|
||||||
reinterpret_cast<CString>(m_presenceMapBuff.data()),
|
m_presenceMapBuff.data(),
|
||||||
m_presenceMapBuff.size()));
|
m_presenceMapBuff.size()));
|
||||||
OX_RETURN_ERROR(m_writer.seekp(end));
|
OX_RETURN_ERROR(m_writer.seekp(end));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Buffer> writeMC(Writer_c auto &writer, auto const &val) noexcept {
|
Result<Buffer> writeMC(Writer_c auto &writer, auto const &val) noexcept {
|
||||||
MetalClawWriter mcWriter(writer);
|
MetalClawWriter mcWriter(writer);
|
||||||
ModelHandlerInterface handler{mcWriter};
|
OX_RETURN_ERROR(model(mcWriter.interface(), &val));
|
||||||
OX_RETURN_ERROR(model(&handler, &val));
|
|
||||||
OX_RETURN_ERROR(mcWriter.finalize());
|
OX_RETURN_ERROR(mcWriter.finalize());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
64
deps/ox/src/ox/model/modelhandleradaptor.hpp
vendored
64
deps/ox/src/ox/model/modelhandleradaptor.hpp
vendored
@@ -25,28 +25,28 @@ class ModelHandlerInterface {
|
|||||||
|
|
||||||
template<typename T = std::nullptr_t>
|
template<typename T = std::nullptr_t>
|
||||||
constexpr ox::Error setTypeInfo(
|
constexpr ox::Error setTypeInfo(
|
||||||
const char* name = T::TypeName,
|
CString name = T::TypeName,
|
||||||
int version = T::TypeVersion,
|
int version = T::TypeVersion,
|
||||||
const Vector<String>& typeParams = {}) noexcept {
|
Vector<String> const &typeParams = {}) noexcept {
|
||||||
return m_handler.template setTypeInfo<T>(name, version, typeParams, ModelFieldCount_v<T>);
|
return m_handler.template setTypeInfo<T>(name, version, typeParams, ModelFieldCount_v<T>);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T = std::nullptr_t>
|
template<typename T = std::nullptr_t>
|
||||||
constexpr ox::Error setTypeInfo(
|
constexpr ox::Error setTypeInfo(
|
||||||
const char *name,
|
CString name,
|
||||||
int version,
|
int version,
|
||||||
const Vector<String>& typeParams,
|
Vector<String> const &typeParams,
|
||||||
std::size_t fields) noexcept {
|
size_t fields) noexcept {
|
||||||
return m_handler.template setTypeInfo<T>(name, version, typeParams, fields);
|
return m_handler.template setTypeInfo<T>(name, version, typeParams, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t len>
|
template<size_t len>
|
||||||
constexpr Error fieldCString(const char *name, char val[len]) noexcept {
|
constexpr Error fieldCString(CString name, char val[len]) noexcept {
|
||||||
return m_handler.fieldCString(name, &val[0], len);
|
return m_handler.fieldCString(name, &val[0], len);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t len>
|
template<size_t len>
|
||||||
constexpr Error fieldCString(const char *name, const char val[len]) noexcept requires(opType_v != OpType::Read) {
|
constexpr Error fieldCString(CString name, char const val[len]) noexcept requires(opType_v != OpType::Read) {
|
||||||
if constexpr(opType_v != OpType::Read) {
|
if constexpr(opType_v != OpType::Read) {
|
||||||
return m_handler.fieldCString(name, &val[0], len);
|
return m_handler.fieldCString(name, &val[0], len);
|
||||||
} else {
|
} else {
|
||||||
@@ -54,11 +54,11 @@ class ModelHandlerInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error fieldCString(const char *name, char **val) noexcept {
|
constexpr Error fieldCString(CString name, char **val) noexcept {
|
||||||
return m_handler.fieldCString(name, val);
|
return m_handler.fieldCString(name, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error fieldCString(const char *name, const char *const*val) noexcept requires(opType_v != OpType::Read) {
|
constexpr Error fieldCString(CString name, char const *const*val) noexcept requires(opType_v != OpType::Read) {
|
||||||
// this check looks pointless, but it's to address a Clang bug
|
// this check looks pointless, but it's to address a Clang bug
|
||||||
if constexpr(opType_v != OpType::Read) {
|
if constexpr(opType_v != OpType::Read) {
|
||||||
return m_handler.fieldCString(name, val);
|
return m_handler.fieldCString(name, val);
|
||||||
@@ -67,7 +67,7 @@ class ModelHandlerInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error fieldCString(const char *name, const char **val) noexcept requires(opType_v != OpType::Read) {
|
constexpr Error fieldCString(CString name, char const **val) noexcept requires(opType_v != OpType::Read) {
|
||||||
// this check looks pointless, but it's to address a Clang bug
|
// this check looks pointless, but it's to address a Clang bug
|
||||||
if constexpr(opType_v != OpType::Read) {
|
if constexpr(opType_v != OpType::Read) {
|
||||||
return m_handler.fieldCString(name, val);
|
return m_handler.fieldCString(name, val);
|
||||||
@@ -76,11 +76,11 @@ class ModelHandlerInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error fieldCString(const char *name, char **val, std::size_t buffLen) noexcept {
|
constexpr Error fieldCString(CString name, char **val, size_t buffLen) noexcept {
|
||||||
return m_handler.fieldCString(name, val, buffLen);
|
return m_handler.fieldCString(name, val, buffLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error fieldCString(const char *name, const char **val, std::size_t buffLen) noexcept requires(opType_v != OpType::Read) {
|
constexpr Error fieldCString(CString name, char const **val, size_t buffLen) noexcept requires(opType_v != OpType::Read) {
|
||||||
// this check looks pointless, but it's to address a Clang bug
|
// this check looks pointless, but it's to address a Clang bug
|
||||||
if constexpr(opType_v != OpType::Read) {
|
if constexpr(opType_v != OpType::Read) {
|
||||||
return m_handler.fieldCString(name, val, buffLen);
|
return m_handler.fieldCString(name, val, buffLen);
|
||||||
@@ -89,11 +89,11 @@ class ModelHandlerInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error fieldCString(const char *name, char *val, std::size_t buffLen) noexcept {
|
constexpr Error fieldCString(CString name, char *val, size_t buffLen) noexcept {
|
||||||
return m_handler.fieldCString(name, val, buffLen);
|
return m_handler.fieldCString(name, val, buffLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error fieldModelValue(const char *name, CommonPtrWith<ModelValue> auto *v) noexcept {
|
constexpr Error fieldModelValue(char const *name, CommonPtrWith<ModelValue> auto *v) noexcept {
|
||||||
switch (v->type()) {
|
switch (v->type()) {
|
||||||
case ModelValue::Type::Undefined:
|
case ModelValue::Type::Undefined:
|
||||||
break;
|
break;
|
||||||
@@ -123,10 +123,10 @@ class ModelHandlerInterface {
|
|||||||
{
|
{
|
||||||
auto &u = v->template get<ModelUnion>();
|
auto &u = v->template get<ModelUnion>();
|
||||||
if constexpr(opType_v == OpType::Read) {
|
if constexpr(opType_v == OpType::Read) {
|
||||||
u.setActiveField(m_handler.whichFieldPresent(name, u));
|
u.setActiveField(whichFieldPresent(m_handler, name, u));
|
||||||
return m_handler.field(name, UnionView<ModelUnion, true>(&u, u.unionIdx()));
|
return m_handler.field(name, UnionView<ModelUnion, true>(&u, u.unionIdx()));
|
||||||
} else {
|
} else {
|
||||||
return m_handler.field(name, UnionView<const ModelUnion, true>(&u, u.unionIdx()));
|
return m_handler.field(name, UnionView<ModelUnion const, true>(&u, u.unionIdx()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case ModelValue::Type::Vector:
|
case ModelValue::Type::Vector:
|
||||||
@@ -141,12 +141,12 @@ class ModelHandlerInterface {
|
|||||||
|
|
||||||
// array handler, with callback to allow handling individual elements
|
// array handler, with callback to allow handling individual elements
|
||||||
template<typename T, typename Callback>
|
template<typename T, typename Callback>
|
||||||
constexpr Error field(const char *name, Callback cb) noexcept {
|
constexpr Error field(CString name, Callback cb) noexcept {
|
||||||
return m_handler.template field<T, Callback>(name, cb);
|
return m_handler.template field<T, Callback>(name, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error field(const char *name, const T *v) noexcept {
|
constexpr Error field(CString name, const T *v) noexcept {
|
||||||
if constexpr(ox::is_same_v<T, ModelValue>) {
|
if constexpr(ox::is_same_v<T, ModelValue>) {
|
||||||
return fieldModelValue(name, v);
|
return fieldModelValue(name, v);
|
||||||
} else {
|
} else {
|
||||||
@@ -155,7 +155,7 @@ class ModelHandlerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error field(const char *name, T *v) noexcept {
|
constexpr Error field(CString name, T *v) noexcept {
|
||||||
if constexpr(ox::is_same_v<T, ModelValue>) {
|
if constexpr(ox::is_same_v<T, ModelValue>) {
|
||||||
return fieldModelValue(name, v);
|
return fieldModelValue(name, v);
|
||||||
} else {
|
} else {
|
||||||
@@ -164,11 +164,11 @@ class ModelHandlerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, bool force = false>
|
template<typename U, bool force = false>
|
||||||
constexpr Error field(const char *name, UnionView<U, force> val) noexcept {
|
constexpr Error field(CString name, UnionView<U, force> val) noexcept {
|
||||||
return m_handler.field(name, val);
|
return m_handler.field(name, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error field(const char *name, auto *val, std::size_t len) noexcept {
|
constexpr Error field(CString name, auto *val, size_t len) noexcept {
|
||||||
return m_handler.field(name, val, len);
|
return m_handler.field(name, val, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ class ModelHandlerInterface {
|
|||||||
* @param pass indicates that the parsing should iterate past the array length
|
* @param pass indicates that the parsing should iterate past the array length
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto arrayLength(const char *name, bool pass = true) noexcept {
|
constexpr auto arrayLength(CString name, bool pass = true) noexcept {
|
||||||
return m_handler.arrayLength(name, pass);
|
return m_handler.arrayLength(name, pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ class ModelHandlerInterface {
|
|||||||
* Reads an string length from the current location in the buffer.
|
* Reads an string length from the current location in the buffer.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto stringLength(const char *name) noexcept {
|
constexpr auto stringLength(CString name) noexcept {
|
||||||
return m_handler.stringLength(name);
|
return m_handler.stringLength(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,6 +199,20 @@ class ModelHandlerInterface {
|
|||||||
constexpr auto handler() noexcept {
|
constexpr auto handler() noexcept {
|
||||||
return m_handler;
|
return m_handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename H>
|
||||||
|
static constexpr int whichFieldPresent(H &h, CString name, ModelUnion const &u) noexcept
|
||||||
|
requires(H::opType() == OpType::Read) {
|
||||||
|
return h.whichFieldPresent(name, u);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename H>
|
||||||
|
static constexpr int whichFieldPresent(H&, CString, ModelUnion const&) noexcept
|
||||||
|
requires(H::opType() != OpType::Read) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Handler, OpType opType_v = Handler::opType()>
|
template<typename Handler, OpType opType_v = Handler::opType()>
|
||||||
|
|||||||
6
deps/ox/src/ox/model/modelvalue.hpp
vendored
6
deps/ox/src/ox/model/modelvalue.hpp
vendored
@@ -200,8 +200,6 @@ class ModelValue {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error set(T &&v) noexcept;
|
constexpr Error set(T &&v) noexcept;
|
||||||
|
|
||||||
constexpr ModelValue &operator=(ModelValue &val) noexcept;
|
|
||||||
|
|
||||||
constexpr ModelValue &operator=(const ModelValue &val) noexcept;
|
constexpr ModelValue &operator=(const ModelValue &val) noexcept;
|
||||||
|
|
||||||
constexpr ModelValue &operator=(ModelValue &&val) noexcept;
|
constexpr ModelValue &operator=(ModelValue &&val) noexcept;
|
||||||
@@ -1202,10 +1200,6 @@ constexpr Error ModelValue::set(T &&v) noexcept {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ModelValue &ModelValue::operator=(ModelValue &other) noexcept {
|
|
||||||
return this->operator=(const_cast<const ModelValue&>(other));
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ModelValue &ModelValue::operator=(const ModelValue &other) noexcept {
|
constexpr ModelValue &ModelValue::operator=(const ModelValue &other) noexcept {
|
||||||
if (this == &other) [[unlikely]] {
|
if (this == &other) [[unlikely]] {
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
37
deps/ox/src/ox/std/serialize.hpp
vendored
37
deps/ox/src/ox/std/serialize.hpp
vendored
@@ -18,7 +18,7 @@ namespace ox {
|
|||||||
|
|
||||||
template<typename PlatSpec>
|
template<typename PlatSpec>
|
||||||
struct VectorMemMap {
|
struct VectorMemMap {
|
||||||
const std::size_t smallVecSize = 0; // not a map value
|
size_t const smallVecSize = 0; // not a map value
|
||||||
typename PlatSpec::size_t size = 0;
|
typename PlatSpec::size_t size = 0;
|
||||||
typename PlatSpec::size_t cap = 0;
|
typename PlatSpec::size_t cap = 0;
|
||||||
typename PlatSpec::PtrType items = 0;
|
typename PlatSpec::PtrType items = 0;
|
||||||
@@ -26,11 +26,11 @@ struct VectorMemMap {
|
|||||||
|
|
||||||
template<typename PlatSpec>
|
template<typename PlatSpec>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto sizeOf(const VectorMemMap<PlatSpec> *t) noexcept {
|
constexpr auto sizeOf(VectorMemMap<PlatSpec> const *t) noexcept {
|
||||||
constexpr auto padding = [](std::size_t size, std::size_t al) {
|
constexpr auto padding = [](size_t const size, size_t const al) {
|
||||||
return size % al;
|
return size % al;
|
||||||
};
|
};
|
||||||
std::size_t size = 0;
|
size_t size = 0;
|
||||||
if (t->smallVecSize) {
|
if (t->smallVecSize) {
|
||||||
size += t->smallVecSize;
|
size += t->smallVecSize;
|
||||||
size += padding(size, PlatSpec::alignOf(t->size));
|
size += padding(size, PlatSpec::alignOf(t->size));
|
||||||
@@ -43,17 +43,17 @@ constexpr auto sizeOf(const VectorMemMap<PlatSpec> *t) noexcept {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename PlatSpec, std::size_t SmallVecSize = 0>
|
template<typename PlatSpec, size_t SmallVecSize = 0>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto alignOf(const VectorMemMap<PlatSpec>&) noexcept {
|
constexpr auto alignOf(VectorMemMap<PlatSpec> const&) noexcept {
|
||||||
const typename PlatSpec::size_t i = 0;
|
typename PlatSpec::size_t const i = 0;
|
||||||
return PlatSpec::alignOf(i);
|
return PlatSpec::alignOf(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename PlatSpec, typename T>
|
template<typename PlatSpec, typename T>
|
||||||
constexpr ox::Error pad(Writer_c auto &w, const T *v) noexcept {
|
constexpr Error pad(Writer_c auto &w, T const *v) noexcept {
|
||||||
const auto a = PlatSpec::alignOf(*v);
|
auto const a = PlatSpec::alignOf(*v);
|
||||||
const auto excess = w.tellp() % a;
|
auto const excess = w.tellp() % a;
|
||||||
if (excess) {
|
if (excess) {
|
||||||
return w.write(nullptr, a - excess);
|
return w.write(nullptr, a - excess);
|
||||||
} else {
|
} else {
|
||||||
@@ -62,7 +62,7 @@ constexpr ox::Error pad(Writer_c auto &w, const T *v) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename PlatSpec>
|
template<typename PlatSpec>
|
||||||
constexpr ox::Error serialize(Writer_c auto &w, const VectorMemMap<PlatSpec> &vm) noexcept {
|
constexpr Error serialize(Writer_c auto &w, VectorMemMap<PlatSpec> const &vm) noexcept {
|
||||||
OX_RETURN_ERROR(w.write(nullptr, vm.smallVecSize));
|
OX_RETURN_ERROR(w.write(nullptr, vm.smallVecSize));
|
||||||
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.size)));
|
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.size)));
|
||||||
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.cap)));
|
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.cap)));
|
||||||
@@ -70,21 +70,20 @@ constexpr ox::Error serialize(Writer_c auto &w, const VectorMemMap<PlatSpec> &vm
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
constexpr Error serialize(Writer_c auto &w, Integral_c auto val) noexcept {
|
||||||
constexpr ox::Error serialize(Writer_c auto &w, T val) noexcept requires(is_integer_v<T>) {
|
Array<char, sizeof(val)> tmp;
|
||||||
ox::Array<char, sizeof(T)> tmp;
|
for (auto i = 0u; i < sizeof(val); ++i) {
|
||||||
for (auto i = 0u; i < sizeof(T); ++i) {
|
|
||||||
tmp[i] = static_cast<char>((val >> i * 8) & 255);
|
tmp[i] = static_cast<char>((val >> i * 8) & 255);
|
||||||
}
|
}
|
||||||
return w.write(tmp.data(), tmp.size());
|
return w.write(tmp.data(), tmp.size());
|
||||||
};
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Result<ox::Array<char, sizeof(T)>> serialize(const T &in) noexcept {
|
constexpr Result<Array<char, sizeof(T)>> serialize(T const &in) noexcept {
|
||||||
ox::Array<char, sizeof(T)> out = {};
|
Array<char, sizeof(T)> out = {};
|
||||||
CharBuffWriter w(out);
|
CharBuffWriter w(out);
|
||||||
OX_RETURN_ERROR(serialize(w, in));
|
OX_RETURN_ERROR(serialize(w, in));
|
||||||
return out;
|
return out;
|
||||||
};
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
25
deps/ox/src/ox/std/strops.cpp
vendored
25
deps/ox/src/ox/std/strops.cpp
vendored
@@ -7,9 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "def.hpp"
|
#include "def.hpp"
|
||||||
|
#include "span.hpp"
|
||||||
#include "strops.hpp"
|
#include "strops.hpp"
|
||||||
|
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
|
||||||
|
|
||||||
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
|
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
|
||||||
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
|
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
|
||||||
@@ -19,30 +19,25 @@ static_assert(ox::strcmp("resize", "resize") == 0, "resize == resize");
|
|||||||
static_assert(ox::strcmp("", "") == 0, "\"\" == \"\"");
|
static_assert(ox::strcmp("", "") == 0, "\"\" == \"\"");
|
||||||
|
|
||||||
static_assert([] {
|
static_assert([] {
|
||||||
auto testStr = "asdf";
|
auto constexpr testStr = ox::Span{"asdf"};
|
||||||
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
return ox::strchr(testStr.data(), 0, 4) == &testStr[4];
|
||||||
return ox::strchr(testStr, 0, 4) == &testStr[4];
|
|
||||||
OX_CLANG_NOWARN_END
|
|
||||||
}(), "ox::strchr 0");
|
}(), "ox::strchr 0");
|
||||||
|
|
||||||
static_assert([] {
|
static_assert([] {
|
||||||
int retval = 0;
|
auto constexpr testStr = "aaaa";
|
||||||
auto testStr = "aaaa";
|
|
||||||
// test the const and non-const versions of ox::lastIndexOf
|
// test the const and non-const versions of ox::lastIndexOf
|
||||||
retval |= !(ox::lastIndexOf(const_cast<char*>(testStr), 'a', ox::strlen(testStr)) == 3);
|
return ox::lastIndexOf(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
|
#ifndef OX_USE_STDLIB
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
std::size_t strlen(const char *str) {
|
size_t strlen(const char *str) {
|
||||||
std::size_t len = 0;
|
size_t len{};
|
||||||
for (; str[len]; len++);
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
|
while (str[len]) { ++len; }
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
|
||||||
82
deps/ox/src/ox/std/typetraits.hpp
vendored
82
deps/ox/src/ox/std/typetraits.hpp
vendored
@@ -34,6 +34,41 @@ inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(T);
|
|||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct remove_cv {
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct remove_cv<const T> {
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct remove_cv<volatile T> {
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct remove_cv<const volatile T> {
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct remove_const {
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct remove_const<const T> {
|
||||||
|
using type = T;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using remove_const_t = typename remove_const<T>::type;
|
||||||
|
|
||||||
|
|
||||||
template<class T, T v>
|
template<class T, T v>
|
||||||
struct integral_constant {
|
struct integral_constant {
|
||||||
|
|
||||||
@@ -109,6 +144,12 @@ template<> struct is_integer<int16_t> : true_type {};
|
|||||||
template<> struct is_integer<uint16_t>: true_type {};
|
template<> struct is_integer<uint16_t>: true_type {};
|
||||||
template<> struct is_integer<int32_t> : true_type {};
|
template<> struct is_integer<int32_t> : true_type {};
|
||||||
template<> struct is_integer<uint32_t>: true_type {};
|
template<> struct is_integer<uint32_t>: true_type {};
|
||||||
|
template<> struct is_integer<int8_t const> : true_type {};
|
||||||
|
template<> struct is_integer<uint8_t const> : true_type {};
|
||||||
|
template<> struct is_integer<int16_t const> : true_type {};
|
||||||
|
template<> struct is_integer<uint16_t const>: true_type {};
|
||||||
|
template<> struct is_integer<int32_t const> : true_type {};
|
||||||
|
template<> struct is_integer<uint32_t const>: true_type {};
|
||||||
|
|
||||||
// some of these need to be done with the actual language syntax because no one
|
// some of these need to be done with the actual language syntax because no one
|
||||||
// can agree on what an (u)int64_t is...
|
// can agree on what an (u)int64_t is...
|
||||||
@@ -116,9 +157,13 @@ template<> struct is_integer<long>: true_type {};
|
|||||||
template<> struct is_integer<long long>: true_type {};
|
template<> struct is_integer<long long>: true_type {};
|
||||||
template<> struct is_integer<unsigned long>: true_type {};
|
template<> struct is_integer<unsigned long>: true_type {};
|
||||||
template<> struct is_integer<unsigned long long>: true_type {};
|
template<> struct is_integer<unsigned long long>: true_type {};
|
||||||
|
template<> struct is_integer<long const>: true_type {};
|
||||||
|
template<> struct is_integer<long long const>: true_type {};
|
||||||
|
template<> struct is_integer<unsigned long const>: true_type {};
|
||||||
|
template<> struct is_integer<unsigned long long const>: true_type {};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr bool is_integer_v = is_integral<T>::value;
|
constexpr bool is_integer_v = is_integer<T>::value;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept Integer_c = is_integer<T>::value;
|
concept Integer_c = is_integer<T>::value;
|
||||||
@@ -264,41 +309,6 @@ template<class T>
|
|||||||
constexpr bool is_move_constructible_v = detail::is_move_constructible<T>(0);
|
constexpr bool is_move_constructible_v = detail::is_move_constructible<T>(0);
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct remove_cv {
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct remove_cv<const T> {
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct remove_cv<volatile T> {
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct remove_cv<const volatile T> {
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct remove_const {
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct remove_const<const T> {
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using remove_const_t = typename remove_const<T>::type;
|
|
||||||
|
|
||||||
|
|
||||||
// is String?
|
// is String?
|
||||||
|
|
||||||
template<std::size_t SmallStringSize>
|
template<std::size_t SmallStringSize>
|
||||||
|
|||||||
Reference in New Issue
Block a user