Merge commit '420fa96463f59c4a4a7cd66b16b0ad01ab0d55e6'

This commit is contained in:
Gary Talent 2024-05-08 23:55:07 -05:00
commit 7d1641faee
44 changed files with 529 additions and 344 deletions

8
.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,22 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C>
<option name="INDENT_NAMESPACE_MEMBERS" value="0" />
<option name="INDENT_CLASS_MEMBERS" value="8" />
<option name="INDENT_VISIBILITY_KEYWORDS" value="4" />
</Objective-C>
<Objective-C-extensions>
<extensions>
<pair source="cpp" header="hpp" fileNamingConvention="LOWERCASE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
<pair source="cu" header="cuh" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
<codeStyleSettings language="ObjectiveC">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -1,5 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="DrinkingTea" />
</state>
</component>

View File

@ -1,17 +0,0 @@
/*
* Copyright 2016 - 2021 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 http://mozilla.org/MPL/2.0/.
*/
#[[#pragma]]# once
${NAMESPACES_OPEN}
class ${NAME} {
};
${NAMESPACES_CLOSE}

View File

@ -1,13 +0,0 @@
/*
* Copyright 2016 - 2021 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 http://mozilla.org/MPL/2.0/.
*/
#[[#include]]# "${HEADER_FILENAME}"
${NAMESPACES_OPEN}
${NAMESPACES_CLOSE}

View File

@ -1,24 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
<option name="clangTidyChecks" value="-*,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof,cert-*,misc-*,readability-duplicate-include,-misc-non-private-member-variables-in-classes,-misc-no-recursion,bugprone-*,clang-analyzer-*,modernize-*,portability-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters" />
</inspection_tool>
<inspection_tool class="Clazy" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ConstantConditionsOC" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ConstantFunctionResult" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ConstantParameter" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="DanglingPointers" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="EndlessLoop" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="InfiniteRecursion" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="LocalValueEscapesScope" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="LoopDoesntUseConditionVariable" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="NullDereference" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="NullDereferences" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="UnreachableCallsOfFunction" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="UnreachableCode" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="UnusedLocalVariable" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="UnusedParameter" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="UnusedValue" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

17
.idea/misc.xml generated
View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompDBSettings">
<option name="linkedExternalProjectsSettings">
<CompDBProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</CompDBProjectSettings>
</option>
</component>
<component name="CompDBWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="ExternalStorageConfigurationManager" enabled="true" />
</project>

8
.idea/nostalgia.iml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="Python" name="Python facet">
<configuration sdkName="Python 3.8" />
</facet>
</component>
</module>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -12,34 +12,66 @@
namespace ox { namespace ox {
Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcept { ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept {
const auto s1End = ox::strchr(buff, ';', buffLen); auto buffRaw = buff.data();
auto buffLen = buff.size();
size_t outSz{};
const auto s1End = ox::strchr(buffRaw, ';', buffLen);
if (!s1End) { if (!s1End) {
return OxError(1, "Could not read Claw header"); return OxError(1, "Could not read Claw header");
} }
const auto s1Size = static_cast<std::size_t>(s1End - buff); auto const fmtSz = static_cast<std::size_t>(s1End - buffRaw) + 1;
const String fmt(buff, s1Size); buffRaw += fmtSz;
buff += s1Size + 1; buffLen -= fmtSz;
buffLen -= s1Size + 1; outSz += fmtSz;
auto const s2End = ox::strchr(buffRaw, ';', buffLen);
const auto s2End = ox::strchr(buff, ';', buffLen);
if (!s2End) { if (!s2End) {
return OxError(2, "Could not read Claw header"); return OxError(2, "Could not read Claw header");
} }
const auto s2Size = static_cast<std::size_t>(s2End - buff); auto const s2Size = static_cast<std::size_t>(s2End - buffRaw) + 1;
const String typeName(buff, s2Size); buffRaw += s2Size;
buff += s2Size + 1; buffLen -= s2Size;
buffLen -= s2Size + 1; outSz += s2Size;
auto const s3End = ox::strchr(buffRaw, ';', buffLen) + 1;
const auto s3End = ox::strchr(buff, ';', buffLen);
if (!s3End) { if (!s3End) {
return OxError(3, "Could not read Claw header"); return OxError(3, "Could not read Claw header");
} }
const auto s3Size = static_cast<std::size_t>(s3End - buff); auto const s3Size = static_cast<std::size_t>(s3End - buffRaw);
const String versionStr(buff, s3Size); buffRaw += s3Size;
buff += s3Size + 1; buffLen -= s3Size;
buffLen -= s3Size + 1; outSz += s3Size;
return {{buff.data() + fmtSz, outSz - fmtSz - 1}};
}
Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
auto buffRaw = buff.data();
auto buffLen = buff.size();
const auto s1End = ox::strchr(buffRaw, ';', buffLen);
if (!s1End) {
return OxError(1, "Could not read Claw header");
}
auto const s1Size = static_cast<std::size_t>(s1End - buffRaw);
StringView const fmt(buffRaw, s1Size);
buffRaw += s1Size + 1;
buffLen -= s1Size + 1;
auto const s2End = ox::strchr(buffRaw, ';', buffLen);
if (!s2End) {
return OxError(2, "Could not read Claw header");
}
auto const s2Size = static_cast<std::size_t>(s2End - buffRaw);
StringView const typeName(buffRaw, s2Size);
buffRaw += s2Size + 1;
buffLen -= s2Size + 1;
auto const s3End = ox::strchr(buffRaw, ';', buffLen);
if (!s3End) {
return OxError(3, "Could not read Claw header");
}
auto const s3Size = static_cast<std::size_t>(s3End - buffRaw);
StringView const versionStr(buffRaw, s3Size);
buffRaw += s3Size + 1;
buffLen -= s3Size + 1;
ClawHeader hdr; ClawHeader hdr;
if (fmt == "M2") { if (fmt == "M2") {
hdr.fmt = ClawFormat::Metal; hdr.fmt = ClawFormat::Metal;
@ -49,32 +81,21 @@ Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcep
return OxError(4, "Claw format does not match any supported format/version combo"); return OxError(4, "Claw format does not match any supported format/version combo");
} }
hdr.typeName = typeName; hdr.typeName = typeName;
if (auto r = ox::atoi(versionStr.c_str()); r.error == 0) { std::ignore = ox::atoi(versionStr).copyTo(hdr.typeVersion);
hdr.typeVersion = r.value; hdr.data = buffRaw;
}
hdr.data = buff;
hdr.dataSize = buffLen; hdr.dataSize = buffLen;
return hdr; return hdr;
} }
Result<ClawHeader> readClawHeader(const ox::Buffer &buff) noexcept { Result<BufferView> stripClawHeader(ox::BufferView buff) noexcept {
return readClawHeader(buff.data(), buff.size()); oxRequire(header, readClawHeader(buff));
return {{header.data, header.dataSize}};
} }
Result<Buffer> stripClawHeader(const char *buff, std::size_t buffLen) noexcept { Result<ModelObject> readClaw(TypeStore &ts, BufferView buff) noexcept {
oxRequire(header, readClawHeader(buff, buffLen)); oxRequire(header, readClawHeader(buff));
Buffer out(header.dataSize); auto const [t, tdErr] = ts.getLoad(
ox::listcpy(out.data(), header.data, out.size()); header.typeName, header.typeVersion, header.typeParams);
return out;
}
Result<Buffer> stripClawHeader(const ox::Buffer &buff) noexcept {
return stripClawHeader(buff.data(), buff.size());
}
Result<ModelObject> readClaw(TypeStore &ts, const char *buff, std::size_t buffSz) noexcept {
oxRequire(header, readClawHeader(buff, buffSz));
auto const [t, tdErr] = ts.getLoad(header.typeName, header.typeVersion, header.typeParams);
if (tdErr) { if (tdErr) {
return OxError(3, "Could not load type descriptor"); return OxError(3, "Could not load type descriptor");
} }
@ -83,7 +104,7 @@ Result<ModelObject> readClaw(TypeStore &ts, const char *buff, std::size_t buffSz
switch (header.fmt) { switch (header.fmt) {
case ClawFormat::Metal: case ClawFormat::Metal:
{ {
ox::BufferReader br(header.data, header.dataSize); ox::BufferReader br({header.data, header.dataSize});
MetalClawReader reader(br); MetalClawReader reader(br);
ModelHandlerInterface handler(&reader); ModelHandlerInterface handler(&reader);
oxReturnError(model(&handler, &obj)); oxReturnError(model(&handler, &obj));
@ -92,7 +113,7 @@ Result<ModelObject> readClaw(TypeStore &ts, const char *buff, std::size_t buffSz
case ClawFormat::Organic: case ClawFormat::Organic:
{ {
#ifdef OX_USE_STDLIB #ifdef OX_USE_STDLIB
OrganicClawReader reader(header.data, header.dataSize); OrganicClawReader reader({header.data, header.dataSize});
ModelHandlerInterface handler(&reader); ModelHandlerInterface handler(&reader);
oxReturnError(model(&handler, &obj)); oxReturnError(model(&handler, &obj));
return obj; return obj;
@ -106,8 +127,4 @@ Result<ModelObject> readClaw(TypeStore &ts, const char *buff, std::size_t buffSz
return OxError(1); return OxError(1);
} }
Result<ModelObject> readClaw(TypeStore &ts, const Buffer &buff) noexcept {
return readClaw(ts, buff.data(), buff.size());
}
} }

View File

@ -8,6 +8,7 @@
#pragma once #pragma once
#include <ox/std/span.hpp>
#include <ox/mc/read.hpp> #include <ox/mc/read.hpp>
#ifdef OX_USE_STDLIB #ifdef OX_USE_STDLIB
#include <ox/oc/read.hpp> #include <ox/oc/read.hpp>
@ -31,17 +32,15 @@ struct ClawHeader {
std::size_t dataSize = 0; std::size_t dataSize = 0;
}; };
Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcept; ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept;
Result<ClawHeader> readClawHeader(const ox::Buffer &buff) noexcept; Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept;
Result<Buffer> stripClawHeader(const char *buff, std::size_t buffLen) noexcept; Result<BufferView> stripClawHeader(ox::BufferView buff) noexcept;
Result<Buffer> stripClawHeader(const ox::Buffer &buff) noexcept;
template<typename T> template<typename T>
Error readClaw(const char *buff, std::size_t buffLen, T *val) { Error readClaw(ox::BufferView buff, T &val) {
oxRequire(header, readClawHeader(buff, buffLen)); oxRequire(header, readClawHeader(buff));
if (header.typeName != getModelTypeName<T>()) { if (header.typeName != getModelTypeName<T>()) {
return OxError(Error_ClawTypeMismatch, "Claw Read: Type mismatch"); return OxError(Error_ClawTypeMismatch, "Claw Read: Type mismatch");
} }
@ -51,16 +50,16 @@ Error readClaw(const char *buff, std::size_t buffLen, T *val) {
switch (header.fmt) { switch (header.fmt) {
case ClawFormat::Metal: case ClawFormat::Metal:
{ {
ox::BufferReader br(header.data, header.dataSize); ox::BufferReader br({header.data, header.dataSize});
MetalClawReader reader(br); MetalClawReader reader(br);
ModelHandlerInterface handler(&reader); ModelHandlerInterface handler(&reader);
return model(&handler, val); return model(&handler, &val);
} }
case ClawFormat::Organic: case ClawFormat::Organic:
{ {
#ifdef OX_USE_STDLIB #ifdef OX_USE_STDLIB
OrganicClawReader reader(header.data, header.dataSize); OrganicClawReader reader(header.data, header.dataSize);
return model(&reader, val); return model(&reader, &val);
#else #else
break; break;
#endif #endif
@ -72,24 +71,12 @@ Error readClaw(const char *buff, std::size_t buffLen, T *val) {
} }
template<typename T> template<typename T>
Result<T> readClaw(const char *buff, std::size_t buffLen) { Result<T> readClaw(ox::BufferView buff) {
T val; Result<T> val;
oxReturnError(readClaw(buff, buffLen, &val)); oxReturnError(readClaw(buff, val.value));
return val; return val;
} }
template<typename T> Result<ModelObject> readClaw(TypeStore &ts, BufferView buff) noexcept;
Error readClaw(const Buffer &buff, T *val) {
return readClaw<T>(buff.data(), buff.size(), val);
}
template<typename T>
Result<T> readClaw(const Buffer &buff) {
return readClaw<T>(buff.data(), buff.size());
}
Result<ModelObject> readClaw(TypeStore &ts, const char *buff, std::size_t buffSz) noexcept;
Result<ModelObject> readClaw(TypeStore &ts, const Buffer &buff) noexcept;
} }

View File

@ -10,5 +10,6 @@ target_link_libraries(
add_test("[ox/claw] ClawHeaderReader" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawHeaderReader) add_test("[ox/claw] ClawHeaderReader" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawHeaderReader)
add_test("[ox/claw] ClawHeaderReader2" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawHeaderReader2) add_test("[ox/claw] ClawHeaderReader2" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawHeaderReader2)
add_test("[ox/claw] ClawHeaderReadTypeId" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawHeaderReadTypeId)
add_test("[ox/claw] ClawWriter" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawWriter) add_test("[ox/claw] ClawWriter" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawWriter)
add_test("[ox/claw] ClawReader" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawReader) add_test("[ox/claw] ClawReader" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ClawTest ClawReader)

View File

@ -109,7 +109,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
"ClawHeaderReader", "ClawHeaderReader",
[] { [] {
constexpr auto hdr = ox::StringLiteral("O1;com.drinkingtea.ox.claw.test.Header;2;"); constexpr auto hdr = ox::StringLiteral("O1;com.drinkingtea.ox.claw.test.Header;2;");
auto [ch, err] = ox::readClawHeader(hdr.c_str(), hdr.len() + 1); auto [ch, err] = ox::readClawHeader({hdr.c_str(), hdr.len() + 1});
oxAssert(err, "Error parsing header"); oxAssert(err, "Error parsing header");
oxAssert(ch.fmt == ox::ClawFormat::Organic, "Format wrong"); oxAssert(ch.fmt == ox::ClawFormat::Organic, "Format wrong");
oxAssert(ch.typeName == "com.drinkingtea.ox.claw.test.Header", "Type name wrong"); oxAssert(ch.typeName == "com.drinkingtea.ox.claw.test.Header", "Type name wrong");
@ -121,7 +121,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
"ClawHeaderReader2", "ClawHeaderReader2",
[] { [] {
constexpr auto hdr = ox::StringLiteral("M2;com.drinkingtea.ox.claw.test.Header2;3;"); constexpr auto hdr = ox::StringLiteral("M2;com.drinkingtea.ox.claw.test.Header2;3;");
auto [ch, err] = ox::readClawHeader(hdr.c_str(), hdr.len() + 1); auto [ch, err] = ox::readClawHeader({hdr.c_str(), hdr.len() + 1});
oxAssert(err, "Error parsing header"); oxAssert(err, "Error parsing header");
oxAssert(ch.fmt == ox::ClawFormat::Metal, "Format wrong"); oxAssert(ch.fmt == ox::ClawFormat::Metal, "Format wrong");
oxAssert(ch.typeName == "com.drinkingtea.ox.claw.test.Header2", "Type name wrong"); oxAssert(ch.typeName == "com.drinkingtea.ox.claw.test.Header2", "Type name wrong");
@ -129,6 +129,16 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
return OxError(0); return OxError(0);
} }
}, },
{
"ClawHeaderReadTypeId",
[] {
constexpr auto hdr = ox::StringLiteral("M2;com.drinkingtea.ox.claw.test.Header2;3;awefawf");
constexpr auto expected = ox::StringLiteral("com.drinkingtea.ox.claw.test.Header2;3");
oxRequire(actual, ox::readClawTypeId({hdr.data(), hdr.len() + 1}));
oxExpect(actual, expected);
return ox::Error{};
}
},
{ {
"ClawWriter", "ClawWriter",
[] { [] {
@ -156,7 +166,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
testIn.Struct.String = "Test String 2"; testIn.Struct.String = "Test String 2";
const auto [buff, err] = ox::writeMC(testIn); const auto [buff, err] = ox::writeMC(testIn);
oxAssert(err, "writeClaw failed"); oxAssert(err, "writeClaw failed");
oxAssert(ox::readMC(buff.data(), buff.size(), &testOut), "readClaw failed"); oxAssert(ox::readMC(buff, testOut), "readClaw failed");
//std::cout << testIn.Union.Int << "|" << testOut.Union.Int << "|\n"; //std::cout << testIn.Union.Int << "|" << testOut.Union.Int << "|\n";
oxAssert(testIn.Bool == testOut.Bool, "Bool value mismatch"); oxAssert(testIn.Bool == testOut.Bool, "Bool value mismatch");
oxAssert(testIn.Int == testOut.Int, "Int value mismatch"); oxAssert(testIn.Int == testOut.Int, "Int value mismatch");

View File

@ -185,7 +185,7 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
template<typename I> template<typename I>
Result<I> decodeInteger(McInt m) noexcept { Result<I> decodeInteger(McInt m) noexcept {
std::size_t bytesRead{}; std::size_t bytesRead{};
BufferReader br(reinterpret_cast<const char*>(m.data), 9); BufferReader br({reinterpret_cast<const char*>(m.data), 9});
return decodeInteger<I>(br, &bytesRead); return decodeInteger<I>(br, &bytesRead);
} }

View File

@ -524,25 +524,20 @@ constexpr void MetalClawReaderTemplate<Reader>::nextField() noexcept {
using MetalClawReader = MetalClawReaderTemplate<ox::BufferReader>; using MetalClawReader = MetalClawReaderTemplate<ox::BufferReader>;
template<typename T> template<typename T>
Error readMC(const char *buff, std::size_t buffLen, T *val) noexcept { Error readMC(ox::BufferView buff, T &val) noexcept {
BufferReader br(buff, buffLen); BufferReader br(buff);
MetalClawReader reader(br); MetalClawReader reader(br);
ModelHandlerInterface<MetalClawReader, ox::OpType::Read> handler(&reader); ModelHandlerInterface<MetalClawReader, ox::OpType::Read> handler(&reader);
return model(&handler, val); return model(&handler, &val);
} }
template<typename T> template<typename T>
Result<T> readMC(const char *buff, std::size_t buffLen) noexcept { Result<T> readMC(ox::BufferView buff) noexcept {
T val; Result<T> val;
oxReturnError(readMC(buff, buffLen, &val)); oxReturnError(readMC(buff, val.value));
return val; return val;
} }
template<typename T>
Result<T> readMC(const Buffer &buff) noexcept {
return readMC<T>(buff.data(), buff.size());
}
extern template class ModelHandlerInterface<MetalClawReaderTemplate<BufferReader>>; extern template class ModelHandlerInterface<MetalClawReaderTemplate<BufferReader>>;
} }

View File

@ -143,7 +143,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
// run tests // run tests
const auto [buff, err] = ox::writeMC(testIn); const auto [buff, err] = ox::writeMC(testIn);
oxAssert(err, "writeMC failed"); oxAssert(err, "writeMC failed");
oxAssert(ox::readMC(buff.data(), buff.size(), &testOut), "readMC failed"); oxAssert(ox::readMC(buff, testOut), "readMC failed");
//std::cout << testIn.Union.Int << "|" << testOut.Union.Int << "|\n"; //std::cout << testIn.Union.Int << "|" << testOut.Union.Int << "|\n";
oxAssert(testIn.Bool == testOut.Bool, "Bool value mismatch"); oxAssert(testIn.Bool == testOut.Bool, "Bool value mismatch");
oxAssert(testIn.Int == testOut.Int, "Int value mismatch"); oxAssert(testIn.Int == testOut.Int, "Int value mismatch");
@ -319,7 +319,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(typeErr, "Descriptor write failed"); oxAssert(typeErr, "Descriptor write failed");
ox::ModelObject testOut; ox::ModelObject testOut;
oxReturnError(testOut.setType(type)); oxReturnError(testOut.setType(type));
oxAssert(ox::readMC(dataBuff.data(), dataBuff.size(), &testOut), "Data read failed"); oxAssert(ox::readMC(dataBuff, testOut), "Data read failed");
oxAssert(testOut.at("Int").unwrap()->get<int>() == testIn.Int, "testOut.Int failed"); oxAssert(testOut.at("Int").unwrap()->get<int>() == testIn.Int, "testOut.Int failed");
oxAssert(testOut.at("Bool").unwrap()->get<bool>() == testIn.Bool, "testOut.Bool failed"); oxAssert(testOut.at("Bool").unwrap()->get<bool>() == testIn.Bool, "testOut.Bool failed");
oxAssert(testOut.at("IString").unwrap()->get<ox::String>() == testIn.IString.c_str(), "testOut.String failed"); oxAssert(testOut.at("IString").unwrap()->get<ox::String>() == testIn.IString.c_str(), "testOut.String failed");
@ -369,7 +369,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
ox::TypeStore typeStore; ox::TypeStore typeStore;
const auto [type, typeErr] = ox::buildTypeDef(&typeStore, &testIn); const auto [type, typeErr] = ox::buildTypeDef(&typeStore, &testIn);
oxAssert(typeErr, "Descriptor write failed"); oxAssert(typeErr, "Descriptor write failed");
ox::BufferReader br(dataBuff, dataBuffLen); ox::BufferReader br({dataBuff, dataBuffLen});
oxReturnError(ox::walkModel<ox::MetalClawReader>(type, br, oxReturnError(ox::walkModel<ox::MetalClawReader>(type, br,
[](const ox::Vector<ox::FieldName>&, const ox::Vector<ox::String>&, const ox::DescriptorField &f, ox::MetalClawReader *rdr) -> ox::Error { [](const ox::Vector<ox::FieldName>&, const ox::Vector<ox::String>&, const ox::DescriptorField &f, ox::MetalClawReader *rdr) -> ox::Error {
//std::cout << f.fieldName.c_str() << '\n'; //std::cout << f.fieldName.c_str() << '\n';

View File

@ -37,12 +37,12 @@ constexpr auto buildTypeId() noexcept {
static constexpr auto buildTypeId(CRStringView name, int version, static constexpr auto buildTypeId(CRStringView name, int version,
const TypeParamPack &typeParams = {}) noexcept { const TypeParamPack &typeParams = {}) noexcept {
String tp; String tp;
if (typeParams.size()) { if (!typeParams.empty()) {
tp = "#"; tp = "#";
for (const auto &p : typeParams) { for (const auto &p : typeParams) {
tp += p + ","; tp += p + ",";
} }
tp = tp.substr(0, tp.len() - 1); tp.resize(tp.len() - 1);
tp += "#"; tp += "#";
} }
return ox::sfmt("{}{};{}", name, tp, version); return ox::sfmt("{}{};{}", name, tp, version);

View File

@ -97,6 +97,7 @@ struct TypeInfoCatcher {
}; };
template<typename T> template<typename T>
[[nodiscard]]
constexpr int getModelTypeVersion(T *val) noexcept { constexpr int getModelTypeVersion(T *val) noexcept {
TypeInfoCatcher nc; TypeInfoCatcher nc;
std::ignore = model(&nc, val); std::ignore = model(&nc, val);
@ -104,6 +105,7 @@ constexpr int getModelTypeVersion(T *val) noexcept {
} }
template<typename T> template<typename T>
[[nodiscard]]
constexpr int getModelTypeVersion() noexcept { constexpr int getModelTypeVersion() noexcept {
std::allocator<T> a; std::allocator<T> a;
const auto t = a.allocate(1); const auto t = a.allocate(1);
@ -113,6 +115,7 @@ constexpr int getModelTypeVersion() noexcept {
} }
template<typename T> template<typename T>
[[nodiscard]]
consteval int requireModelTypeVersion() noexcept { consteval int requireModelTypeVersion() noexcept {
constexpr auto version = getModelTypeVersion<T>(); constexpr auto version = getModelTypeVersion<T>();
static_assert(version != 0, "TypeVersion is required"); static_assert(version != 0, "TypeVersion is required");
@ -120,6 +123,7 @@ consteval int requireModelTypeVersion() noexcept {
} }
template<typename T, typename Str = const char*> template<typename T, typename Str = const char*>
[[nodiscard]]
constexpr Str getModelTypeName(T *val) noexcept { constexpr Str getModelTypeName(T *val) noexcept {
TypeNameCatcher nc; TypeNameCatcher nc;
std::ignore = model(&nc, val); std::ignore = model(&nc, val);
@ -127,6 +131,7 @@ constexpr Str getModelTypeName(T *val) noexcept {
} }
template<typename T, typename Str = const char*> template<typename T, typename Str = const char*>
[[nodiscard]]
constexpr Str getModelTypeName() noexcept { constexpr Str getModelTypeName() noexcept {
std::allocator<T> a; std::allocator<T> a;
auto t = a.allocate(1); auto t = a.allocate(1);
@ -136,8 +141,10 @@ constexpr Str getModelTypeName() noexcept {
} }
template<typename T> template<typename T>
[[nodiscard]]
consteval auto requireModelTypeName() noexcept { consteval auto requireModelTypeName() noexcept {
constexpr auto name = getModelTypeName<T>(); constexpr auto name = getModelTypeName<T>();
static_assert(ox::StringView{name}.len(), "Type lacks required TypeName");
return name; return name;
} }

View File

@ -101,7 +101,7 @@ class TypeStore {
} }
protected: protected:
virtual Result<UniquePtr<DescriptorType>> loadDescriptor(ox::CRStringView) noexcept { virtual Result<UniquePtr<DescriptorType>> loadDescriptor(ox::StringView) noexcept {
return OxError(1); return OxError(1);
} }

View File

@ -246,18 +246,18 @@ Error OrganicClawReader::field(const char *key, HashMap<String, T> *val) noexcep
return OxError(0); return OxError(0);
} }
Error readOC(const char *buff, std::size_t buffSize, auto *val) noexcept { Error readOC(BufferView buff, auto &val) noexcept {
// OrganicClawReader constructor can throw, but readOC should return its errors. // OrganicClawReader constructor can throw, but readOC should return its errors.
try { try {
Json::Value doc; Json::Value doc;
Json::CharReaderBuilder parserBuilder; Json::CharReaderBuilder parserBuilder;
auto parser = UniquePtr<Json::CharReader>(parserBuilder.newCharReader()); auto parser = UniquePtr<Json::CharReader>(parserBuilder.newCharReader());
if (!parser->parse(buff, buff + buffSize, &doc, nullptr)) { if (!parser->parse(buff.data(), buff.data() + buff.size(), &doc, nullptr)) {
return OxError(1, "Could not parse JSON"); return OxError(1, "Could not parse JSON");
} }
OrganicClawReader reader(buff, buffSize); OrganicClawReader reader(buff.data(), buff.size());
ModelHandlerInterface handler(&reader); ModelHandlerInterface handler(&reader);
return model(&handler, val); return model(&handler, &val);
} catch (const Error &err) { } catch (const Error &err) {
return err; return err;
} catch (...) { } catch (...) {
@ -266,20 +266,15 @@ Error readOC(const char *buff, std::size_t buffSize, auto *val) noexcept {
} }
template<typename T> template<typename T>
Result<T> readOC(const char *json, std::size_t jsonLen) noexcept { Result<T> readOC(BufferView buff) noexcept {
T val; Result<T> val;
oxReturnError(readOC(json, jsonLen, &val)); oxReturnError(readOC(buff, val.value));
return val; return val;
} }
template<typename T> template<typename T>
Result<T> readOC(const char *json) noexcept { Result<T> readOC(ox::StringView json) noexcept {
return readOC<T>(json, ox::strlen(json)); return readOC<T>(ox::BufferView{json.data(), json.len()});
}
template<typename T>
Result<T> readOC(const Buffer &buff) noexcept {
return readOC<T>(buff.data(), buff.size());
} }
} }

View File

@ -211,7 +211,7 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(type.error, "Descriptor write failed"); oxAssert(type.error, "Descriptor write failed");
ox::ModelObject testOut; ox::ModelObject testOut;
oxReturnError(testOut.setType(type.value)); oxReturnError(testOut.setType(type.value));
oxAssert(ox::readOC(dataBuff.data(), dataBuff.size(), &testOut), "Data read failed"); oxAssert(ox::readOC(dataBuff, testOut), "Data read failed");
oxAssert(testOut.get("Int").unwrap()->get<int>() == testIn.Int, "testOut.Int failed"); oxAssert(testOut.get("Int").unwrap()->get<int>() == testIn.Int, "testOut.Int failed");
oxAssert(testOut.get("Bool").unwrap()->get<bool>() == testIn.Bool, "testOut.Bool failed"); oxAssert(testOut.get("Bool").unwrap()->get<bool>() == testIn.Bool, "testOut.Bool failed");
oxAssert(testOut.get("String").unwrap()->get<ox::String>() == testIn.String, "testOut.String failed"); oxAssert(testOut.get("String").unwrap()->get<ox::String>() == testIn.String, "testOut.String failed");

View File

@ -117,6 +117,7 @@ install(
ranges.hpp ranges.hpp
serialize.hpp serialize.hpp
size.hpp size.hpp
smallmap.hpp
stacktrace.hpp stacktrace.hpp
std.hpp std.hpp
stddef.hpp stddef.hpp

View File

@ -10,6 +10,7 @@
#include "error.hpp" #include "error.hpp"
#include "reader.hpp" #include "reader.hpp"
#include "span.hpp"
#include "vector.hpp" #include "vector.hpp"
#include "writer.hpp" #include "writer.hpp"
@ -18,6 +19,7 @@ namespace ox {
extern template class Vector<char>; extern template class Vector<char>;
using Buffer = Vector<char>; using Buffer = Vector<char>;
using BufferView = SpanView<char>;
class BufferWriter { class BufferWriter {
private: private:
@ -174,10 +176,7 @@ class BufferReader {
char const* m_buff = nullptr; char const* m_buff = nullptr;
public: public:
constexpr explicit BufferReader(char const*buff, std::size_t sz) noexcept: constexpr explicit BufferReader(ox::BufferView buffer) noexcept:
m_size(sz), m_buff(buff) {}
constexpr explicit BufferReader(ox::Buffer const&buffer) noexcept:
m_size(buffer.size()), m_buff(buffer.data()) {} m_size(buffer.size()), m_buff(buffer.data()) {}
constexpr ox::Result<char> peek() const noexcept { constexpr ox::Result<char> peek() const noexcept {

View File

@ -234,6 +234,22 @@ struct [[nodiscard]] Result {
return value; return value;
} }
template<typename U = T>
constexpr ox::Result<U> to() & noexcept {
if (error) [[unlikely]] {
return error;
}
return U(value);
}
template<typename U = T>
constexpr ox::Result<U> to() && noexcept {
if (error) [[unlikely]] {
return error;
}
return U(std::move(value));
}
template<typename U = T> template<typename U = T>
constexpr ox::Result<U> to(auto const&f) & noexcept { constexpr ox::Result<U> to(auto const&f) & noexcept {
if (error) [[unlikely]] { if (error) [[unlikely]] {

View File

@ -40,12 +40,17 @@ constexpr StringView toStringView(const char *s) noexcept {
template<bool force = false, std::size_t size> template<bool force = false, std::size_t size>
constexpr StringView toStringView(const IString<size> &s) noexcept { constexpr StringView toStringView(const IString<size> &s) noexcept {
return s.c_str(); return s;
}
template<bool force = false>
constexpr StringView toStringView(ox::StringLiteral s) noexcept {
return s;
} }
template<bool force = false, std::size_t size> template<bool force = false, std::size_t size>
constexpr StringView toStringView(const BasicString<size> &s) noexcept { constexpr StringView toStringView(const BasicString<size> &s) noexcept {
return s.c_str(); return s;
} }
#if __has_include(<string>) #if __has_include(<string>)

238
deps/ox/src/ox/std/smallmap.hpp vendored Normal file
View File

@ -0,0 +1,238 @@
/*
* Copyright 2015 - 2024 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 "algorithm.hpp"
#include "hash.hpp"
#include "ignore.hpp"
#include "stringview.hpp"
#include "strops.hpp"
#include "vector.hpp"
namespace ox {
template<typename K, typename T>
class SmallMap {
public:
using key_t = K;
using value_t = T;
private:
struct Pair {
K key = {};
T value{};
};
Vector<K> m_keys;
Vector<Pair> m_pairs;
public:
explicit constexpr SmallMap(std::size_t size = 127);
constexpr SmallMap(SmallMap const&other);
constexpr SmallMap(SmallMap &&other) noexcept;
constexpr ~SmallMap();
constexpr bool operator==(SmallMap const&other) const;
constexpr SmallMap &operator=(SmallMap const&other);
constexpr SmallMap &operator=(SmallMap &&other) noexcept;
constexpr T &operator[](MaybeView_t<K> const&key);
constexpr Result<T*> at(MaybeView_t<K> const&key) noexcept;
constexpr Result<const T*> at(MaybeView_t<K> const&key) const noexcept;
constexpr void erase(MaybeView_t<K> const&key);
[[nodiscard]]
constexpr bool contains(MaybeView_t<K> const&key) const noexcept;
[[nodiscard]]
constexpr std::size_t size() const noexcept;
[[nodiscard]]
constexpr Vector<K> const&keys() const noexcept;
constexpr void clear();
private:
constexpr void expand();
template<typename KK>
constexpr Pair *const&access(Vector<Pair> const&pairs, KK const&key) const;
template<typename KK>
constexpr Pair *&access(Vector<Pair> &pairs, KK const&key);
};
template<typename K, typename T>
constexpr SmallMap<K, T>::SmallMap(std::size_t size): m_pairs(size) {
}
template<typename K, typename T>
constexpr SmallMap<K, T>::SmallMap(SmallMap<K, T> const&other) {
m_pairs = other.m_pairs;
}
template<typename K, typename T>
constexpr SmallMap<K, T>::SmallMap(SmallMap<K, T> &&other) noexcept {
m_keys = std::move(other.m_keys);
m_pairs = std::move(other.m_pairs);
}
template<typename K, typename T>
constexpr SmallMap<K, T>::~SmallMap() {
clear();
}
template<typename K, typename T>
constexpr bool SmallMap<K, T>::operator==(SmallMap const&other) const {
if (m_keys != other.m_keys) {
return false;
}
for (int i = 0; i < m_keys.size(); ++i) {
auto &k = m_keys[i];
if (at(k) != other.at(k)) {
return false;
}
}
return true;
}
template<typename K, typename T>
constexpr SmallMap<K, T> &SmallMap<K, T>::operator=(SmallMap<K, T> const&other) {
if (this != &other) {
clear();
m_keys = other.m_keys;
m_pairs = other.m_pairs;
}
return *this;
}
template<typename K, typename T>
constexpr SmallMap<K, T> &SmallMap<K, T>::operator=(SmallMap<K, T> &&other) noexcept {
if (this != &other) {
clear();
m_keys = std::move(other.m_keys);
m_pairs = std::move(other.m_pairs);
}
return *this;
}
template<typename K, typename T>
constexpr T &SmallMap<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 <
static_cast<double>(m_keys.size())) {
expand();
}
p = new Pair;
p->key = k;
m_keys.emplace_back(k);
}
return p->value;
}
template<typename K, typename T>
constexpr Result<T*> SmallMap<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")};
}
return &p->value;
}
template<typename K, typename T>
constexpr Result<const T*> SmallMap<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")};
}
return &p->value;
}
template<typename K, typename T>
constexpr void SmallMap<K, T>::erase(MaybeView_t<K> const&k) {
size_t i{};
for (auto const&p : m_pairs) {
if (k == p.key) {
break;
}
++i;
}
std::ignore = m_pairs.erase(i);
std::ignore = m_keys.erase(i);
}
template<typename K, typename T>
constexpr bool SmallMap<K, T>::contains(MaybeView_t<K> const&k) const noexcept {
return access(m_pairs, k) != nullptr;
}
template<typename K, typename T>
constexpr std::size_t SmallMap<K, T>::size() const noexcept {
return m_keys.size();
}
template<typename K, typename T>
constexpr Vector<K> const&SmallMap<K, T>::keys() const noexcept {
return m_keys;
}
template<typename K, typename T>
constexpr void SmallMap<K, T>::clear() {
for (std::size_t i = 0; i < m_pairs.size(); i++) {
delete m_pairs[i];
}
m_pairs.clear();
m_pairs.resize(127);
}
template<typename K, typename T>
constexpr void SmallMap<K, T>::expand() {
Vector<Pair*> r;
for (std::size_t i = 0; i < m_keys.size(); ++i) {
auto const&k = m_keys[i];
access(r, k) = std::move(access(m_pairs, k));
}
m_pairs = std::move(r);
}
template<typename K, typename T>
template<typename KK>
constexpr typename SmallMap<K, T>::Pair *const&SmallMap<K, T>::access(
Vector<Pair> const&pairs, KK const&k) const {
for (auto const&p : pairs) {
if (p.key == k) {
return &p;
}
}
return nullptr;
}
template<typename K, typename T>
template<typename KK>
constexpr typename SmallMap<K, T>::Pair *&SmallMap<K, T>::access(
Vector<Pair> &pairs, KK const&k) {
for (auto &p : pairs) {
if (p.key == k) {
return &p;
}
}
return nullptr;
}
}

View File

@ -19,8 +19,8 @@ template<typename T>
class SpanView { class SpanView {
private: private:
const T *m_items{}; T const*m_items{};
const std::size_t m_size{}; std::size_t m_size{};
public: public:
using value_type = T; using value_type = T;
@ -106,6 +106,16 @@ class SpanView {
return m_items[i]; return m_items[i];
} }
constexpr SpanView operator+(size_t i) const noexcept {
return {m_items + i, m_size - i};
}
constexpr SpanView operator+=(size_t i) noexcept {
m_items += i;
m_size -= i;
return *this;
}
[[nodiscard]] [[nodiscard]]
constexpr T const*data() const noexcept { constexpr T const*data() const noexcept {
return m_items; return m_items;

View File

@ -39,6 +39,7 @@
#include "realstd.hpp" #include "realstd.hpp"
#include "serialize.hpp" #include "serialize.hpp"
#include "size.hpp" #include "size.hpp"
#include "smallmap.hpp"
#include "stacktrace.hpp" #include "stacktrace.hpp"
#include "stddef.hpp" #include "stddef.hpp"
#include "string.hpp" #include "string.hpp"

View File

@ -1,7 +1,9 @@
#pragma once #pragma once
#include "bit.hpp"
#include "error.hpp" #include "error.hpp"
#include "math.hpp"
#include "types.hpp" #include "types.hpp"
#include "writer.hpp" #include "writer.hpp"

View File

@ -192,6 +192,10 @@ class BasicString {
[[nodiscard]] [[nodiscard]]
constexpr BasicString substr(std::size_t begin, std::size_t end) const noexcept; constexpr BasicString substr(std::size_t begin, std::size_t end) const noexcept;
constexpr void resize(size_t sz) noexcept {
m_buff.resize(sz);
}
[[nodiscard]] [[nodiscard]]
constexpr const char *data() const noexcept { constexpr const char *data() const noexcept {
return m_buff.data(); return m_buff.data();

View File

@ -109,7 +109,9 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
oxAssert(ox::StringView("Write") != ox::String(""), "String / StringView comparison broken"); oxAssert(ox::StringView("Write") != ox::String(""), "String / StringView comparison broken");
oxAssert(ox::String("Write") != ox::StringView(""), "String / StringView comparison broken"); oxAssert(ox::String("Write") != ox::StringView(""), "String / StringView comparison broken");
oxAssert(ox::String("Write") == ox::StringView("Write"), "String / StringView comparison broken"); oxAssert(ox::String("Write") == ox::StringView("Write"), "String / StringView comparison broken");
oxAssert(ox::String(ox::StringView("Write")) == ox::StringView("Write"), "String / StringView comparison broken"); oxAssert(
ox::String(ox::StringView("Write")) == ox::StringView("Write"),
"String / StringView comparison broken");
return OxError(0); return OxError(0);
} }
}, },
@ -119,7 +121,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
ox::Vector<int> v; ox::Vector<int> v;
oxAssert(v.size() == 0, "Initial Vector size not 0"); oxAssert(v.size() == 0, "Initial Vector size not 0");
oxAssert(v.empty(), "Vector::empty() is broken"); oxAssert(v.empty(), "Vector::empty() is broken");
auto insertTest = [&v](int val, [[maybe_unused]] std::size_t size) { auto insertTest = [&v](int val, std::size_t size) {
v.push_back(val); v.push_back(val);
oxReturnError(OxError(v.size() != size, "Vector size incorrect")); oxReturnError(OxError(v.size() != size, "Vector size incorrect"));
oxReturnError(OxError(v[v.size() - 1] != val, "Vector value wrong")); oxReturnError(OxError(v[v.size() - 1] != val, "Vector value wrong"));
@ -152,7 +154,11 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
[] { [] {
using BA = ox::Array<char, 4>; using BA = ox::Array<char, 4>;
const auto actual = ox::serialize<uint32_t>(256).unwrap(); const auto actual = ox::serialize<uint32_t>(256).unwrap();
oxOutf("[{}, {}, {}, {}]", static_cast<int>(actual[0]), static_cast<int>(actual[1]), static_cast<int>(actual[2]), static_cast<int>(actual[3])); oxOutf("[{}, {}, {}, {}]",
static_cast<int>(actual[0]),
static_cast<int>(actual[1]),
static_cast<int>(actual[2]),
static_cast<int>(actual[3]));
oxExpect(ox::serialize<int32_t>(4).unwrap(), BA({4, 0, 0, 0})); oxExpect(ox::serialize<int32_t>(4).unwrap(), BA({4, 0, 0, 0}));
oxExpect(ox::serialize<int32_t>(256).unwrap(), BA({0, 1, 0, 0})); oxExpect(ox::serialize<int32_t>(256).unwrap(), BA({0, 1, 0, 0}));
oxExpect(ox::serialize<int32_t>(257).unwrap(), BA({1, 1, 0, 0})); oxExpect(ox::serialize<int32_t>(257).unwrap(), BA({1, 1, 0, 0}));

View File

@ -196,7 +196,7 @@ static ox::Error loadTileSheetSet(
.targetBpp = static_cast<unsigned>(set.bpp), .targetBpp = static_cast<unsigned>(set.bpp),
.setEntry = &entry, .setEntry = &entry,
}; };
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target)); oxReturnError(ox::readMC({ts, static_cast<std::size_t>(tsStat.size)}, target));
tileWriteIdx += target.tileWriteIdx; tileWriteIdx += target.tileWriteIdx;
} }
return {}; return {};
@ -215,7 +215,7 @@ ox::Error loadBgTileSheet(
.defaultPalette = {}, .defaultPalette = {},
.tileMap = MEM_BG_TILES[cbb].data(), .tileMap = MEM_BG_TILES[cbb].data(),
}; };
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target)); oxReturnError(ox::readMC({ts, static_cast<std::size_t>(tsStat.size)}, target));
// update bpp of all bgs with the updated cbb // update bpp of all bgs with the updated cbb
const auto bpp = ctx.cbbData[cbb].bpp; const auto bpp = ctx.cbbData[cbb].bpp;
teagba::iterateBgCtl([bpp, cbb](volatile BgCtl &bgCtl) { teagba::iterateBgCtl([bpp, cbb](volatile BgCtl &bgCtl) {
@ -267,7 +267,7 @@ ox::Error loadSpriteTileSheet(
.defaultPalette = {}, .defaultPalette = {},
.tileMap = MEM_SPRITE_TILES, .tileMap = MEM_SPRITE_TILES,
}; };
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target)); oxReturnError(ox::readMC({ts, static_cast<std::size_t>(tsStat.size)}, target));
if (loadDefaultPalette && target.defaultPalette) { if (loadDefaultPalette && target.defaultPalette) {
oxReturnError(loadSpritePalette(ctx, target.defaultPalette)); oxReturnError(loadSpritePalette(ctx, target.defaultPalette));
} }

View File

@ -58,27 +58,21 @@ static class: public keel::Module {
ox::Vector<keel::PackTransform> packTransforms() const noexcept final { ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
return { return {
// convert tilesheets to CompactTileSheets // convert tilesheets to CompactTileSheets
[](keel::Context &ctx, ox::Buffer &buff) -> ox::Error { [](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Error {
oxRequire(hdr, keel::readAssetHeader(buff));
auto const typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::ModelTypeId_v<TileSheetV1> || if (typeId == ox::ModelTypeId_v<TileSheetV1> ||
typeId == ox::ModelTypeId_v<TileSheetV2> || typeId == ox::ModelTypeId_v<TileSheetV2> ||
typeId == ox::ModelTypeId_v<TileSheetV3> || typeId == ox::ModelTypeId_v<TileSheetV3> ||
typeId == ox::ModelTypeId_v<TileSheetV4>) { typeId == ox::ModelTypeId_v<TileSheetV4>) {
oxReturnError(keel::convertBuffToBuff<CompactTileSheet>( return keel::convertBuffToBuff<CompactTileSheet>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff)); ctx, buff, ox::ClawFormat::Metal).moveTo(buff);
} }
return {}; return {};
}, },
[](keel::Context &ctx, ox::Buffer &buff) -> ox::Error { [](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Error {
oxRequire(hdr, keel::readAssetHeader(buff));
auto const typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::ModelTypeId_v<NostalgiaPalette> || if (typeId == ox::ModelTypeId_v<NostalgiaPalette> ||
typeId == ox::ModelTypeId_v<PaletteV1>) { typeId == ox::ModelTypeId_v<PaletteV1>) {
oxReturnError(keel::convertBuffToBuff<Palette>( return keel::convertBuffToBuff<Palette>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff)); ctx, buff, ox::ClawFormat::Metal).moveTo(buff);
} }
return {}; return {};
}, },

View File

@ -11,9 +11,7 @@ namespace keel {
constexpr auto K1HdrSz = 40; constexpr auto K1HdrSz = 40;
ox::Result<ox::UUID> readUuidHeader(ox::Buffer const&buff) noexcept; ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept;
ox::Result<ox::UUID> readUuidHeader(const char *buff, std::size_t buffLen) noexcept;
ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexcept { ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexcept {
oxReturnError(write(writer, "K1;")); oxReturnError(write(writer, "K1;"));
@ -22,24 +20,24 @@ ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexce
} }
template<typename T> template<typename T>
ox::Result<T> readAsset(ox::Buffer const&buff) noexcept { ox::Result<T> readAsset(ox::BufferView buff) noexcept {
std::size_t offset = 0; std::size_t offset = 0;
const auto err = readUuidHeader(buff).error; const auto err = readUuidHeader(buff).error;
if (!err) { if (!err) {
offset = K1HdrSz; // the size of K1 headers offset = K1HdrSz; // the size of K1 headers
} }
return ox::readClaw<T>(buff.data() + offset, buff.size() - offset); return ox::readClaw<T>(buff + offset);
} }
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::Buffer const&buff) noexcept; ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept;
struct AssetHdr { struct AssetHdr {
ox::UUID uuid; ox::UUID uuid;
ox::ClawHeader clawHdr; ox::ClawHeader clawHdr;
}; };
ox::Result<AssetHdr> readAssetHeader(char const*buff, std::size_t buffLen) noexcept; ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept;
ox::Result<AssetHdr> readAssetHeader(ox::Buffer const&buff) noexcept; ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept;
} }

View File

@ -12,7 +12,7 @@
namespace keel { namespace keel {
class Context; class Context;
using PackTransform = ox::Error(*)(Context&, ox::Buffer &clawData); using PackTransform = ox::Error(*)(Context&, ox::Buffer &clawData, ox::StringView);
class Context { class Context {
public: public:
@ -36,4 +36,22 @@ class Context {
constexpr virtual ~Context() noexcept = default; constexpr virtual ~Context() noexcept = default;
}; };
constexpr ox::SpanView<PackTransform> packTransforms(
[[maybe_unused]] Context const&ctx) noexcept {
#ifndef OX_BARE_METAL
return ctx.packTransforms;
#else
return {};
#endif
}
constexpr ox::SpanView<class BaseConverter const*> converters(
[[maybe_unused]] Context const&ctx) noexcept {
#ifndef OX_BARE_METAL
return ctx.converters;
#else
return {};
#endif
}
} }

View File

@ -40,7 +40,7 @@ class WrapInline: public Wrap {
}; };
template<typename T, typename... Args> template<typename T, typename... Args>
constexpr auto makeWrap(Args &&...args) noexcept { constexpr ox::UPtr<Wrap> makeWrap(Args &&...args) noexcept {
return ox::make_unique<WrapInline<T>>(ox::forward<Args>(args)...); return ox::make_unique<WrapInline<T>>(ox::forward<Args>(args)...);
} }
@ -65,9 +65,10 @@ class BaseConverter {
[[nodiscard]] [[nodiscard]]
virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0; virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0;
virtual ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0; virtual ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0;
virtual ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept = 0; virtual ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept = 0;
[[nodiscard]] [[nodiscard]]
inline bool matches( inline bool matches(
@ -84,12 +85,12 @@ class Converter: public BaseConverter {
public: public:
[[nodiscard]] [[nodiscard]]
ox::StringView srcTypeName() const noexcept final { ox::StringView srcTypeName() const noexcept final {
return ox::requireModelTypeName<SrcType>(); return ox::ModelTypeName_v<SrcType>;
} }
[[nodiscard]] [[nodiscard]]
int srcTypeVersion() const noexcept final { int srcTypeVersion() const noexcept final {
return ox::requireModelTypeVersion<SrcType>(); return ox::ModelTypeVersion_v<SrcType>;
} }
[[nodiscard]] [[nodiscard]]
@ -108,17 +109,19 @@ class Converter: public BaseConverter {
&& dstTypeVersion == DstTypeVersion; && dstTypeVersion == DstTypeVersion;
} }
ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept final { ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(
keel::Context &ctx, Wrap &src) const noexcept final {
auto dst = makeWrap<DstType>(); auto dst = makeWrap<DstType>();
oxReturnError(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst))); oxReturnError(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst)));
return ox::Result<ox::UniquePtr<Wrap>>(std::move(dst)); return {std::move(dst)};
} }
ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept final { ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept final {
oxRequireM(src, readAsset<SrcType>(srcBuff)); oxRequireM(src, readAsset<SrcType>(srcBuff));
auto dst = makeWrap<DstType>(); auto dst = makeWrap<DstType>();
oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst))); oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst)));
return ox::Result<ox::UniquePtr<Wrap>>(std::move(dst)); return {std::move(dst)};
} }
protected: protected:
@ -126,9 +129,11 @@ class Converter: public BaseConverter {
}; };
ox::Result<ox::UniquePtr<Wrap>> convert( ox::Result<ox::UPtr<Wrap>> convert(
keel::Context &ctx, ox::Buffer const&srcBuffer, keel::Context &ctx,
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept; ox::Buffer const&srcBuffer,
ox::CRStringView dstTypeName,
int dstTypeVersion) noexcept;
template<typename DstType> template<typename DstType>
ox::Result<DstType> convert(keel::Context &ctx, ox::Buffer const&srcBuffer) noexcept { ox::Result<DstType> convert(keel::Context &ctx, ox::Buffer const&srcBuffer) noexcept {
@ -148,7 +153,8 @@ ox::Error convert(keel::Context &ctx, ox::Buffer const&buff, DstType *outObj) no
} }
template<typename DstType> template<typename DstType>
ox::Result<ox::Buffer> convertBuffToBuff(keel::Context &ctx, ox::Buffer const&srcBuffer, ox::ClawFormat fmt) noexcept { ox::Result<ox::Buffer> convertBuffToBuff(
keel::Context &ctx, ox::Buffer const&srcBuffer, ox::ClawFormat fmt) noexcept {
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>(); static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>(); static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
oxRequire(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion)); oxRequire(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
@ -156,10 +162,7 @@ ox::Result<ox::Buffer> convertBuffToBuff(keel::Context &ctx, ox::Buffer const&sr
} }
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal> template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
auto transformRule(keel::Context &ctx, ox::Buffer &buff) noexcept -> ox::Error { auto transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept -> ox::Error {
oxRequire(hdr, readAssetHeader(buff));
const auto typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::ModelTypeId_v<From>) { if (typeId == ox::ModelTypeId_v<From>) {
oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff)); oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
} }

View File

@ -19,7 +19,7 @@ class TypeStore: public ox::TypeStore {
explicit TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept; explicit TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept;
protected: protected:
ox::Result<ox::UPtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override; ox::Result<ox::UPtr<ox::DescriptorType>> loadDescriptor(ox::StringView typeId) noexcept override;
}; };
} }

View File

@ -6,41 +6,45 @@
namespace keel { namespace keel {
ox::Result<ox::UUID> readUuidHeader(ox::Buffer const&buff) noexcept { ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept {
return readUuidHeader(buff.data(), buff.size()); if (buff.size() < K1HdrSz) [[unlikely]] {
}
ox::Result<ox::UUID> readUuidHeader(char const*buff, std::size_t buffLen) noexcept {
if (buffLen < K1HdrSz) {
return OxError(1, "Insufficient data to contain complete Keel header"); return OxError(1, "Insufficient data to contain complete Keel header");
} }
constexpr ox::StringView k1Hdr = "K1;"; constexpr ox::StringView k1Hdr = "K1;";
if (k1Hdr != ox::StringView(buff, k1Hdr.bytes())) { if (k1Hdr != ox::StringView(buff.data(), k1Hdr.bytes())) [[unlikely]] {
return OxError(2, "No Keel asset header data"); return OxError(2, "No Keel asset header data");
} }
return ox::UUID::fromString(ox::StringView(buff + k1Hdr.bytes(), 36)); return ox::UUID::fromString(ox::StringView(buff.data() + k1Hdr.bytes(), 36));
} }
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::Buffer const&buff) noexcept { ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept {
std::size_t offset = 0; std::size_t offset = 0;
if (!readUuidHeader(buff).error) { if (!readUuidHeader(buff).error) {
offset = K1HdrSz; offset = K1HdrSz;
} }
return ox::readClaw(ts, buff.data() + offset, buff.size() - offset); buff += offset;
return ox::readClaw(ts, buff);
} }
ox::Result<AssetHdr> readAssetHeader(char const*buff, std::size_t buffLen) noexcept { ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept {
AssetHdr out; const auto err = readUuidHeader(buff).error;
const auto err = readUuidHeader(buff, buffLen).moveTo(out.uuid);
const auto offset = err ? 0u : K1HdrSz; const auto offset = err ? 0u : K1HdrSz;
buff = buff + offset; if (offset >= buff.size()) [[unlikely]] {
buffLen = buffLen - offset; return OxError(1, "Buffer too small for expected data");
oxReturnError(ox::readClawHeader(buff, buffLen).moveTo(out.clawHdr)); }
return ox::readClawTypeId(buff + offset);
}
ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept {
ox::Result<AssetHdr> out;
const auto err = readUuidHeader(buff).moveTo(out.value.uuid);
const auto offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] {
return OxError(1, "Buffer too small for expected data");
}
buff += offset;
oxReturnError(ox::readClawHeader(buff).moveTo(out.value.clawHdr));
return out; return out;
} }
ox::Result<AssetHdr> readAssetHeader(ox::Buffer const&buff) noexcept {
return readAssetHeader(buff.data(), buff.size());
}
} }

View File

@ -102,14 +102,11 @@ ox::Result<ox::String> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
} }
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept { ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept {
#ifndef OX_BARE_METAL oxRequire(typeId, readAssetTypeId(clawData).to<ox::String>());
for (auto tr : ctx.packTransforms) { for (auto const tr : packTransforms(ctx)) {
oxReturnError(tr(ctx, clawData)); oxReturnError(tr(ctx, clawData, typeId));
} }
return {}; return {};
#else
return OxError(1, "Transformations not supported on this platform");
#endif
} }
} }
@ -153,7 +150,7 @@ ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::CRStringView path
oxRequire(stat, ctx.rom->stat(path)); oxRequire(stat, ctx.rom->stat(path));
oxRequire(buff, static_cast<ox::MemFS*>(ctx.rom.get())->directAccess(path)); oxRequire(buff, static_cast<ox::MemFS*>(ctx.rom.get())->directAccess(path));
PreloadPtr p; PreloadPtr p;
oxReturnError(ox::readMC(buff, static_cast<std::size_t>(stat.size), &p)); oxReturnError(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset; return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset;
} }
@ -161,7 +158,7 @@ ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const
oxRequire(stat, ctx.rom->stat(file)); oxRequire(stat, ctx.rom->stat(file));
oxRequire(buff, static_cast<ox::MemFS*>(ctx.rom.get())->directAccess(file)); oxRequire(buff, static_cast<ox::MemFS*>(ctx.rom.get())->directAccess(file));
PreloadPtr p; PreloadPtr p;
oxReturnError(ox::readMC(buff, static_cast<std::size_t>(stat.size), &p)); oxReturnError(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset; return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset;
} }

View File

@ -10,13 +10,13 @@
namespace keel { namespace keel {
[[nodiscard]] [[nodiscard]]
static ox::Result<const BaseConverter*> findConverter( static ox::Result<BaseConverter const*> findConverter(
ox::Vector<const BaseConverter*> const&converters, ox::SpanView<BaseConverter const*> const&converters,
ox::CRStringView srcTypeName, ox::CRStringView srcTypeName,
int srcTypeVersion, int srcTypeVersion,
ox::CRStringView dstTypeName, ox::CRStringView dstTypeName,
int dstTypeVersion) noexcept { int dstTypeVersion) noexcept {
for (auto &c : converters) { for (auto const&c : converters) {
if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) { if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
return c; return c;
} }
@ -24,21 +24,22 @@ static ox::Result<const BaseConverter*> findConverter(
return OxError(1, "Could not find converter"); return OxError(1, "Could not find converter");
}; };
static ox::Result<ox::UniquePtr<Wrap>> convert( static ox::Result<ox::UPtr<Wrap>> convert(
[[maybe_unused]] keel::Context &ctx, keel::Context &ctx,
ox::Vector<const BaseConverter*> const&converters, ox::SpanView<BaseConverter const*> const&converters,
[[maybe_unused]] ox::Buffer const&srcBuffer, ox::Buffer const&srcBuffer,
[[maybe_unused]] ox::CRStringView srcTypeName, ox::CRStringView srcTypeName,
[[maybe_unused]] int srcTypeVersion, int srcTypeVersion,
[[maybe_unused]] ox::CRStringView dstTypeName, ox::CRStringView dstTypeName,
[[maybe_unused]] int dstTypeVersion) noexcept { int dstTypeVersion) noexcept {
// look for direct converter // look for direct converter
auto [c, err] = findConverter(converters, srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion); auto [c, err] = findConverter(
converters, srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion);
if (!err) { if (!err) {
return c->convertBuffToPtr(ctx, srcBuffer); return c->convertBuffToPtr(ctx, srcBuffer);
} }
// try to chain multiple converters // try to chain multiple converters
for (const auto &subConverter : converters) { for (auto const&subConverter : converters) {
if (!subConverter->dstMatches(dstTypeName, dstTypeVersion)) { if (!subConverter->dstMatches(dstTypeName, dstTypeVersion)) {
continue; continue;
} }
@ -52,24 +53,20 @@ static ox::Result<ox::UniquePtr<Wrap>> convert(
return OxError(1, "Could not convert between types"); return OxError(1, "Could not convert between types");
} }
ox::Result<ox::UniquePtr<Wrap>> convert( ox::Result<ox::UPtr<Wrap>> convert(
[[maybe_unused]] keel::Context &ctx, keel::Context &ctx,
[[maybe_unused]] ox::Buffer const&srcBuffer, ox::Buffer const&srcBuffer,
[[maybe_unused]] ox::CRStringView dstTypeName, ox::CRStringView dstTypeName,
[[maybe_unused]] int dstTypeVersion) noexcept { int dstTypeVersion) noexcept {
#ifndef OX_BARE_METAL
oxRequire(hdr, readAssetHeader(srcBuffer)); oxRequire(hdr, readAssetHeader(srcBuffer));
return convert( return convert(
ctx, ctx,
ctx.converters, converters(ctx),
srcBuffer, srcBuffer,
hdr.clawHdr.typeName, hdr.clawHdr.typeName,
hdr.clawHdr.typeVersion, hdr.clawHdr.typeVersion,
dstTypeName, dstTypeName,
dstTypeVersion); dstTypeVersion);
#else
return OxError(1, "Operation not supported on this platform");
#endif
} }
} }

View File

@ -11,11 +11,11 @@ TypeStore::TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept:
m_descPath(descPath) { m_descPath(descPath) {
} }
ox::Result<ox::UPtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept { ox::Result<ox::UPtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::StringView const typeId) noexcept {
auto path = ox::sfmt("{}/{}", m_descPath, typeId); auto const path = ox::sfmt("{}/{}", m_descPath, typeId);
oxRequire(buff, m_fs.read(path)); oxRequire(buff, m_fs.read(path));
auto dt = ox::make_unique<ox::DescriptorType>(); auto dt = ox::make_unique<ox::DescriptorType>();
oxReturnError(ox::readClaw<ox::DescriptorType>(buff, dt.get())); oxReturnError(ox::readClaw<ox::DescriptorType>(buff, *dt));
return dt; return dt;
} }

View File

@ -68,7 +68,7 @@ static ox::Error run(
static_cast<uint64_t>(time << 1) static_cast<uint64_t>(time << 1)
}); });
// run app // run app
auto const err = runApp(appName, projectDataDir, ox::UniquePtr<ox::FileSystem>(nullptr)); auto const err = runApp(appName, projectDataDir, ox::UPtr<ox::FileSystem>(nullptr));
oxAssert(err, "Something went wrong..."); oxAssert(err, "Something went wrong...");
return err; return err;
} }

View File

@ -29,9 +29,9 @@ ox::Result<T> getDragDropPayload(ox::CStringView name) noexcept {
if (!payload) { if (!payload) {
return OxError(1, "No drag/drop payload"); return OxError(1, "No drag/drop payload");
} }
return ox::readClaw<T>( return ox::readClaw<T>({
reinterpret_cast<char const*>(payload->Data), reinterpret_cast<char const*>(payload->Data),
static_cast<size_t>(payload->DataSize)); static_cast<size_t>(payload->DataSize)});
} }
ox::Error setDragDropPayload(ox::CStringView name, auto const &obj) noexcept { ox::Error setDragDropPayload(ox::CStringView name, auto const &obj) noexcept {