Compare commits
8 Commits
cc4da3a4c4
...
d2e30b4cfd
Author | SHA1 | Date | |
---|---|---|---|
d2e30b4cfd | |||
7a8680610d | |||
1986619f65 | |||
c410c8e897 | |||
2a286a64ca | |||
305eb62647 | |||
4754359a21 | |||
dc07f3d58b |
8
deps/glutils/src/glutils.cpp
vendored
8
deps/glutils/src/glutils.cpp
vendored
@ -89,7 +89,7 @@ static ox::Result<GLShader> buildShader(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<GLProgram> buildShaderProgram(ProgramSource const&src) noexcept {
|
ox::Result<GLProgram> buildShaderProgram(ProgramSource const&src) noexcept {
|
||||||
oxRequireM(program, buildShaderProgram(
|
OX_REQUIRE_M(program, buildShaderProgram(
|
||||||
src.vertShader,
|
src.vertShader,
|
||||||
src.fragShader,
|
src.fragShader,
|
||||||
src.geomShader));
|
src.geomShader));
|
||||||
@ -127,13 +127,13 @@ ox::Result<GLProgram> buildShaderProgram(
|
|||||||
ox::CStringView const&frag,
|
ox::CStringView const&frag,
|
||||||
ox::CStringView const&geo) noexcept {
|
ox::CStringView const&geo) noexcept {
|
||||||
GLProgram prgm(glCreateProgram());
|
GLProgram prgm(glCreateProgram());
|
||||||
oxRequire(vs, buildShader(GL_VERTEX_SHADER, vert.c_str(), "vshad"));
|
OX_REQUIRE(vs, buildShader(GL_VERTEX_SHADER, vert.c_str(), "vshad"));
|
||||||
glAttachShader(prgm, vs);
|
glAttachShader(prgm, vs);
|
||||||
if (geo.c_str() && geo.bytes() != 0) {
|
if (geo.c_str() && geo.bytes() != 0) {
|
||||||
oxRequire(gs, buildShader(GL_GEOMETRY_SHADER, geo.c_str(), "gshad"));
|
OX_REQUIRE(gs, buildShader(GL_GEOMETRY_SHADER, geo.c_str(), "gshad"));
|
||||||
glAttachShader(prgm, gs);
|
glAttachShader(prgm, gs);
|
||||||
}
|
}
|
||||||
oxRequire(fs, buildShader(GL_FRAGMENT_SHADER, frag.c_str(), "fshad"));
|
OX_REQUIRE(fs, buildShader(GL_FRAGMENT_SHADER, frag.c_str(), "fshad"));
|
||||||
glAttachShader(prgm, fs);
|
glAttachShader(prgm, fs);
|
||||||
glLinkProgram(prgm);
|
glLinkProgram(prgm);
|
||||||
return prgm;
|
return prgm;
|
||||||
|
82
deps/ox/ox-docs.md
vendored
82
deps/ox/ox-docs.md
vendored
@ -97,12 +97,12 @@ ox::Result<uint64_t> caller8(int i) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Lastly, there are a few macros available to help in passing ```ox::Error```s
|
Lastly, there are a few macros available to help in passing ```ox::Error```s
|
||||||
back up the call stack, ```oxReturnError```, ```oxThrowError```, and
|
back up the call stack, ```OX_RETURN_ERROR```, ```OX_THROW_ERROR```, and
|
||||||
```oxRequire```.
|
```OX_REQUIRE```.
|
||||||
|
|
||||||
```oxReturnError``` is by far the more helpful of the two.
|
```OX_RETURN_ERROR``` is by far the more helpful of the two.
|
||||||
```oxReturnError``` will return an ```ox::Error``` if it is not 0 and
|
```OX_RETURN_ERROR``` will return an ```ox::Error``` if it is not 0 and
|
||||||
```oxThrowError``` will throw an ```ox::Error``` if it is not 0.
|
```OX_THROW_ERROR``` will throw an ```ox::Error``` if it is not 0.
|
||||||
|
|
||||||
Since ```ox::Error``` is always nodiscard, you must do something with them.
|
Since ```ox::Error``` is always nodiscard, you must do something with them.
|
||||||
In rare cases, you may not have anything you can do with them or you may know
|
In rare cases, you may not have anything you can do with them or you may know
|
||||||
@ -113,13 +113,13 @@ This should be used sparingly.
|
|||||||
```cpp
|
```cpp
|
||||||
void studioCode() {
|
void studioCode() {
|
||||||
auto [val, err] = foo(1);
|
auto [val, err] = foo(1);
|
||||||
oxThrowError(err);
|
OX_THROW_ERROR(err);
|
||||||
doStuff(val);
|
doStuff(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error engineCode() noexcept {
|
ox::Error engineCode() noexcept {
|
||||||
auto [val, err] = foo(1);
|
auto [val, err] = foo(1);
|
||||||
oxReturnError(err);
|
OX_RETURN_ERROR(err);
|
||||||
doStuff(val);
|
doStuff(val);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -136,19 +136,19 @@ Both macros will also take the ```ox::Result``` directly:
|
|||||||
```cpp
|
```cpp
|
||||||
void studioCode() {
|
void studioCode() {
|
||||||
auto valerr = foo(1);
|
auto valerr = foo(1);
|
||||||
oxThrowError(valerr);
|
OX_THROW_ERROR(valerr);
|
||||||
doStuff(valerr.value);
|
doStuff(valerr.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error engineCode() noexcept {
|
ox::Error engineCode() noexcept {
|
||||||
auto valerr = foo(1);
|
auto valerr = foo(1);
|
||||||
oxReturnError(valerr);
|
OX_RETURN_ERROR(valerr);
|
||||||
doStuff(valerr.value);
|
doStuff(valerr.value);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Ox also has the ```oxRequire``` macro, which will initialize a value if there is no error, and return if there is.
|
Ox also has the ```OX_REQUIRE``` macro, which will initialize a value if there is no error, and return if there is.
|
||||||
It aims to somewhat emulate the ```?``` operator in Rust and Swift.
|
It aims to somewhat emulate the ```?``` operator in Rust and Swift.
|
||||||
|
|
||||||
Rust ```?``` operator:
|
Rust ```?``` operator:
|
||||||
@ -163,23 +163,23 @@ fn f2() -> Result<i32, i32> {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```oxRequire```:
|
```OX_REQUIRE```:
|
||||||
```cpp
|
```cpp
|
||||||
ox::Result<int> f() noexcept {
|
ox::Result<int> f() noexcept {
|
||||||
// do stuff
|
// do stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<int> f2() noexcept {
|
ox::Result<int> f2() noexcept {
|
||||||
oxRequire(i, f()); // const auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__))
|
OX_REQUIRE(i, f()); // const auto [out, OX_CONCAT(oxRequire_err_, __LINE__)] = x; OX_RETURN_ERROR(OX_CONCAT(oxRequire_err_, __LINE__))
|
||||||
return i + 4;
|
return i + 4;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
```oxRequire``` is not quite as versatile, but it should still cleanup a lot of otherwise less ideal code.
|
```OX_REQUIRE``` is not quite as versatile, but it should still cleanup a lot of otherwise less ideal code.
|
||||||
|
|
||||||
```oxRequire``` by default creates a const, but there is also an ```oxRequireM``` (oxRequire Mutable)
|
```OX_REQUIRE``` by default creates a const, but there is also an ```OX_REQUIRE_M``` (OX_REQUIRE Mutable)
|
||||||
variant for creating a non-const value.
|
variant for creating a non-const value.
|
||||||
|
|
||||||
* ```oxRequireM``` - oxRequire Mutable
|
* ```OX_REQUIRE_M``` - OX_REQUIRE Mutable
|
||||||
|
|
||||||
### Logging and Output
|
### Logging and Output
|
||||||
|
|
||||||
@ -268,19 +268,19 @@ constexpr ox::Error model(T *h, ox::CommonPtrWith<NostalgiaPalette> auto *pal) n
|
|||||||
h->template setTypeInfo<NostalgiaPalette>();
|
h->template setTypeInfo<NostalgiaPalette>();
|
||||||
// it is also possible to provide the type name and type version as function arguments
|
// it is also possible to provide the type name and type version as function arguments
|
||||||
//h->setTypeInfo("net.drinkingtea.nostalgia.core.NostalgiaPalette", 1);
|
//h->setTypeInfo("net.drinkingtea.nostalgia.core.NostalgiaPalette", 1);
|
||||||
oxReturnError(h->field("colors", &pal->colors));
|
OX_RETURN_ERROR(h->field("colors", &pal->colors));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error model(T *h, ox::CommonPtrWith<NostalgiaGraphic> auto *ng) noexcept {
|
constexpr ox::Error model(T *h, ox::CommonPtrWith<NostalgiaGraphic> auto *ng) noexcept {
|
||||||
h->template setTypeInfo<NostalgiaGraphic>();
|
h->template setTypeInfo<NostalgiaGraphic>();
|
||||||
oxReturnError(h->field("bpp", &ng->bpp));
|
OX_RETURN_ERROR(h->field("bpp", &ng->bpp));
|
||||||
oxReturnError(h->field("rows", &ng->rows));
|
OX_RETURN_ERROR(h->field("rows", &ng->rows));
|
||||||
oxReturnError(h->field("columns", &ng->columns));
|
OX_RETURN_ERROR(h->field("columns", &ng->columns));
|
||||||
oxReturnError(h->field("defaultPalette", &ng->defaultPalette));
|
OX_RETURN_ERROR(h->field("defaultPalette", &ng->defaultPalette));
|
||||||
oxReturnError(h->field("pal", &ng->pal));
|
OX_RETURN_ERROR(h->field("pal", &ng->pal));
|
||||||
oxReturnError(h->field("pixels", &ng->pixels));
|
OX_RETURN_ERROR(h->field("pixels", &ng->pixels));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -315,9 +315,9 @@ class FileAddress {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *h, ox::CommonPtrWith<FileAddress::Data> auto *obj) noexcept {
|
constexpr Error model(T *h, ox::CommonPtrWith<FileAddress::Data> auto *obj) noexcept {
|
||||||
h->template setTypeInfo<FileAddress::Data>();
|
h->template setTypeInfo<FileAddress::Data>();
|
||||||
oxReturnError(h->fieldCString("path", &obj->path));
|
OX_RETURN_ERROR(h->fieldCString("path", &obj->path));
|
||||||
oxReturnError(h->fieldCString("constPath", &obj->path));
|
OX_RETURN_ERROR(h->fieldCString("constPath", &obj->path));
|
||||||
oxReturnError(h->field("inode", &obj->inode));
|
OX_RETURN_ERROR(h->field("inode", &obj->inode));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,13 +327,13 @@ constexpr Error model(T *io, ox::CommonPtrWith<FileAddress> auto *fa) noexcept {
|
|||||||
// cannot read from object in Reflect operation
|
// cannot read from object in Reflect operation
|
||||||
if constexpr(ox_strcmp(T::opType(), OpType::Reflect) == 0) {
|
if constexpr(ox_strcmp(T::opType(), OpType::Reflect) == 0) {
|
||||||
int8_t type = 0;
|
int8_t type = 0;
|
||||||
oxReturnError(io->field("type", &type));
|
OX_RETURN_ERROR(io->field("type", &type));
|
||||||
oxReturnError(io->field("data", UnionView(&fa->m_data, 0)));
|
OX_RETURN_ERROR(io->field("data", UnionView(&fa->m_data, 0)));
|
||||||
} else {
|
} else {
|
||||||
auto type = static_cast<int8_t>(fa->m_type);
|
auto type = static_cast<int8_t>(fa->m_type);
|
||||||
oxReturnError(io->field("type", &type));
|
OX_RETURN_ERROR(io->field("type", &type));
|
||||||
fa->m_type = static_cast<FileAddressType>(type);
|
fa->m_type = static_cast<FileAddressType>(type);
|
||||||
oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
OX_RETURN_ERROR(io->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -343,13 +343,13 @@ constexpr Error model(T *io, ox::CommonPtrWith<FileAddress> auto *fa) noexcept {
|
|||||||
There are also macros in ```<ox/model/def.hpp>``` for simplifying the declaration of models:
|
There are also macros in ```<ox/model/def.hpp>``` for simplifying the declaration of models:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
oxModelBegin(NostalgiaGraphic)
|
OX_MODEL_BEGIN(NostalgiaGraphic)
|
||||||
oxModelField(bpp)
|
OX_MODEL_FIELD(bpp)
|
||||||
oxModelField(rows)
|
OX_MODEL_FIELD(rows)
|
||||||
oxModelField(columns)
|
OX_MODEL_FIELD(columns)
|
||||||
oxModelField(defaultPalette)
|
OX_MODEL_FIELD(defaultPalette)
|
||||||
oxModelField(pal)
|
OX_MODEL_FIELD(pal)
|
||||||
oxModelField(pixels)
|
OX_MODEL_FIELD(pixels)
|
||||||
oxModelEnd()
|
oxModelEnd()
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ ox::Result<NostalgiaPalette> loadPalette1(ox::BufferView const&buff) noexcept {
|
|||||||
|
|
||||||
ox::Result<NostalgiaPalette> loadPalette2(ox::BufferView const&buff) noexcept {
|
ox::Result<NostalgiaPalette> loadPalette2(ox::BufferView const&buff) noexcept {
|
||||||
NostalgiaPalette pal;
|
NostalgiaPalette pal;
|
||||||
oxReturnError(ox::readMC(buff, pal));
|
OX_RETURN_ERROR(ox::readMC(buff, pal));
|
||||||
return pal;
|
return pal;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -405,7 +405,7 @@ ox::Result<NostalgiaPalette> loadPalette2(ox::BufferView const&buff) noexcept {
|
|||||||
ox::Result<ox::Buffer> writeSpritePalette1(NostalgiaPalette const&pal) noexcept {
|
ox::Result<ox::Buffer> writeSpritePalette1(NostalgiaPalette const&pal) noexcept {
|
||||||
ox::Buffer buffer(ox::units::MB);
|
ox::Buffer buffer(ox::units::MB);
|
||||||
std::size_t sz = 0;
|
std::size_t sz = 0;
|
||||||
oxReturnError(ox::writeMC(buffer.data(), buffer.size(), pal, &sz));
|
OX_RETURN_ERROR(ox::writeMC(buffer.data(), buffer.size(), pal, &sz));
|
||||||
buffer.resize(sz);
|
buffer.resize(sz);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@ -428,7 +428,7 @@ ox::Result<NostalgiaPalette> loadPalette1(ox::BufferView const&buff) noexcept {
|
|||||||
|
|
||||||
ox::Result<NostalgiaPalette> loadPalette2(ox::BufferView const&buff) noexcept {
|
ox::Result<NostalgiaPalette> loadPalette2(ox::BufferView const&buff) noexcept {
|
||||||
NostalgiaPalette pal;
|
NostalgiaPalette pal;
|
||||||
oxReturnError(ox::readOC(buff, &pal));
|
OX_RETURN_ERROR(ox::readOC(buff, &pal));
|
||||||
return pal;
|
return pal;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -440,7 +440,7 @@ ox::Result<NostalgiaPalette> loadPalette2(ox::BufferView const&buff) noexcept {
|
|||||||
|
|
||||||
ox::Result<ox::Buffer> writeSpritePalette1(NostalgiaPalette const&pal) noexcept {
|
ox::Result<ox::Buffer> writeSpritePalette1(NostalgiaPalette const&pal) noexcept {
|
||||||
ox::Buffer buffer(ox::units::MB);
|
ox::Buffer buffer(ox::units::MB);
|
||||||
oxReturnError(ox::writeOC(buffer.data(), buffer.size(), pal));
|
OX_RETURN_ERROR(ox::writeOC(buffer.data(), buffer.size(), pal));
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,7 +462,7 @@ ox::Result<NostalgiaPalette> loadPalette1(ox::BufferView const&buff) noexcept {
|
|||||||
|
|
||||||
ox::Result<NostalgiaPalette> loadPalette2(ox::BufferView const&buff) noexcept {
|
ox::Result<NostalgiaPalette> loadPalette2(ox::BufferView const&buff) noexcept {
|
||||||
NostalgiaPalette pal;
|
NostalgiaPalette pal;
|
||||||
oxReturnError(ox::readClaw(buff, pal));
|
OX_RETURN_ERROR(ox::readClaw(buff, pal));
|
||||||
return pal;
|
return pal;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
6
deps/ox/src/ox/clargs/clargs.cpp
vendored
6
deps/ox/src/ox/clargs/clargs.cpp
vendored
@ -55,17 +55,17 @@ int ClArgs::getInt(ox::StringViewCR arg, int defaultValue) const noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result<bool> ClArgs::getBool(ox::StringViewCR arg) const noexcept {
|
Result<bool> ClArgs::getBool(ox::StringViewCR arg) const noexcept {
|
||||||
oxRequire(out, m_bools.at(arg));
|
OX_REQUIRE(out, m_bools.at(arg));
|
||||||
return *out;
|
return *out;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<String> ClArgs::getString(ox::StringViewCR argName) const noexcept {
|
Result<String> ClArgs::getString(ox::StringViewCR argName) const noexcept {
|
||||||
oxRequire(out, m_strings.at(argName));
|
OX_REQUIRE(out, m_strings.at(argName));
|
||||||
return *out;
|
return *out;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<int> ClArgs::getInt(ox::StringViewCR arg) const noexcept {
|
Result<int> ClArgs::getInt(ox::StringViewCR arg) const noexcept {
|
||||||
oxRequire(out, m_ints.at(arg));
|
OX_REQUIRE(out, m_ints.at(arg));
|
||||||
return *out;
|
return *out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
deps/ox/src/ox/claw/read.cpp
vendored
10
deps/ox/src/ox/claw/read.cpp
vendored
@ -88,26 +88,26 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result<BufferView> stripClawHeader(ox::BufferView buff) noexcept {
|
Result<BufferView> stripClawHeader(ox::BufferView buff) noexcept {
|
||||||
oxRequire(header, readClawHeader(buff));
|
OX_REQUIRE(header, readClawHeader(buff));
|
||||||
return {{header.data, header.dataSize}};
|
return {{header.data, header.dataSize}};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<ModelObject> readClaw(TypeStore &ts, BufferView buff) noexcept {
|
Result<ModelObject> readClaw(TypeStore &ts, BufferView buff) noexcept {
|
||||||
oxRequire(header, readClawHeader(buff));
|
OX_REQUIRE(header, readClawHeader(buff));
|
||||||
auto const [t, tdErr] = ts.getLoad(
|
auto const [t, tdErr] = ts.getLoad(
|
||||||
header.typeName, header.typeVersion, header.typeParams);
|
header.typeName, header.typeVersion, header.typeParams);
|
||||||
if (tdErr) {
|
if (tdErr) {
|
||||||
return ox::Error(3, "Could not load type descriptor");
|
return ox::Error(3, "Could not load type descriptor");
|
||||||
}
|
}
|
||||||
ModelObject obj;
|
ModelObject obj;
|
||||||
oxReturnError(obj.setType(t));
|
OX_RETURN_ERROR(obj.setType(t));
|
||||||
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));
|
OX_RETURN_ERROR(model(&handler, &obj));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
case ClawFormat::Organic:
|
case ClawFormat::Organic:
|
||||||
@ -115,7 +115,7 @@ Result<ModelObject> readClaw(TypeStore &ts, BufferView buff) noexcept {
|
|||||||
#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));
|
OX_RETURN_ERROR(model(&handler, &obj));
|
||||||
return obj;
|
return obj;
|
||||||
#else
|
#else
|
||||||
break;
|
break;
|
||||||
|
4
deps/ox/src/ox/claw/read.hpp
vendored
4
deps/ox/src/ox/claw/read.hpp
vendored
@ -40,7 +40,7 @@ Result<BufferView> stripClawHeader(ox::BufferView buff) noexcept;
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Error readClaw(ox::BufferView buff, T &val) {
|
Error readClaw(ox::BufferView buff, T &val) {
|
||||||
oxRequire(header, readClawHeader(buff));
|
OX_REQUIRE(header, readClawHeader(buff));
|
||||||
if (header.typeName != getModelTypeName<T>()) {
|
if (header.typeName != getModelTypeName<T>()) {
|
||||||
return ox::Error(Error_ClawTypeMismatch, "Claw Read: Type mismatch");
|
return ox::Error(Error_ClawTypeMismatch, "Claw Read: Type mismatch");
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ Error readClaw(ox::BufferView buff, T &val) {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
Result<T> readClaw(ox::BufferView buff) {
|
Result<T> readClaw(ox::BufferView buff) {
|
||||||
Result<T> val;
|
Result<T> val;
|
||||||
oxReturnError(readClaw(buff, val.value));
|
OX_RETURN_ERROR(readClaw(buff, val.value));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
52
deps/ox/src/ox/claw/test/tests.cpp
vendored
52
deps/ox/src/ox/claw/test/tests.cpp
vendored
@ -62,44 +62,44 @@ struct TestStruct {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestUnion> auto *obj) {
|
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestUnion> auto *obj) {
|
||||||
oxReturnError(io->template setTypeInfo<TestUnion>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TestUnion>());
|
||||||
oxReturnError(io->field("Bool", &obj->Bool));
|
OX_RETURN_ERROR(io->field("Bool", &obj->Bool));
|
||||||
oxReturnError(io->field("Int", &obj->Int));
|
OX_RETURN_ERROR(io->field("Int", &obj->Int));
|
||||||
oxReturnError(io->fieldCString("String", &obj->String));
|
OX_RETURN_ERROR(io->fieldCString("String", &obj->String));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStructNest> auto *obj) {
|
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStructNest> auto *obj) {
|
||||||
oxReturnError(io->template setTypeInfo<TestStructNest>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TestStructNest>());
|
||||||
oxReturnError(io->field("Bool", &obj->Bool));
|
OX_RETURN_ERROR(io->field("Bool", &obj->Bool));
|
||||||
oxReturnError(io->field("Int", &obj->Int));
|
OX_RETURN_ERROR(io->field("Int", &obj->Int));
|
||||||
oxReturnError(io->field("String", &obj->String));
|
OX_RETURN_ERROR(io->field("String", &obj->String));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) {
|
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) {
|
||||||
oxReturnError(io->template setTypeInfo<TestStruct>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TestStruct>());
|
||||||
oxReturnError(io->field("Bool", &obj->Bool));
|
OX_RETURN_ERROR(io->field("Bool", &obj->Bool));
|
||||||
oxReturnError(io->field("Int", &obj->Int));
|
OX_RETURN_ERROR(io->field("Int", &obj->Int));
|
||||||
oxReturnError(io->field("Int1", &obj->Int1));
|
OX_RETURN_ERROR(io->field("Int1", &obj->Int1));
|
||||||
oxReturnError(io->field("Int2", &obj->Int2));
|
OX_RETURN_ERROR(io->field("Int2", &obj->Int2));
|
||||||
oxReturnError(io->field("Int3", &obj->Int3));
|
OX_RETURN_ERROR(io->field("Int3", &obj->Int3));
|
||||||
oxReturnError(io->field("Int4", &obj->Int4));
|
OX_RETURN_ERROR(io->field("Int4", &obj->Int4));
|
||||||
oxReturnError(io->field("Int5", &obj->Int5));
|
OX_RETURN_ERROR(io->field("Int5", &obj->Int5));
|
||||||
oxReturnError(io->field("Int6", &obj->Int6));
|
OX_RETURN_ERROR(io->field("Int6", &obj->Int6));
|
||||||
oxReturnError(io->field("Int7", &obj->Int7));
|
OX_RETURN_ERROR(io->field("Int7", &obj->Int7));
|
||||||
oxReturnError(io->field("Int8", &obj->Int8));
|
OX_RETURN_ERROR(io->field("Int8", &obj->Int8));
|
||||||
int unionIdx = 0;
|
int unionIdx = 0;
|
||||||
if constexpr(T::opType() != ox::OpType::Reflect) {
|
if constexpr(T::opType() != ox::OpType::Reflect) {
|
||||||
unionIdx = obj->unionIdx;
|
unionIdx = obj->unionIdx;
|
||||||
}
|
}
|
||||||
oxReturnError(io->field("Union", ox::UnionView{&obj->Union, unionIdx}));
|
OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, unionIdx}));
|
||||||
oxReturnError(io->field("String", &obj->String));
|
OX_RETURN_ERROR(io->field("String", &obj->String));
|
||||||
oxReturnError(io->field("List", obj->List, 4));
|
OX_RETURN_ERROR(io->field("List", obj->List, 4));
|
||||||
oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct));
|
OX_RETURN_ERROR(io->field("EmptyStruct", &obj->EmptyStruct));
|
||||||
oxReturnError(io->field("Struct", &obj->Struct));
|
OX_RETURN_ERROR(io->field("Struct", &obj->Struct));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
[] {
|
[] {
|
||||||
constexpr auto hdr = ox::StringLiteral("M2;com.drinkingtea.ox.claw.test.Header2;3;awefawf");
|
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");
|
constexpr auto expected = ox::StringLiteral("com.drinkingtea.ox.claw.test.Header2;3");
|
||||||
oxRequire(actual, ox::readClawTypeId({hdr.data(), hdr.len() + 1}));
|
OX_REQUIRE(actual, ox::readClawTypeId({hdr.data(), hdr.len() + 1}));
|
||||||
oxExpect(actual, expected);
|
oxExpect(actual, expected);
|
||||||
return ox::Error{};
|
return ox::Error{};
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
// This test doesn't confirm much, but it does show that the writer
|
// This test doesn't confirm much, but it does show that the writer
|
||||||
// doesn't segfault
|
// doesn't segfault
|
||||||
TestStruct ts;
|
TestStruct ts;
|
||||||
oxReturnError(ox::writeClaw(ts, ox::ClawFormat::Metal));
|
OX_RETURN_ERROR(ox::writeClaw(ts, ox::ClawFormat::Metal));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
22
deps/ox/src/ox/claw/write.hpp
vendored
22
deps/ox/src/ox/claw/write.hpp
vendored
@ -76,21 +76,21 @@ template<typename T>
|
|||||||
ox::Error writeClawHeader(Writer_c auto &writer, const T *t, ClawFormat fmt) noexcept {
|
ox::Error writeClawHeader(Writer_c auto &writer, const T *t, ClawFormat fmt) noexcept {
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case ClawFormat::Metal:
|
case ClawFormat::Metal:
|
||||||
oxReturnError(write(writer, "M2;"));
|
OX_RETURN_ERROR(write(writer, "M2;"));
|
||||||
break;
|
break;
|
||||||
case ClawFormat::Organic:
|
case ClawFormat::Organic:
|
||||||
oxReturnError(write(writer, "O1;"));
|
OX_RETURN_ERROR(write(writer, "O1;"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
}
|
}
|
||||||
oxReturnError(write(writer, detail::getTypeName(t)));
|
OX_RETURN_ERROR(write(writer, detail::getTypeName(t)));
|
||||||
oxReturnError(writer.put(';'));
|
OX_RETURN_ERROR(writer.put(';'));
|
||||||
const auto tn = detail::getTypeVersion(t);
|
const auto tn = detail::getTypeVersion(t);
|
||||||
if (tn > -1) {
|
if (tn > -1) {
|
||||||
oxReturnError(ox::writeItoa(tn, writer));
|
OX_RETURN_ERROR(ox::writeItoa(tn, writer));
|
||||||
}
|
}
|
||||||
oxReturnError(writer.put(';'));
|
OX_RETURN_ERROR(writer.put(';'));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,19 +102,19 @@ Result<Buffer> writeClaw(
|
|||||||
std::size_t buffReserveSz = 2 * units::KB) noexcept {
|
std::size_t buffReserveSz = 2 * units::KB) noexcept {
|
||||||
Buffer out(buffReserveSz);
|
Buffer out(buffReserveSz);
|
||||||
BufferWriter bw(&out, 0);
|
BufferWriter bw(&out, 0);
|
||||||
oxReturnError(detail::writeClawHeader(bw, &t, fmt));
|
OX_RETURN_ERROR(detail::writeClawHeader(bw, &t, fmt));
|
||||||
#ifdef OX_USE_STDLIB
|
#ifdef OX_USE_STDLIB
|
||||||
if (fmt == ClawFormat::Metal) {
|
if (fmt == ClawFormat::Metal) {
|
||||||
oxReturnError(writeMC(bw, t));
|
OX_RETURN_ERROR(writeMC(bw, t));
|
||||||
} else if (fmt == ClawFormat::Organic) {
|
} else if (fmt == ClawFormat::Organic) {
|
||||||
oxRequire(data, writeOC(t));
|
OX_REQUIRE(data, writeOC(t));
|
||||||
oxReturnError(bw.write(data.data(), data.size()));
|
OX_RETURN_ERROR(bw.write(data.data(), data.size()));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (fmt != ClawFormat::Metal) {
|
if (fmt != ClawFormat::Metal) {
|
||||||
return ox::Error(1, "OC is not supported in this build");
|
return ox::Error(1, "OC is not supported in this build");
|
||||||
}
|
}
|
||||||
oxReturnError(writeMC(bw, t));
|
OX_RETURN_ERROR(writeMC(bw, t));
|
||||||
#endif
|
#endif
|
||||||
out.resize(bw.tellp());
|
out.resize(bw.tellp());
|
||||||
return out;
|
return out;
|
||||||
|
12
deps/ox/src/ox/event/signal.hpp
vendored
12
deps/ox/src/ox/event/signal.hpp
vendored
@ -57,7 +57,7 @@ class Signal {
|
|||||||
|
|
||||||
void call(Args... args) final {
|
void call(Args... args) final {
|
||||||
if constexpr(detail::isError<decltype(f(args...))>::value) {
|
if constexpr(detail::isError<decltype(f(args...))>::value) {
|
||||||
oxThrowError(f(args...));
|
OX_THROW_ERROR(f(args...));
|
||||||
} else {
|
} else {
|
||||||
f(args...);
|
f(args...);
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ class Signal {
|
|||||||
|
|
||||||
void call(Args... args) final {
|
void call(Args... args) final {
|
||||||
if constexpr(detail::isError<decltype((m_receiver->*(m_methodPtr))(args...))>::value) {
|
if constexpr(detail::isError<decltype((m_receiver->*(m_methodPtr))(args...))>::value) {
|
||||||
oxThrowError((m_receiver->*(m_methodPtr))(args...));
|
OX_THROW_ERROR((m_receiver->*(m_methodPtr))(args...));
|
||||||
} else {
|
} else {
|
||||||
f(args...);
|
f(args...);
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ class Signal {
|
|||||||
|
|
||||||
void call(Args... args) final {
|
void call(Args... args) final {
|
||||||
if constexpr(detail::isError<decltype((m_receiver->*(m_methodPtr))(args...))>::value) {
|
if constexpr(detail::isError<decltype((m_receiver->*(m_methodPtr))(args...))>::value) {
|
||||||
oxThrowError((m_receiver->*(m_methodPtr))(args...));
|
OX_THROW_ERROR((m_receiver->*(m_methodPtr))(args...));
|
||||||
} else {
|
} else {
|
||||||
(m_receiver->*(m_methodPtr))(args...);
|
(m_receiver->*(m_methodPtr))(args...);
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ Error Signal<Args...>::disconnectObject(const void *receiver) const noexcept {
|
|||||||
for (auto i = 0u; i < m_slots.size(); ++i) {
|
for (auto i = 0u; i < m_slots.size(); ++i) {
|
||||||
const auto &slot = m_slots[i];
|
const auto &slot = m_slots[i];
|
||||||
if (slot->receiver() == receiver) {
|
if (slot->receiver() == receiver) {
|
||||||
oxReturnError(m_slots.erase(i));
|
OX_RETURN_ERROR(m_slots.erase(i));
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,7 +381,7 @@ Error Signal<Error(Args...)>::disconnectObject(const void *receiver) const noexc
|
|||||||
for (auto i = 0u; i < m_slots.size(); ++i) {
|
for (auto i = 0u; i < m_slots.size(); ++i) {
|
||||||
const auto &slot = m_slots[i];
|
const auto &slot = m_slots[i];
|
||||||
if (slot->receiver() == receiver) {
|
if (slot->receiver() == receiver) {
|
||||||
oxReturnError(m_slots.erase(i));
|
OX_RETURN_ERROR(m_slots.erase(i));
|
||||||
--i;
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,7 +398,7 @@ void Signal<Error(Args...)>::emit(Args... args) const noexcept {
|
|||||||
template<class... Args>
|
template<class... Args>
|
||||||
Error Signal<Error(Args...)>::emitCheckError(Args... args) const noexcept {
|
Error Signal<Error(Args...)>::emitCheckError(Args... args) const noexcept {
|
||||||
for (auto &f : m_slots) {
|
for (auto &f : m_slots) {
|
||||||
oxReturnError(f->call(ox::forward<Args>(args)...));
|
OX_RETURN_ERROR(f->call(ox::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
4
deps/ox/src/ox/event/test/tests.cpp
vendored
4
deps/ox/src/ox/event/test/tests.cpp
vendored
@ -31,8 +31,8 @@ std::map<ox::StringView, std::function<ox::Error()>> tests = {
|
|||||||
});
|
});
|
||||||
TestStruct ts;
|
TestStruct ts;
|
||||||
signal.connect(&ts, &TestStruct::method);
|
signal.connect(&ts, &TestStruct::method);
|
||||||
oxReturnError(signal.emitCheckError(5));
|
OX_RETURN_ERROR(signal.emitCheckError(5));
|
||||||
oxReturnError(ox::Error(ts.value != 5));
|
OX_RETURN_ERROR(ox::Error(ts.value != 5));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -228,17 +228,17 @@ Error FileStoreTemplate<size_t>::setSize(std::size_t size) {
|
|||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
Error FileStoreTemplate<size_t>::incLinks(uint64_t id) {
|
Error FileStoreTemplate<size_t>::incLinks(uint64_t id) {
|
||||||
oxRequireM(item, find(static_cast<size_t>(id)).validate());
|
OX_REQUIRE_M(item, find(static_cast<size_t>(id)).validate());
|
||||||
++item->links;
|
++item->links;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
Error FileStoreTemplate<size_t>::decLinks(uint64_t id) {
|
Error FileStoreTemplate<size_t>::decLinks(uint64_t id) {
|
||||||
oxRequireM(item, find(static_cast<size_t>(id)).validate());
|
OX_REQUIRE_M(item, find(static_cast<size_t>(id)).validate());
|
||||||
--item->links;
|
--item->links;
|
||||||
if (item->links == 0) {
|
if (item->links == 0) {
|
||||||
oxReturnError(remove(item));
|
OX_RETURN_ERROR(remove(item));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -249,7 +249,7 @@ Error FileStoreTemplate<size_t>::write(uint64_t id64, const void *data, FsSize_t
|
|||||||
oxTracef("ox.fs.FileStoreTemplate.write", "Attempting to write to inode {}", id);
|
oxTracef("ox.fs.FileStoreTemplate.write", "Attempting to write to inode {}", id);
|
||||||
auto existing = find(id);
|
auto existing = find(id);
|
||||||
if (!canWrite(existing, dataSize)) {
|
if (!canWrite(existing, dataSize)) {
|
||||||
oxReturnError(compact());
|
OX_RETURN_ERROR(compact());
|
||||||
existing = find(id);
|
existing = find(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ Error FileStoreTemplate<size_t>::write(uint64_t id64, const void *data, FsSize_t
|
|||||||
// if first malloc failed, compact and try again
|
// if first malloc failed, compact and try again
|
||||||
if (!dest.valid()) {
|
if (!dest.valid()) {
|
||||||
oxTrace("ox.fs.FileStoreTemplate.write", "Allocation failed, compacting");
|
oxTrace("ox.fs.FileStoreTemplate.write", "Allocation failed, compacting");
|
||||||
oxReturnError(compact());
|
OX_RETURN_ERROR(compact());
|
||||||
dest = m_buffer->malloc(dataSize).value;
|
dest = m_buffer->malloc(dataSize).value;
|
||||||
}
|
}
|
||||||
if (dest.valid()) {
|
if (dest.valid()) {
|
||||||
@ -305,7 +305,7 @@ Error FileStoreTemplate<size_t>::write(uint64_t id64, const void *data, FsSize_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oxReturnError(m_buffer->free(dest));
|
OX_RETURN_ERROR(m_buffer->free(dest));
|
||||||
}
|
}
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
}
|
}
|
||||||
@ -422,10 +422,10 @@ ptrarith::Ptr<uint8_t, std::size_t> FileStoreTemplate<size_t>::read(uint64_t id)
|
|||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
Error FileStoreTemplate<size_t>::resize() {
|
Error FileStoreTemplate<size_t>::resize() {
|
||||||
oxReturnError(compact());
|
OX_RETURN_ERROR(compact());
|
||||||
const auto newSize = static_cast<std::size_t>(size() - available());
|
const auto newSize = static_cast<std::size_t>(size() - available());
|
||||||
oxTracef("ox.fs.FileStoreTemplate.resize", "resize to: {}", newSize);
|
oxTracef("ox.fs.FileStoreTemplate.resize", "resize to: {}", newSize);
|
||||||
oxReturnError(m_buffer->setSize(newSize));
|
OX_RETURN_ERROR(m_buffer->setSize(newSize));
|
||||||
oxTracef("ox.fs.FileStoreTemplate.resize", "resized to: {}", m_buffer->size());
|
oxTracef("ox.fs.FileStoreTemplate.resize", "resized to: {}", m_buffer->size());
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -438,14 +438,14 @@ Error FileStoreTemplate<size_t>::resize(std::size_t size, void *newBuff) {
|
|||||||
m_buffSize = static_cast<size_t>(size);
|
m_buffSize = static_cast<size_t>(size);
|
||||||
if (newBuff) {
|
if (newBuff) {
|
||||||
m_buffer = reinterpret_cast<Buffer*>(newBuff);
|
m_buffer = reinterpret_cast<Buffer*>(newBuff);
|
||||||
oxReturnError(m_buffer->setSize(static_cast<size_t>(size)));
|
OX_RETURN_ERROR(m_buffer->setSize(static_cast<size_t>(size)));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
Result<StatInfo> FileStoreTemplate<size_t>::stat(uint64_t id) const {
|
Result<StatInfo> FileStoreTemplate<size_t>::stat(uint64_t id) const {
|
||||||
oxRequire(inode, find(static_cast<size_t>(id)).validate());
|
OX_REQUIRE(inode, find(static_cast<size_t>(id)).validate());
|
||||||
return StatInfo {
|
return StatInfo {
|
||||||
id,
|
id,
|
||||||
inode->links,
|
inode->links,
|
||||||
@ -477,7 +477,7 @@ char *FileStoreTemplate<size_t>::buff() {
|
|||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
Error FileStoreTemplate<size_t>::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) {
|
Error FileStoreTemplate<size_t>::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) {
|
||||||
for (auto i = m_buffer->iterator(); i.valid(); i.next()) {
|
for (auto i = m_buffer->iterator(); i.valid(); i.next()) {
|
||||||
oxReturnError(cb(i->fileType, i.ptr().offset(), i.ptr().end()));
|
OX_RETURN_ERROR(cb(i->fileType, i.ptr().offset(), i.ptr().end()));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -546,7 +546,7 @@ Error FileStoreTemplate<size_t>::placeItem(ItemPtr item) {
|
|||||||
if (!fsData) {
|
if (!fsData) {
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
}
|
}
|
||||||
oxRequireM(root, m_buffer->ptr(fsData->rootNode).validate());
|
OX_REQUIRE_M(root, m_buffer->ptr(fsData->rootNode).validate());
|
||||||
if (root->id == item->id) {
|
if (root->id == item->id) {
|
||||||
fsData->rootNode = item;
|
fsData->rootNode = item;
|
||||||
item->left = root->left;
|
item->left = root->left;
|
||||||
@ -602,7 +602,7 @@ Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr item) {
|
|||||||
if (!fsData) {
|
if (!fsData) {
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
}
|
}
|
||||||
oxRequireM(root, m_buffer->ptr(fsData->rootNode).validate());
|
OX_REQUIRE_M(root, m_buffer->ptr(fsData->rootNode).validate());
|
||||||
if (root->id == item->id) {
|
if (root->id == item->id) {
|
||||||
item->left = root->left;
|
item->left = root->left;
|
||||||
item->right = root->right;
|
item->right = root->right;
|
||||||
@ -656,10 +656,10 @@ Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr root, ItemPtr item, int dep
|
|||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
}
|
}
|
||||||
if (item->right) {
|
if (item->right) {
|
||||||
oxReturnError(placeItem(m_buffer->ptr(item->right)));
|
OX_RETURN_ERROR(placeItem(m_buffer->ptr(item->right)));
|
||||||
}
|
}
|
||||||
if (item->left) {
|
if (item->left) {
|
||||||
oxReturnError(placeItem(m_buffer->ptr(item->left)));
|
OX_RETURN_ERROR(placeItem(m_buffer->ptr(item->left)));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -667,8 +667,8 @@ Error FileStoreTemplate<size_t>::unplaceItem(ItemPtr root, ItemPtr item, int dep
|
|||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
Error FileStoreTemplate<size_t>::remove(ItemPtr item) {
|
Error FileStoreTemplate<size_t>::remove(ItemPtr item) {
|
||||||
if (item.valid()) {
|
if (item.valid()) {
|
||||||
oxReturnError(unplaceItem(item));
|
OX_RETURN_ERROR(unplaceItem(item));
|
||||||
oxReturnError(m_buffer->free(item));
|
OX_RETURN_ERROR(m_buffer->free(item));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
|
32
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
32
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
@ -141,7 +141,7 @@ template<typename FileStore, typename InodeId_t>
|
|||||||
Error Directory<FileStore, InodeId_t>::init() noexcept {
|
Error Directory<FileStore, InodeId_t>::init() noexcept {
|
||||||
constexpr auto Size = sizeof(Buffer);
|
constexpr auto Size = sizeof(Buffer);
|
||||||
oxTracef("ox.fs.Directory.init", "Initializing Directory with Inode ID: {}", m_inodeId);
|
oxTracef("ox.fs.Directory.init", "Initializing Directory with Inode ID: {}", m_inodeId);
|
||||||
oxReturnError(m_fs.write(m_inodeId, nullptr, Size, static_cast<uint8_t>(FileType::Directory)));
|
OX_RETURN_ERROR(m_fs.write(m_inodeId, nullptr, Size, static_cast<uint8_t>(FileType::Directory)));
|
||||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||||
if (!buff.valid()) {
|
if (!buff.valid()) {
|
||||||
m_size = 0;
|
m_size = 0;
|
||||||
@ -158,7 +158,7 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents) {
|
|||||||
oxTrace("ox.fs.Directory.mkdir", path.fullPath());
|
oxTrace("ox.fs.Directory.mkdir", path.fullPath());
|
||||||
// determine if already exists
|
// determine if already exists
|
||||||
ox::StringView name;
|
ox::StringView name;
|
||||||
oxReturnError(path.get(name));
|
OX_RETURN_ERROR(path.get(name));
|
||||||
auto childInode = find(PathIterator(name));
|
auto childInode = find(PathIterator(name));
|
||||||
if (!childInode.ok()) {
|
if (!childInode.ok()) {
|
||||||
// if this is not the last item in the path and parents is disabled,
|
// if this is not the last item in the path and parents is disabled,
|
||||||
@ -169,10 +169,10 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents) {
|
|||||||
childInode = m_fs.generateInodeId();
|
childInode = m_fs.generateInodeId();
|
||||||
oxTracef("ox.fs.Directory.mkdir", "Generated Inode ID: {}", childInode.value);
|
oxTracef("ox.fs.Directory.mkdir", "Generated Inode ID: {}", childInode.value);
|
||||||
oxLogError(childInode.error);
|
oxLogError(childInode.error);
|
||||||
oxReturnError(childInode.error);
|
OX_RETURN_ERROR(childInode.error);
|
||||||
// initialize the directory
|
// initialize the directory
|
||||||
Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
|
Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
|
||||||
oxReturnError(child.init());
|
OX_RETURN_ERROR(child.init());
|
||||||
auto err = write(PathIterator(name), childInode.value);
|
auto err = write(PathIterator(name), childInode.value);
|
||||||
if (err) {
|
if (err) {
|
||||||
oxLogError(err);
|
oxLogError(err);
|
||||||
@ -183,7 +183,7 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents) {
|
|||||||
}
|
}
|
||||||
Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
|
Directory<FileStore, InodeId_t> child(m_fs, childInode.value);
|
||||||
if (path.hasNext()) {
|
if (path.hasNext()) {
|
||||||
oxReturnError(child.mkdir(path.next(), parents));
|
OX_RETURN_ERROR(child.mkdir(path.next(), parents));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
@ -196,8 +196,8 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, uint64_t inode64
|
|||||||
if (path.next().hasNext()) { // not yet at target directory, recurse to next one
|
if (path.next().hasNext()) { // not yet at target directory, recurse to next one
|
||||||
oxTracef("ox.fs.Directory.write", "Attempting to write to next sub-Directory: {} of {}",
|
oxTracef("ox.fs.Directory.write", "Attempting to write to next sub-Directory: {} of {}",
|
||||||
name, path.fullPath());
|
name, path.fullPath());
|
||||||
oxReturnError(path.get(name));
|
OX_RETURN_ERROR(path.get(name));
|
||||||
oxRequire(nextChild, findEntry(name));
|
OX_REQUIRE(nextChild, findEntry(name));
|
||||||
oxTracef("ox.fs.Directory.write", "{}: {}", name, nextChild);
|
oxTracef("ox.fs.Directory.write", "{}: {}", name, nextChild);
|
||||||
if (nextChild) {
|
if (nextChild) {
|
||||||
return Directory(m_fs, nextChild).write(path.next(), inode);
|
return Directory(m_fs, nextChild).write(path.next(), inode);
|
||||||
@ -207,12 +207,12 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, uint64_t inode64
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oxTrace("ox.fs.Directory.write", path.fullPath());
|
oxTrace("ox.fs.Directory.write", path.fullPath());
|
||||||
oxReturnError(path.next(name));
|
OX_RETURN_ERROR(path.next(name));
|
||||||
// insert the new entry on this directory
|
// insert the new entry on this directory
|
||||||
// get the name
|
// get the name
|
||||||
// find existing version of directory
|
// find existing version of directory
|
||||||
oxTracef("ox.fs.Directory.write", "Searching for directory inode {}", m_inodeId);
|
oxTracef("ox.fs.Directory.write", "Searching for directory inode {}", m_inodeId);
|
||||||
oxRequire(oldStat, m_fs.stat(m_inodeId));
|
OX_REQUIRE(oldStat, m_fs.stat(m_inodeId));
|
||||||
oxTracef("ox.fs.Directory.write", "Found existing directory of size {}", oldStat.size);
|
oxTracef("ox.fs.Directory.write", "Found existing directory of size {}", oldStat.size);
|
||||||
auto old = m_fs.read(m_inodeId).template to<Buffer>();
|
auto old = m_fs.read(m_inodeId).template to<Buffer>();
|
||||||
if (!old.valid()) {
|
if (!old.valid()) {
|
||||||
@ -227,14 +227,14 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, uint64_t inode64
|
|||||||
oxTrace("ox.fs.Directory.write.fail", "Could not allocate memory for copy of Directory");
|
oxTrace("ox.fs.Directory.write.fail", "Could not allocate memory for copy of Directory");
|
||||||
return ox::Error(1, "Could not allocate memory for copy of Directory");
|
return ox::Error(1, "Could not allocate memory for copy of Directory");
|
||||||
}
|
}
|
||||||
oxReturnError(cpy->setSize(newSize));
|
OX_RETURN_ERROR(cpy->setSize(newSize));
|
||||||
auto val = cpy->malloc(entryDataSize).value;
|
auto val = cpy->malloc(entryDataSize).value;
|
||||||
if (!val.valid()) {
|
if (!val.valid()) {
|
||||||
oxTrace("ox.fs.Directory.write.fail", "Could not allocate memory for new directory entry");
|
oxTrace("ox.fs.Directory.write.fail", "Could not allocate memory for new directory entry");
|
||||||
return ox::Error(1, "Could not allocate memory for new directory entry");
|
return ox::Error(1, "Could not allocate memory for new directory entry");
|
||||||
}
|
}
|
||||||
oxTracef("ox.fs.Directory.write", "Attempting to write Directory entry: {}", name);
|
oxTracef("ox.fs.Directory.write", "Attempting to write Directory entry: {}", name);
|
||||||
oxReturnError(val->init(inode, name, val.size()));
|
OX_RETURN_ERROR(val->init(inode, name, val.size()));
|
||||||
return m_fs.write(m_inodeId, cpy.get(), cpy->size(), static_cast<uint8_t>(FileType::Directory));
|
return m_fs.write(m_inodeId, cpy.get(), cpy->size(), static_cast<uint8_t>(FileType::Directory));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,7 +242,7 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, uint64_t inode64
|
|||||||
template<typename FileStore, typename InodeId_t>
|
template<typename FileStore, typename InodeId_t>
|
||||||
Error Directory<FileStore, InodeId_t>::remove(PathIterator path) noexcept {
|
Error Directory<FileStore, InodeId_t>::remove(PathIterator path) noexcept {
|
||||||
ox::StringView name;
|
ox::StringView name;
|
||||||
oxReturnError(path.get(name));
|
OX_RETURN_ERROR(path.get(name));
|
||||||
oxTrace("ox.fs.Directory.remove", name);
|
oxTrace("ox.fs.Directory.remove", name);
|
||||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||||
if (buff.valid()) {
|
if (buff.valid()) {
|
||||||
@ -251,7 +251,7 @@ Error Directory<FileStore, InodeId_t>::remove(PathIterator path) noexcept {
|
|||||||
auto data = i->data();
|
auto data = i->data();
|
||||||
if (data.valid()) {
|
if (data.valid()) {
|
||||||
if (name == data->name) {
|
if (name == data->name) {
|
||||||
oxReturnError(buff->free(i));
|
OX_RETURN_ERROR(buff->free(i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oxTrace("ox.fs.Directory.remove", "INVALID DIRECTORY ENTRY");
|
oxTrace("ox.fs.Directory.remove", "INVALID DIRECTORY ENTRY");
|
||||||
@ -277,7 +277,7 @@ Error Directory<FileStore, InodeId_t>::ls(F cb) noexcept {
|
|||||||
for (auto i = buff->iterator(); i.valid(); i.next()) {
|
for (auto i = buff->iterator(); i.valid(); i.next()) {
|
||||||
auto data = i->data();
|
auto data = i->data();
|
||||||
if (data.valid()) {
|
if (data.valid()) {
|
||||||
oxReturnError(cb(data->name, data->inode));
|
OX_RETURN_ERROR(cb(data->name, data->inode));
|
||||||
} else {
|
} else {
|
||||||
oxTrace("ox.fs.Directory.ls", "INVALID DIRECTORY ENTRY");
|
oxTrace("ox.fs.Directory.ls", "INVALID DIRECTORY ENTRY");
|
||||||
}
|
}
|
||||||
@ -314,8 +314,8 @@ template<typename FileStore, typename InodeId_t>
|
|||||||
Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::find(PathIterator path) const noexcept {
|
Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::find(PathIterator path) const noexcept {
|
||||||
// determine if already exists
|
// determine if already exists
|
||||||
ox::StringView name;
|
ox::StringView name;
|
||||||
oxReturnError(path.get(name));
|
OX_RETURN_ERROR(path.get(name));
|
||||||
oxRequire(v, findEntry(name));
|
OX_REQUIRE(v, findEntry(name));
|
||||||
// recurse if not at end of path
|
// recurse if not at end of path
|
||||||
if (auto p = path.next(); p.valid()) {
|
if (auto p = path.next(); p.valid()) {
|
||||||
Directory dir(m_fs, v);
|
Directory dir(m_fs, v);
|
||||||
|
22
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
22
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
@ -154,29 +154,29 @@ constexpr const char *getModelTypeName<FileAddress>() noexcept {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *h, CommonPtrWith<FileAddress::Data> auto *obj) noexcept {
|
constexpr Error model(T *h, CommonPtrWith<FileAddress::Data> auto *obj) noexcept {
|
||||||
oxReturnError(h->template setTypeInfo<FileAddress::Data>());
|
OX_RETURN_ERROR(h->template setTypeInfo<FileAddress::Data>());
|
||||||
oxReturnError(h->fieldCString("path", &obj->path));
|
OX_RETURN_ERROR(h->fieldCString("path", &obj->path));
|
||||||
oxReturnError(h->fieldCString("constPath", &obj->path));
|
OX_RETURN_ERROR(h->fieldCString("constPath", &obj->path));
|
||||||
oxReturnError(h->field("inode", &obj->inode));
|
OX_RETURN_ERROR(h->field("inode", &obj->inode));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *h, CommonPtrWith<FileAddress> auto *fa) noexcept {
|
constexpr Error model(T *h, CommonPtrWith<FileAddress> auto *fa) noexcept {
|
||||||
oxReturnError(h->template setTypeInfo<FileAddress>());
|
OX_RETURN_ERROR(h->template setTypeInfo<FileAddress>());
|
||||||
if constexpr(T::opType() == OpType::Reflect) {
|
if constexpr(T::opType() == OpType::Reflect) {
|
||||||
int8_t type = -1;
|
int8_t type = -1;
|
||||||
oxReturnError(h->field("type", &type));
|
OX_RETURN_ERROR(h->field("type", &type));
|
||||||
oxReturnError(h->field("data", UnionView(&fa->m_data, type)));
|
OX_RETURN_ERROR(h->field("data", UnionView(&fa->m_data, type)));
|
||||||
} else if constexpr(T::opType() == OpType::Read) {
|
} else if constexpr(T::opType() == OpType::Read) {
|
||||||
auto type = static_cast<int8_t>(fa->m_type);
|
auto type = static_cast<int8_t>(fa->m_type);
|
||||||
oxReturnError(h->field("type", &type));
|
OX_RETURN_ERROR(h->field("type", &type));
|
||||||
fa->m_type = static_cast<FileAddressType>(type);
|
fa->m_type = static_cast<FileAddressType>(type);
|
||||||
oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
OX_RETURN_ERROR(h->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||||
} else if constexpr(T::opType() == OpType::Write) {
|
} else if constexpr(T::opType() == OpType::Write) {
|
||||||
auto const type = static_cast<int8_t>(fa->m_type);
|
auto const type = static_cast<int8_t>(fa->m_type);
|
||||||
oxReturnError(h->field("type", &type));
|
OX_RETURN_ERROR(h->field("type", &type));
|
||||||
oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
OX_RETURN_ERROR(h->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
8
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
8
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
@ -38,16 +38,16 @@ Error FileSystem::read(const FileAddress &addr, void *buffer, std::size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result<Buffer> FileSystem::read(const FileAddress &addr) noexcept {
|
Result<Buffer> FileSystem::read(const FileAddress &addr) noexcept {
|
||||||
oxRequire(s, stat(addr));
|
OX_REQUIRE(s, stat(addr));
|
||||||
Buffer buff(static_cast<std::size_t>(s.size));
|
Buffer buff(static_cast<std::size_t>(s.size));
|
||||||
oxReturnError(read(addr, buff.data(), buff.size()));
|
OX_RETURN_ERROR(read(addr, buff.data(), buff.size()));
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Buffer> FileSystem::read(StringViewCR path) noexcept {
|
Result<Buffer> FileSystem::read(StringViewCR path) noexcept {
|
||||||
oxRequire(s, statPath(path));
|
OX_REQUIRE(s, statPath(path));
|
||||||
Buffer buff(static_cast<std::size_t>(s.size));
|
Buffer buff(static_cast<std::size_t>(s.size));
|
||||||
oxReturnError(readFilePath(path, buff.data(), buff.size()));
|
OX_RETURN_ERROR(readFilePath(path, buff.data(), buff.size()));
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
58
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -284,17 +284,17 @@ FileSystemTemplate<FileStore, Directory>::~FileSystemTemplate() noexcept {
|
|||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::format(void *buff, uint64_t buffSize) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::format(void *buff, uint64_t buffSize) noexcept {
|
||||||
oxReturnError(FileStore::format(buff, static_cast<size_t>(buffSize)));
|
OX_RETURN_ERROR(FileStore::format(buff, static_cast<size_t>(buffSize)));
|
||||||
FileStore fs(buff, static_cast<size_t>(buffSize));
|
FileStore fs(buff, static_cast<size_t>(buffSize));
|
||||||
|
|
||||||
constexpr auto rootDirInode = MaxValue<typename FileStore::InodeId_t> / 2;
|
constexpr auto rootDirInode = MaxValue<typename FileStore::InodeId_t> / 2;
|
||||||
Directory rootDir(fs, rootDirInode);
|
Directory rootDir(fs, rootDirInode);
|
||||||
oxReturnError(rootDir.init());
|
OX_RETURN_ERROR(rootDir.init());
|
||||||
|
|
||||||
FileSystemData fd;
|
FileSystemData fd;
|
||||||
fd.rootDirInode = rootDirInode;
|
fd.rootDirInode = rootDirInode;
|
||||||
oxTracef("ox.fs.FileSystemTemplate.format", "rootDirInode: {}", fd.rootDirInode.get());
|
oxTracef("ox.fs.FileSystemTemplate.format", "rootDirInode: {}", fd.rootDirInode.get());
|
||||||
oxReturnError(fs.write(InodeFsData, &fd, sizeof(fd)));
|
OX_RETURN_ERROR(fs.write(InodeFsData, &fd, sizeof(fd)));
|
||||||
|
|
||||||
if (!fs.read(fd.rootDirInode).valid()) {
|
if (!fs.read(fd.rootDirInode).valid()) {
|
||||||
oxTrace("ox.fs.FileSystemTemplate.format.error", "FileSystemTemplate::format did not correctly create root directory");
|
oxTrace("ox.fs.FileSystemTemplate.format.error", "FileSystemTemplate::format did not correctly create root directory");
|
||||||
@ -307,26 +307,26 @@ Error FileSystemTemplate<FileStore, Directory>::format(void *buff, uint64_t buff
|
|||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::mkdir(StringViewCR path, bool recursive) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::mkdir(StringViewCR path, bool recursive) noexcept {
|
||||||
oxTracef("ox.fs.FileSystemTemplate.mkdir", "path: {}, recursive: {}", path, recursive);
|
oxTracef("ox.fs.FileSystemTemplate.mkdir", "path: {}, recursive: {}", path, recursive);
|
||||||
oxRequireM(rootDir, this->rootDir());
|
OX_REQUIRE_M(rootDir, this->rootDir());
|
||||||
return rootDir.mkdir(path, recursive);
|
return rootDir.mkdir(path, recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::move(StringViewCR src, StringViewCR dest) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::move(StringViewCR src, StringViewCR dest) noexcept {
|
||||||
oxRequire(fd, fileSystemData());
|
OX_REQUIRE(fd, fileSystemData());
|
||||||
Directory rootDir(m_fs, fd.rootDirInode);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
oxRequireM(inode, rootDir.find(src));
|
OX_REQUIRE_M(inode, rootDir.find(src));
|
||||||
oxReturnError(rootDir.write(dest, inode));
|
OX_RETURN_ERROR(rootDir.write(dest, inode));
|
||||||
oxReturnError(rootDir.remove(src));
|
OX_RETURN_ERROR(rootDir.remove(src));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::readFilePath(StringViewCR path, void *buffer, std::size_t buffSize) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::readFilePath(StringViewCR path, void *buffer, std::size_t buffSize) noexcept {
|
||||||
oxTrace("ox.fs.FileSystemTemplate.readFilePath", path);
|
oxTrace("ox.fs.FileSystemTemplate.readFilePath", path);
|
||||||
oxRequire(fd, fileSystemData());
|
OX_REQUIRE(fd, fileSystemData());
|
||||||
Directory rootDir(m_fs, fd.rootDirInode);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
oxRequire(s, stat(path));
|
OX_REQUIRE(s, stat(path));
|
||||||
if (s.size > buffSize) {
|
if (s.size > buffSize) {
|
||||||
return ox::Error(1, "Buffer to small to load file");
|
return ox::Error(1, "Buffer to small to load file");
|
||||||
}
|
}
|
||||||
@ -335,16 +335,16 @@ Error FileSystemTemplate<FileStore, Directory>::readFilePath(StringViewCR path,
|
|||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccessPath(StringViewCR path) const noexcept {
|
Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccessPath(StringViewCR path) const noexcept {
|
||||||
oxRequire(fd, fileSystemData());
|
OX_REQUIRE(fd, fileSystemData());
|
||||||
Directory rootDir(m_fs, fd.rootDirInode);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
oxRequire(inode, rootDir.find(path));
|
OX_REQUIRE(inode, rootDir.find(path));
|
||||||
return directAccessInode(inode);
|
return directAccessInode(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::readFileInode(uint64_t inode, void *buffer, std::size_t buffSize) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::readFileInode(uint64_t inode, void *buffer, std::size_t buffSize) noexcept {
|
||||||
oxTracef("ox.fs.FileSystemTemplate.readFileInode", "{}", inode);
|
oxTracef("ox.fs.FileSystemTemplate.readFileInode", "{}", inode);
|
||||||
oxRequire(s, stat(inode));
|
OX_REQUIRE(s, stat(inode));
|
||||||
if (s.size > buffSize) {
|
if (s.size > buffSize) {
|
||||||
return ox::Error(1, "Buffer to small to load file");
|
return ox::Error(1, "Buffer to small to load file");
|
||||||
}
|
}
|
||||||
@ -368,7 +368,7 @@ Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccessInode(
|
|||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<Vector<String>> FileSystemTemplate<FileStore, Directory>::ls(StringViewCR path) const noexcept {
|
Result<Vector<String>> FileSystemTemplate<FileStore, Directory>::ls(StringViewCR path) const noexcept {
|
||||||
Vector<String> out;
|
Vector<String> out;
|
||||||
oxReturnError(ls(path, [&out](StringViewCR name, typename FileStore::InodeId_t) {
|
OX_RETURN_ERROR(ls(path, [&out](StringViewCR name, typename FileStore::InodeId_t) {
|
||||||
out.emplace_back(name);
|
out.emplace_back(name);
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}));
|
}));
|
||||||
@ -379,17 +379,17 @@ template<typename FileStore, typename Directory>
|
|||||||
template<typename F>
|
template<typename F>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::ls(StringViewCR path, F cb) const {
|
Error FileSystemTemplate<FileStore, Directory>::ls(StringViewCR path, F cb) const {
|
||||||
oxTracef("ox.fs.FileSystemTemplate.ls", "path: {}", path);
|
oxTracef("ox.fs.FileSystemTemplate.ls", "path: {}", path);
|
||||||
oxRequire(s, stat(path));
|
OX_REQUIRE(s, stat(path));
|
||||||
Directory dir(m_fs, s.inode);
|
Directory dir(m_fs, s.inode);
|
||||||
return dir.ls(cb);
|
return dir.ls(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::remove(StringViewCR path, bool recursive) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::remove(StringViewCR path, bool recursive) noexcept {
|
||||||
oxRequire(fd, fileSystemData());
|
OX_REQUIRE(fd, fileSystemData());
|
||||||
Directory rootDir(m_fs, fd.rootDirInode);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
oxRequire(inode, rootDir.find(path));
|
OX_REQUIRE(inode, rootDir.find(path));
|
||||||
oxRequire(st, statInode(inode));
|
OX_REQUIRE(st, statInode(inode));
|
||||||
if (st.fileType == FileType::NormalFile || recursive) {
|
if (st.fileType == FileType::NormalFile || recursive) {
|
||||||
if (auto err = rootDir.remove(path)) {
|
if (auto err = rootDir.remove(path)) {
|
||||||
// removal failed, try putting the index back
|
// removal failed, try putting the index back
|
||||||
@ -410,7 +410,7 @@ Error FileSystemTemplate<FileStore, Directory>::resize() noexcept {
|
|||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::resize(uint64_t size, void *buffer) noexcept {
|
Error FileSystemTemplate<FileStore, Directory>::resize(uint64_t size, void *buffer) noexcept {
|
||||||
oxReturnError(m_fs.resize(static_cast<size_t>(size), buffer));
|
OX_RETURN_ERROR(m_fs.resize(static_cast<size_t>(size), buffer));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,11 +423,11 @@ Error FileSystemTemplate<FileStore, Directory>::writeFilePath(
|
|||||||
oxTrace("ox.fs.FileSystemTemplate.writeFilePath", path);
|
oxTrace("ox.fs.FileSystemTemplate.writeFilePath", path);
|
||||||
auto [inode, err] = find(path);
|
auto [inode, err] = find(path);
|
||||||
if (err) {
|
if (err) {
|
||||||
oxReturnError(m_fs.generateInodeId().moveTo(inode));
|
OX_RETURN_ERROR(m_fs.generateInodeId().moveTo(inode));
|
||||||
oxRequireM(rootDir, this->rootDir());
|
OX_REQUIRE_M(rootDir, this->rootDir());
|
||||||
oxReturnError(rootDir.write(path, inode));
|
OX_RETURN_ERROR(rootDir.write(path, inode));
|
||||||
}
|
}
|
||||||
oxReturnError(writeFileInode(inode, buffer, size, fileType));
|
OX_RETURN_ERROR(writeFileInode(inode, buffer, size, fileType));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, c
|
|||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::statInode(uint64_t inode) const noexcept {
|
Result<FileStat> FileSystemTemplate<FileStore, Directory>::statInode(uint64_t inode) const noexcept {
|
||||||
oxRequire(s, m_fs.stat(inode));
|
OX_REQUIRE(s, m_fs.stat(inode));
|
||||||
FileStat out;
|
FileStat out;
|
||||||
out.inode = s.inode;
|
out.inode = s.inode;
|
||||||
out.links = s.links;
|
out.links = s.links;
|
||||||
@ -450,7 +450,7 @@ Result<FileStat> FileSystemTemplate<FileStore, Directory>::statInode(uint64_t in
|
|||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::statPath(StringViewCR path) const noexcept {
|
Result<FileStat> FileSystemTemplate<FileStore, Directory>::statPath(StringViewCR path) const noexcept {
|
||||||
oxRequire(inode, find(path));
|
OX_REQUIRE(inode, find(path));
|
||||||
return stat(inode);
|
return stat(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,25 +487,25 @@ bool FileSystemTemplate<FileStore, Directory>::valid() const noexcept {
|
|||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSystemTemplate<FileStore, Directory>::fileSystemData() const noexcept {
|
Result<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSystemTemplate<FileStore, Directory>::fileSystemData() const noexcept {
|
||||||
FileSystemData fd;
|
FileSystemData fd;
|
||||||
oxReturnError(m_fs.read(InodeFsData, &fd, sizeof(fd)));
|
OX_RETURN_ERROR(m_fs.read(InodeFsData, &fd, sizeof(fd)));
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<uint64_t> FileSystemTemplate<FileStore, Directory>::find(StringViewCR path) const noexcept {
|
Result<uint64_t> FileSystemTemplate<FileStore, Directory>::find(StringViewCR path) const noexcept {
|
||||||
oxRequire(fd, fileSystemData());
|
OX_REQUIRE(fd, fileSystemData());
|
||||||
// return root as a special case
|
// return root as a special case
|
||||||
if (path == "/") {
|
if (path == "/") {
|
||||||
return static_cast<uint64_t>(fd.rootDirInode);
|
return static_cast<uint64_t>(fd.rootDirInode);
|
||||||
}
|
}
|
||||||
Directory rootDir(m_fs, fd.rootDirInode);
|
Directory rootDir(m_fs, fd.rootDirInode);
|
||||||
oxRequire(out, rootDir.find(path));
|
OX_REQUIRE(out, rootDir.find(path));
|
||||||
return static_cast<uint64_t>(out);
|
return static_cast<uint64_t>(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<Directory> FileSystemTemplate<FileStore, Directory>::rootDir() const noexcept {
|
Result<Directory> FileSystemTemplate<FileStore, Directory>::rootDir() const noexcept {
|
||||||
oxRequire(fd, fileSystemData());
|
OX_REQUIRE(fd, fileSystemData());
|
||||||
return Directory(m_fs, fd.rootDirInode);
|
return Directory(m_fs, fd.rootDirInode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
12
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
@ -39,7 +39,7 @@ Error PassThroughFS::mkdir(StringViewCR path, bool recursive) noexcept {
|
|||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
success = std::filesystem::create_directories(p, ec);
|
success = std::filesystem::create_directories(p, ec);
|
||||||
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
|
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
@ -48,7 +48,7 @@ Error PassThroughFS::mkdir(StringViewCR path, bool recursive) noexcept {
|
|||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
success = std::filesystem::create_directory(p, ec);
|
success = std::filesystem::create_directory(p, ec);
|
||||||
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
|
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ox::Error(success ? 0 : 1);
|
return ox::Error(success ? 0 : 1);
|
||||||
@ -67,7 +67,7 @@ Result<Vector<String>> PassThroughFS::ls(StringViewCR dir) const noexcept {
|
|||||||
Vector<String> out;
|
Vector<String> out;
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
|
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
|
||||||
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
|
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
|
||||||
for (const auto &p : di) {
|
for (const auto &p : di) {
|
||||||
const auto u8p = p.path().filename().u8string();
|
const auto u8p = p.path().filename().u8string();
|
||||||
out.emplace_back(reinterpret_cast<const char*>(u8p.c_str()));
|
out.emplace_back(reinterpret_cast<const char*>(u8p.c_str()));
|
||||||
@ -101,7 +101,7 @@ Result<FileStat> PassThroughFS::statPath(StringViewCR path) const noexcept {
|
|||||||
oxTracef("ox.fs.PassThroughFS.statInode", "{} {}", ec.message(), path);
|
oxTracef("ox.fs.PassThroughFS.statInode", "{} {}", ec.message(), path);
|
||||||
const uint64_t size = type == FileType::Directory ? 0 : std::filesystem::file_size(p, ec);
|
const uint64_t size = type == FileType::Directory ? 0 : std::filesystem::file_size(p, ec);
|
||||||
oxTracef("ox.fs.PassThroughFS.statInode.size", "{} {}", path, size);
|
oxTracef("ox.fs.PassThroughFS.statInode.size", "{} {}", path, size);
|
||||||
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: stat failed"));
|
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: stat failed"));
|
||||||
return FileStat{0, 0, size, type};
|
return FileStat{0, 0, size, type};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,14 +112,14 @@ uint64_t PassThroughFS::spaceNeeded(uint64_t size) const noexcept {
|
|||||||
Result<uint64_t> PassThroughFS::available() const noexcept {
|
Result<uint64_t> PassThroughFS::available() const noexcept {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const auto s = std::filesystem::space(m_path, ec);
|
const auto s = std::filesystem::space(m_path, ec);
|
||||||
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
|
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
|
||||||
return s.available;
|
return s.available;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<uint64_t> PassThroughFS::size() const noexcept {
|
Result<uint64_t> PassThroughFS::size() const noexcept {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const auto s = std::filesystem::space(m_path, ec);
|
const auto s = std::filesystem::space(m_path, ec);
|
||||||
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
|
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
|
||||||
return s.capacity;
|
return s.capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +92,9 @@ template<typename F>
|
|||||||
Error PassThroughFS::ls(StringViewCR dir, F cb) const noexcept {
|
Error PassThroughFS::ls(StringViewCR dir, F cb) const noexcept {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
|
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
|
||||||
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
|
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
|
||||||
for (auto &p : di) {
|
for (auto &p : di) {
|
||||||
oxReturnError(cb(p.path().filename().c_str(), 0));
|
OX_RETURN_ERROR(cb(p.path().filename().c_str(), 0));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
2
deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp
vendored
2
deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp
vendored
@ -408,7 +408,7 @@ Error NodeBuffer<size_t, Item>::compact(F cb) noexcept {
|
|||||||
}
|
}
|
||||||
// move node
|
// move node
|
||||||
ox::memcpy(dest, src, src->fullSize());
|
ox::memcpy(dest, src, src->fullSize());
|
||||||
oxReturnError(cb(src, dest));
|
OX_RETURN_ERROR(cb(src, dest));
|
||||||
// update surrounding nodes
|
// update surrounding nodes
|
||||||
auto prev = ptr(dest->prev);
|
auto prev = ptr(dest->prev);
|
||||||
if (prev.valid()) {
|
if (prev.valid()) {
|
||||||
|
8
deps/ox/src/ox/fs/tool.cpp
vendored
8
deps/ox/src/ox/fs/tool.cpp
vendored
@ -35,7 +35,7 @@ static ox::Result<Buff> loadFsBuff(const char *path) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ox::Result<ox::UniquePtr<ox::FileSystem>> loadFs(const char *path) noexcept {
|
static ox::Result<ox::UniquePtr<ox::FileSystem>> loadFs(const char *path) noexcept {
|
||||||
oxRequire(buff, loadFsBuff(path));
|
OX_REQUIRE(buff, loadFsBuff(path));
|
||||||
return {ox::make_unique<ox::FileSystem32>(buff.data, buff.size)};
|
return {ox::make_unique<ox::FileSystem32>(buff.data, buff.size)};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ static ox::Error runLs(ox::FileSystem *fs, ox::Span<const char*> args) noexcept
|
|||||||
oxErr("Must provide a directory to ls\n");
|
oxErr("Must provide a directory to ls\n");
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
}
|
}
|
||||||
oxRequire(files, fs->ls(args[1]));
|
OX_REQUIRE(files, fs->ls(args[1]));
|
||||||
for (const auto &file : files) {
|
for (const auto &file : files) {
|
||||||
oxOutf("{}\n", file);
|
oxOutf("{}\n", file);
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ static ox::Error runRead(ox::FileSystem *fs, ox::Span<const char*> args) noexcep
|
|||||||
oxErr("Must provide a path to a file to read\n");
|
oxErr("Must provide a path to a file to read\n");
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
}
|
}
|
||||||
oxRequire(buff, fs->read(ox::StringView(args[1])));
|
OX_REQUIRE(buff, fs->read(ox::StringView(args[1])));
|
||||||
std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout);
|
std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout);
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ static ox::Error run(int argc, const char **argv) noexcept {
|
|||||||
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
|
||||||
auto const fsPath = args[1];
|
auto const fsPath = args[1];
|
||||||
ox::String subCmd(args[2]);
|
ox::String subCmd(args[2]);
|
||||||
oxRequire(fs, loadFs(fsPath));
|
OX_REQUIRE(fs, loadFs(fsPath));
|
||||||
if (subCmd == "ls") {
|
if (subCmd == "ls") {
|
||||||
return runLs(fs.get(), args + 2);
|
return runLs(fs.get(), args + 2);
|
||||||
} else if (subCmd == "read") {
|
} else if (subCmd == "read") {
|
||||||
|
2
deps/ox/src/ox/logconn/logconn.cpp
vendored
2
deps/ox/src/ox/logconn/logconn.cpp
vendored
@ -64,7 +64,7 @@ ox::Error LoggerConn::initConn(ox::StringViewCR appName) noexcept {
|
|||||||
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||||
addr.sin_port = htons(5590);
|
addr.sin_port = htons(5590);
|
||||||
m_socket = static_cast<int>(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
|
m_socket = static_cast<int>(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
|
||||||
oxReturnError(ox::Error(static_cast<ox::ErrorCode>(connect(static_cast<Socket>(m_socket), reinterpret_cast<sockaddr*>(&addr), sizeof(addr)))));
|
OX_RETURN_ERROR(ox::Error(static_cast<ox::ErrorCode>(connect(static_cast<Socket>(m_socket), reinterpret_cast<sockaddr*>(&addr), sizeof(addr)))));
|
||||||
return sendInit({.appName = ox::BasicString<128>(appName)});
|
return sendInit({.appName = ox::BasicString<128>(appName)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
deps/ox/src/ox/logconn/logconn.hpp
vendored
10
deps/ox/src/ox/logconn/logconn.hpp
vendored
@ -45,13 +45,13 @@ class LoggerConn: public trace::Logger {
|
|||||||
ox::Error send(trace::MsgId msgId, const auto &msg) noexcept {
|
ox::Error send(trace::MsgId msgId, const auto &msg) noexcept {
|
||||||
ox::Array<char, 10 * ox::units::KB> buff;
|
ox::Array<char, 10 * ox::units::KB> buff;
|
||||||
std::size_t sz = 0;
|
std::size_t sz = 0;
|
||||||
oxReturnError(ox::writeMC(&buff[0], buff.size(), msg, &sz));
|
OX_RETURN_ERROR(ox::writeMC(&buff[0], buff.size(), msg, &sz));
|
||||||
//std::printf("sz: %lu\n", sz);
|
//std::printf("sz: %lu\n", sz);
|
||||||
oxRequire(szBuff, serialize(static_cast<uint32_t>(sz)));
|
OX_REQUIRE(szBuff, serialize(static_cast<uint32_t>(sz)));
|
||||||
std::unique_lock buffLk(m_buffMut);
|
std::unique_lock buffLk(m_buffMut);
|
||||||
oxReturnError(m_buff.put(static_cast<char>(msgId)));
|
OX_RETURN_ERROR(m_buff.put(static_cast<char>(msgId)));
|
||||||
oxReturnError(m_buff.write(szBuff.data(), szBuff.size()));
|
OX_RETURN_ERROR(m_buff.write(szBuff.data(), szBuff.size()));
|
||||||
oxReturnError(m_buff.write(buff.data(), sz));
|
OX_RETURN_ERROR(m_buff.write(buff.data(), sz));
|
||||||
buffLk.unlock();
|
buffLk.unlock();
|
||||||
m_waitCond.notify_one();
|
m_waitCond.notify_one();
|
||||||
return {};
|
return {};
|
||||||
|
10
deps/ox/src/ox/mc/intops.hpp
vendored
10
deps/ox/src/ox/mc/intops.hpp
vendored
@ -135,19 +135,19 @@ static_assert(countBytes(0b1111'1111) == 9);
|
|||||||
template<typename I>
|
template<typename I>
|
||||||
constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noexcept {
|
constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noexcept {
|
||||||
uint8_t firstByte = 0;
|
uint8_t firstByte = 0;
|
||||||
oxReturnError(rdr.read(&firstByte, 1));
|
OX_RETURN_ERROR(rdr.read(&firstByte, 1));
|
||||||
oxReturnError(rdr.seekg(-1, ox::ios_base::cur));
|
OX_RETURN_ERROR(rdr.seekg(-1, ox::ios_base::cur));
|
||||||
const auto bytes = countBytes(firstByte);
|
const auto bytes = countBytes(firstByte);
|
||||||
if (bytes == 9) {
|
if (bytes == 9) {
|
||||||
*bytesRead = bytes;
|
*bytesRead = bytes;
|
||||||
I out = 0;
|
I out = 0;
|
||||||
oxReturnError(rdr.seekg(1, ox::ios_base::cur));
|
OX_RETURN_ERROR(rdr.seekg(1, ox::ios_base::cur));
|
||||||
oxReturnError(rdr.read(&out, sizeof(I)));
|
OX_RETURN_ERROR(rdr.read(&out, sizeof(I)));
|
||||||
return fromLittleEndian<I>(out);
|
return fromLittleEndian<I>(out);
|
||||||
}
|
}
|
||||||
*bytesRead = bytes;
|
*bytesRead = bytes;
|
||||||
uint64_t decoded = 0;
|
uint64_t decoded = 0;
|
||||||
oxReturnError(rdr.read(&decoded, bytes));
|
OX_RETURN_ERROR(rdr.read(&decoded, bytes));
|
||||||
decoded >>= bytes;
|
decoded >>= bytes;
|
||||||
// move sign bit
|
// move sign bit
|
||||||
if constexpr(is_signed_v<I>) {
|
if constexpr(is_signed_v<I>) {
|
||||||
|
10
deps/ox/src/ox/mc/presenceindicator.hpp
vendored
10
deps/ox/src/ox/mc/presenceindicator.hpp
vendored
@ -47,7 +47,7 @@ constexpr Result<bool> FieldBitmapReader<Reader>::get(std::size_t idx) const noe
|
|||||||
constexpr auto blockBits = sizeof(m_mapBlock);
|
constexpr auto blockBits = sizeof(m_mapBlock);
|
||||||
auto const blockIdx = idx / blockBits;
|
auto const blockIdx = idx / blockBits;
|
||||||
if (m_mapBlockIdx != blockIdx) [[unlikely]] {
|
if (m_mapBlockIdx != blockIdx) [[unlikely]] {
|
||||||
oxReturnError(loadMapBlock(blockIdx));
|
OX_RETURN_ERROR(loadMapBlock(blockIdx));
|
||||||
}
|
}
|
||||||
idx %= blockBits;
|
idx %= blockBits;
|
||||||
return (m_mapBlock >> idx) & 1;
|
return (m_mapBlock >> idx) & 1;
|
||||||
@ -55,12 +55,12 @@ constexpr Result<bool> FieldBitmapReader<Reader>::get(std::size_t idx) const noe
|
|||||||
|
|
||||||
template<Reader_c Reader>
|
template<Reader_c Reader>
|
||||||
constexpr ox::Error FieldBitmapReader<Reader>::loadMapBlock(std::size_t idx) const noexcept {
|
constexpr ox::Error FieldBitmapReader<Reader>::loadMapBlock(std::size_t idx) const noexcept {
|
||||||
oxRequire(g, m_reader.tellg());
|
OX_REQUIRE(g, m_reader.tellg());
|
||||||
oxReturnError(m_reader.seekg(static_cast<int>(m_mapStart + idx), ox::ios_base::beg));
|
OX_RETURN_ERROR(m_reader.seekg(static_cast<int>(m_mapStart + idx), ox::ios_base::beg));
|
||||||
ox::Array<char, sizeof(m_mapBlock)> mapBlock{};
|
ox::Array<char, sizeof(m_mapBlock)> mapBlock{};
|
||||||
oxReturnError(m_reader.read(mapBlock.data(), sizeof(m_mapBlock)));
|
OX_RETURN_ERROR(m_reader.read(mapBlock.data(), sizeof(m_mapBlock)));
|
||||||
// Warning: narrow-conv
|
// Warning: narrow-conv
|
||||||
oxReturnError(m_reader.seekg(static_cast<int>(g), ox::ios_base::beg));
|
OX_RETURN_ERROR(m_reader.seekg(static_cast<int>(g), ox::ios_base::beg));
|
||||||
m_mapBlock = 0;
|
m_mapBlock = 0;
|
||||||
for (auto i = 0ull; auto b : mapBlock) {
|
for (auto i = 0ull; auto b : mapBlock) {
|
||||||
m_mapBlock |= static_cast<uint64_t>(std::bit_cast<uint8_t>(b)) << i;
|
m_mapBlock |= static_cast<uint64_t>(std::bit_cast<uint8_t>(b)) << i;
|
||||||
|
76
deps/ox/src/ox/mc/read.hpp
vendored
76
deps/ox/src/ox/mc/read.hpp
vendored
@ -194,7 +194,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, bool *val) n
|
|||||||
if (!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) {
|
if (!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) {
|
||||||
auto const result = m_fieldPresence.get(static_cast<std::size_t>(m_field));
|
auto const result = m_fieldPresence.get(static_cast<std::size_t>(m_field));
|
||||||
*val = result.value;
|
*val = result.value;
|
||||||
oxReturnError(result);
|
OX_RETURN_ERROR(result);
|
||||||
}
|
}
|
||||||
++m_field;
|
++m_field;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
@ -207,15 +207,15 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, auto *v
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(len, mc::decodeInteger<ArrayLength>(m_reader, &bytesRead));
|
OX_REQUIRE(len, mc::decodeInteger<ArrayLength>(m_reader, &bytesRead));
|
||||||
// read the list
|
// read the list
|
||||||
if (valLen >= len) {
|
if (valLen >= len) {
|
||||||
auto reader = child({});
|
auto reader = child({});
|
||||||
auto &handler = *reader.interface();
|
auto &handler = *reader.interface();
|
||||||
oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
|
OX_RETURN_ERROR(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
oxReturnError(handler.field({}, &val[i]));
|
OX_RETURN_ERROR(handler.field({}, &val[i]));
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -234,24 +234,24 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, HashMap<Stri
|
|||||||
if (!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) {
|
if (!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) {
|
||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
oxRequire(g, m_reader.tellg());
|
OX_REQUIRE(g, m_reader.tellg());
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(len, mc::decodeInteger<ArrayLength>(m_reader, &bytesRead));
|
OX_REQUIRE(len, mc::decodeInteger<ArrayLength>(m_reader, &bytesRead));
|
||||||
oxReturnError(m_reader.seekg(g));
|
OX_RETURN_ERROR(m_reader.seekg(g));
|
||||||
// read the list
|
// read the list
|
||||||
auto reader = child("");
|
auto reader = child("");
|
||||||
auto &handler = *reader.interface();
|
auto &handler = *reader.interface();
|
||||||
oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
|
OX_RETURN_ERROR(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
|
||||||
// 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 &val) {
|
constexpr auto loopBody = [](auto &handler, auto &val) {
|
||||||
oxRequire(keyLen, handler.stringLength(nullptr));
|
OX_REQUIRE(keyLen, handler.stringLength(nullptr));
|
||||||
auto wkey = ox_malloca(keyLen + 1, char, 0);
|
auto wkey = ox_malloca(keyLen + 1, char, 0);
|
||||||
auto wkeyPtr = wkey.get();
|
auto wkeyPtr = wkey.get();
|
||||||
oxReturnError(handler.fieldCString("", &wkeyPtr, keyLen + 1));
|
OX_RETURN_ERROR(handler.fieldCString("", &wkeyPtr, keyLen + 1));
|
||||||
return handler.field("", &val[wkeyPtr]);
|
return handler.field("", &val[wkeyPtr]);
|
||||||
};
|
};
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
oxReturnError(loopBody(handler, *val));
|
OX_RETURN_ERROR(loopBody(handler, *val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -266,11 +266,11 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, T *val)
|
|||||||
if (!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) {
|
if (!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) {
|
||||||
// set size of val if the field is present, don't worry about it if not
|
// set size of val if the field is present, don't worry about it if not
|
||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
oxRequire(len, arrayLength(name, false));
|
OX_REQUIRE(len, arrayLength(name, false));
|
||||||
oxReturnError(ox::resizeVector(*val, len));
|
OX_RETURN_ERROR(ox::resizeVector(*val, len));
|
||||||
return field(name, val->data(), val->size());
|
return field(name, val->data(), val->size());
|
||||||
}
|
}
|
||||||
oxReturnError(ox::resizeVector(*val, 0));
|
OX_RETURN_ERROR(ox::resizeVector(*val, 0));
|
||||||
}
|
}
|
||||||
++m_field;
|
++m_field;
|
||||||
return {};
|
return {};
|
||||||
@ -278,7 +278,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, T *val)
|
|||||||
if (!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) {
|
if (!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) {
|
||||||
// set size of val if the field is present, don't worry about it if not
|
// set size of val if the field is present, don't worry about it if not
|
||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
oxRequire(len, arrayLength(name, false));
|
OX_REQUIRE(len, arrayLength(name, false));
|
||||||
if (len > val->size()) {
|
if (len > val->size()) {
|
||||||
return ox::Error(1, "Input array is too long");
|
return ox::Error(1, "Input array is too long");
|
||||||
}
|
}
|
||||||
@ -291,7 +291,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, T *val)
|
|||||||
if ((!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) && val) {
|
if ((!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) && val) {
|
||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
auto reader = child("");
|
auto reader = child("");
|
||||||
oxReturnError(model(reader.interface(), val));
|
OX_RETURN_ERROR(model(reader.interface(), val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++m_field;
|
++m_field;
|
||||||
@ -305,7 +305,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, UnionView<U,
|
|||||||
if ((!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) && val.get()) {
|
if ((!m_unionIdx.has_value() || static_cast<std::size_t>(*m_unionIdx) == m_field) && val.get()) {
|
||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
auto reader = child("", ox::Optional<int>(ox::in_place, val.idx()));
|
auto reader = child("", ox::Optional<int>(ox::in_place, val.idx()));
|
||||||
oxReturnError(model(reader.interface(), val.get()));
|
OX_RETURN_ERROR(model(reader.interface(), val.get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++m_field;
|
++m_field;
|
||||||
@ -319,12 +319,12 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, BasicString<
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
OX_REQUIRE(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
||||||
const auto cap = size;
|
const auto cap = size;
|
||||||
*val = BasicString<SmallStringSize>(cap);
|
*val = BasicString<SmallStringSize>(cap);
|
||||||
auto data = val->data();
|
auto data = val->data();
|
||||||
// read the string
|
// read the string
|
||||||
oxReturnError(m_reader.read(data, size));
|
OX_RETURN_ERROR(m_reader.read(data, size));
|
||||||
} else {
|
} else {
|
||||||
*val = "";
|
*val = "";
|
||||||
}
|
}
|
||||||
@ -340,12 +340,12 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, IString<L> *
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
OX_REQUIRE(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
||||||
*val = IString<L>();
|
*val = IString<L>();
|
||||||
oxReturnError(val->resize(size));
|
OX_RETURN_ERROR(val->resize(size));
|
||||||
auto const data = val->data();
|
auto const data = val->data();
|
||||||
// read the string
|
// read the string
|
||||||
oxReturnError(m_reader.read(data, size));
|
OX_RETURN_ERROR(m_reader.read(data, size));
|
||||||
} else {
|
} else {
|
||||||
*val = "";
|
*val = "";
|
||||||
}
|
}
|
||||||
@ -359,14 +359,14 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
OX_REQUIRE(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
||||||
if (size > buffLen) {
|
if (size > buffLen) {
|
||||||
return ox::Error(McOutputBuffEnded);
|
return ox::Error(McOutputBuffEnded);
|
||||||
}
|
}
|
||||||
// re-allocate in case too small
|
// re-allocate in case too small
|
||||||
auto data = val;
|
auto data = val;
|
||||||
// read the string
|
// read the string
|
||||||
oxReturnError(m_reader.read(data, size));
|
OX_RETURN_ERROR(m_reader.read(data, size));
|
||||||
data[size] = 0;
|
data[size] = 0;
|
||||||
}
|
}
|
||||||
++m_field;
|
++m_field;
|
||||||
@ -378,13 +378,13 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
OX_REQUIRE(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
||||||
// re-allocate in case too small
|
// re-allocate in case too small
|
||||||
safeDelete(*val);
|
safeDelete(*val);
|
||||||
*val = new char[size + 1];
|
*val = new char[size + 1];
|
||||||
auto data = ox::Span{*val, size + 1};
|
auto data = ox::Span{*val, size + 1};
|
||||||
// read the string
|
// read the string
|
||||||
oxReturnError(m_reader.read(data.data(), size));
|
OX_RETURN_ERROR(m_reader.read(data.data(), size));
|
||||||
data[size] = 0;
|
data[size] = 0;
|
||||||
}
|
}
|
||||||
++m_field;
|
++m_field;
|
||||||
@ -397,7 +397,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
OX_REQUIRE(size, mc::decodeInteger<StringLength>(m_reader, &bytesRead));
|
||||||
// re-allocate if too small
|
// re-allocate if too small
|
||||||
if (buffLen < size + 1) {
|
if (buffLen < size + 1) {
|
||||||
safeDelete(*val);
|
safeDelete(*val);
|
||||||
@ -406,7 +406,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
|
|||||||
}
|
}
|
||||||
auto data = ox::Span{*val, size + 1};
|
auto data = ox::Span{*val, size + 1};
|
||||||
// read the string
|
// read the string
|
||||||
oxReturnError(m_reader.read(data.data(), size));
|
OX_RETURN_ERROR(m_reader.read(data.data(), size));
|
||||||
data[size] = 0;
|
data[size] = 0;
|
||||||
} else {
|
} else {
|
||||||
auto data = *val;
|
auto data = *val;
|
||||||
@ -425,10 +425,10 @@ constexpr Result<ArrayLength> MetalClawReaderTemplate<Reader>::arrayLength(const
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(g, m_reader.tellg());
|
OX_REQUIRE(g, m_reader.tellg());
|
||||||
oxRequire(out, mc::decodeInteger<ArrayLength>(m_reader, &bytesRead));
|
OX_REQUIRE(out, mc::decodeInteger<ArrayLength>(m_reader, &bytesRead));
|
||||||
if (!pass) {
|
if (!pass) {
|
||||||
oxReturnError(m_reader.seekg(g));
|
OX_RETURN_ERROR(m_reader.seekg(g));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -443,7 +443,7 @@ constexpr Result<StringLength> MetalClawReaderTemplate<Reader>::stringLength(con
|
|||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
auto len = mc::decodeInteger<StringLength>(m_reader, &bytesRead);
|
auto len = mc::decodeInteger<StringLength>(m_reader, &bytesRead);
|
||||||
oxReturnError(m_reader.seekg(-static_cast<int64_t>(bytesRead), ox::ios_base::cur));
|
OX_RETURN_ERROR(m_reader.seekg(-static_cast<int64_t>(bytesRead), ox::ios_base::cur));
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -457,7 +457,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::readInteger(I *val) noexcept {
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
auto const result = mc::decodeInteger<I>(m_reader, &bytesRead);
|
auto const result = mc::decodeInteger<I>(m_reader, &bytesRead);
|
||||||
oxReturnError(result);
|
OX_RETURN_ERROR(result);
|
||||||
*val = result.value;
|
*val = result.value;
|
||||||
} else {
|
} else {
|
||||||
*val = 0;
|
*val = 0;
|
||||||
@ -474,15 +474,15 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, CB cb) noexc
|
|||||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||||
// read the length
|
// read the length
|
||||||
std::size_t bytesRead = 0;
|
std::size_t bytesRead = 0;
|
||||||
oxRequire(len, mc::decodeInteger<ArrayLength>(m_reader, &bytesRead));
|
OX_REQUIRE(len, mc::decodeInteger<ArrayLength>(m_reader, &bytesRead));
|
||||||
// read the list
|
// read the list
|
||||||
auto reader = child("");
|
auto reader = child("");
|
||||||
auto &handler = *reader.interface();
|
auto &handler = *reader.interface();
|
||||||
oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
|
OX_RETURN_ERROR(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
T val;
|
T val;
|
||||||
oxReturnError(handler.field("", &val));
|
OX_RETURN_ERROR(handler.field("", &val));
|
||||||
oxReturnError(cb(i, &val));
|
OX_RETURN_ERROR(cb(i, &val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -548,7 +548,7 @@ Error readMC(ox::BufferView buff, T &val) noexcept {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
Result<T> readMC(ox::BufferView buff) noexcept {
|
Result<T> readMC(ox::BufferView buff) noexcept {
|
||||||
Result<T> val;
|
Result<T> val;
|
||||||
oxReturnError(readMC(buff, val.value));
|
OX_RETURN_ERROR(readMC(buff, val.value));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
72
deps/ox/src/ox/mc/test/tests.cpp
vendored
72
deps/ox/src/ox/mc/test/tests.cpp
vendored
@ -62,46 +62,46 @@ struct TestStruct {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestUnion> auto *obj) noexcept {
|
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestUnion> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<TestUnion>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TestUnion>());
|
||||||
oxReturnError(io->field("Bool", &obj->Bool));
|
OX_RETURN_ERROR(io->field("Bool", &obj->Bool));
|
||||||
oxReturnError(io->field("Int", &obj->Int));
|
OX_RETURN_ERROR(io->field("Int", &obj->Int));
|
||||||
oxReturnError(io->fieldCString("CString", &obj->CString));
|
OX_RETURN_ERROR(io->fieldCString("CString", &obj->CString));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
oxModelBegin(TestStructNest)
|
OX_MODEL_BEGIN(TestStructNest)
|
||||||
oxModelField(Bool)
|
OX_MODEL_FIELD(Bool)
|
||||||
oxModelField(Int)
|
OX_MODEL_FIELD(Int)
|
||||||
oxModelField(IString)
|
OX_MODEL_FIELD(IString)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) noexcept {
|
constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<TestStruct>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TestStruct>());
|
||||||
oxReturnError(io->field("Bool", &obj->Bool));
|
OX_RETURN_ERROR(io->field("Bool", &obj->Bool));
|
||||||
oxReturnError(io->field("Int", &obj->Int));
|
OX_RETURN_ERROR(io->field("Int", &obj->Int));
|
||||||
oxReturnError(io->field("Int1", &obj->Int1));
|
OX_RETURN_ERROR(io->field("Int1", &obj->Int1));
|
||||||
oxReturnError(io->field("Int2", &obj->Int2));
|
OX_RETURN_ERROR(io->field("Int2", &obj->Int2));
|
||||||
oxReturnError(io->field("Int3", &obj->Int3));
|
OX_RETURN_ERROR(io->field("Int3", &obj->Int3));
|
||||||
oxReturnError(io->field("Int4", &obj->Int4));
|
OX_RETURN_ERROR(io->field("Int4", &obj->Int4));
|
||||||
oxReturnError(io->field("Int5", &obj->Int5));
|
OX_RETURN_ERROR(io->field("Int5", &obj->Int5));
|
||||||
oxReturnError(io->field("Int6", &obj->Int6));
|
OX_RETURN_ERROR(io->field("Int6", &obj->Int6));
|
||||||
oxReturnError(io->field("Int7", &obj->Int7));
|
OX_RETURN_ERROR(io->field("Int7", &obj->Int7));
|
||||||
oxReturnError(io->field("Int8", &obj->Int8));
|
OX_RETURN_ERROR(io->field("Int8", &obj->Int8));
|
||||||
oxReturnError(io->field("unionIdx", &obj->unionIdx));
|
OX_RETURN_ERROR(io->field("unionIdx", &obj->unionIdx));
|
||||||
if constexpr(T::opType() == ox::OpType::Reflect) {
|
if constexpr(T::opType() == ox::OpType::Reflect) {
|
||||||
oxReturnError(io->field("Union", ox::UnionView{&obj->Union, 0}));
|
OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, 0}));
|
||||||
} else {
|
} else {
|
||||||
oxReturnError(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx}));
|
OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx}));
|
||||||
}
|
}
|
||||||
oxReturnError(io->field("String", &obj->String));
|
OX_RETURN_ERROR(io->field("String", &obj->String));
|
||||||
oxReturnError(io->field("IString", &obj->IString));
|
OX_RETURN_ERROR(io->field("IString", &obj->IString));
|
||||||
oxReturnError(io->field("List", obj->List, 4));
|
OX_RETURN_ERROR(io->field("List", obj->List, 4));
|
||||||
oxReturnError(io->field("Vector", &obj->Vector));
|
OX_RETURN_ERROR(io->field("Vector", &obj->Vector));
|
||||||
oxReturnError(io->field("Vector2", &obj->Vector2));
|
OX_RETURN_ERROR(io->field("Vector2", &obj->Vector2));
|
||||||
oxReturnError(io->field("Map", &obj->Map));
|
OX_RETURN_ERROR(io->field("Map", &obj->Map));
|
||||||
oxReturnError(io->field("Struct", &obj->Struct));
|
OX_RETURN_ERROR(io->field("Struct", &obj->Struct));
|
||||||
oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct));
|
OX_RETURN_ERROR(io->field("EmptyStruct", &obj->EmptyStruct));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +114,8 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
// doesn't segfault
|
// doesn't segfault
|
||||||
ox::Array<char, 1024> buff;
|
ox::Array<char, 1024> buff;
|
||||||
TestStruct ts;
|
TestStruct ts;
|
||||||
oxReturnError(ox::writeMC(buff.data(), buff.size(), ts));
|
OX_RETURN_ERROR(ox::writeMC(buff.data(), buff.size(), ts));
|
||||||
oxReturnError(ox::writeMC(ts));
|
OX_RETURN_ERROR(ox::writeMC(ts));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -260,7 +260,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
using ox::mc::decodeInteger;
|
using ox::mc::decodeInteger;
|
||||||
static constexpr auto check = [](auto val) {
|
static constexpr auto check = [](auto val) {
|
||||||
auto result = decodeInteger<decltype(val)>(encodeInteger(val));
|
auto result = decodeInteger<decltype(val)>(encodeInteger(val));
|
||||||
oxReturnError(result.error);
|
OX_RETURN_ERROR(result.error);
|
||||||
if (result.value != val) {
|
if (result.value != val) {
|
||||||
std::cout << "Bad value: " << result.value << ", expected: " << val << '\n';
|
std::cout << "Bad value: " << result.value << ", expected: " << val << '\n';
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
@ -319,7 +319,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
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::ModelObject testOut;
|
ox::ModelObject testOut;
|
||||||
oxReturnError(testOut.setType(type));
|
OX_RETURN_ERROR(testOut.setType(type));
|
||||||
oxAssert(ox::readMC(dataBuff, 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");
|
||||||
@ -371,7 +371,7 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
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,
|
OX_RETURN_ERROR(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';
|
||||||
auto fieldName = f.fieldName.c_str();
|
auto fieldName = f.fieldName.c_str();
|
||||||
|
76
deps/ox/src/ox/mc/write.hpp
vendored
76
deps/ox/src/ox/mc/write.hpp
vendored
@ -117,10 +117,10 @@ class MetalClawWriter {
|
|||||||
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 mi = mc::encodeInteger(val);
|
auto mi = mc::encodeInteger(val);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(mi.data.data()), mi.length));
|
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(mi.data.data()), mi.length));
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
++m_field;
|
++m_field;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const uint64_t *val)
|
|||||||
template<Writer_c Writer>
|
template<Writer_c Writer>
|
||||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const bool *val) noexcept {
|
constexpr Error MetalClawWriter<Writer>::field(const char*, const bool *val) noexcept {
|
||||||
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), *val));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), *val));
|
||||||
}
|
}
|
||||||
++m_field;
|
++m_field;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
@ -194,12 +194,12 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const BasicString<Sm
|
|||||||
if (val->len() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (val->len() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
// write the length
|
// write the length
|
||||||
const auto strLen = mc::encodeInteger(val->len());
|
const auto strLen = mc::encodeInteger(val->len());
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLen.data.data()), strLen.length));
|
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(strLen.data.data()), strLen.length));
|
||||||
// write the string
|
// write the string
|
||||||
oxReturnError(m_writer.write(val->c_str(), static_cast<std::size_t>(val->len())));
|
OX_RETURN_ERROR(m_writer.write(val->c_str(), static_cast<std::size_t>(val->len())));
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
++m_field;
|
++m_field;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -217,12 +217,12 @@ constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *c
|
|||||||
const auto strLen = *val ? ox::strlen(*val) : 0;
|
const auto strLen = *val ? ox::strlen(*val) : 0;
|
||||||
// write the length
|
// write the length
|
||||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
||||||
// write the string
|
// write the string
|
||||||
oxReturnError(m_writer.write(*val, static_cast<std::size_t>(strLen)));
|
OX_RETURN_ERROR(m_writer.write(*val, static_cast<std::size_t>(strLen)));
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
++m_field;
|
++m_field;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -243,12 +243,12 @@ constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *v
|
|||||||
if (strLen && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (strLen && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
// write the length
|
// write the length
|
||||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
||||||
// write the string
|
// write the string
|
||||||
oxReturnError(m_writer.write(val, static_cast<std::size_t>(strLen)));
|
OX_RETURN_ERROR(m_writer.write(val, static_cast<std::size_t>(strLen)));
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
++m_field;
|
++m_field;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -264,11 +264,11 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const T *val) noexce
|
|||||||
auto const writeIdx = m_writer.tellp();
|
auto const writeIdx = m_writer.tellp();
|
||||||
MetalClawWriter<Writer> writer(m_writer);
|
MetalClawWriter<Writer> writer(m_writer);
|
||||||
ModelHandlerInterface<MetalClawWriter<Writer>> handler{&writer};
|
ModelHandlerInterface<MetalClawWriter<Writer>> handler{&writer};
|
||||||
oxReturnError(model(&handler, val));
|
OX_RETURN_ERROR(model(&handler, val));
|
||||||
oxReturnError(writer.finalize());
|
OX_RETURN_ERROR(writer.finalize());
|
||||||
fieldSet = writeIdx != m_writer.tellp();
|
fieldSet = writeIdx != m_writer.tellp();
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
++m_field;
|
++m_field;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -282,11 +282,11 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, UnionView<U, force>
|
|||||||
auto const writeIdx = m_writer.tellp();
|
auto const writeIdx = m_writer.tellp();
|
||||||
MetalClawWriter<Writer> writer(m_writer, ox::Optional<int>(ox::in_place, val.idx()));
|
MetalClawWriter<Writer> writer(m_writer, ox::Optional<int>(ox::in_place, val.idx()));
|
||||||
ModelHandlerInterface handler{&writer};
|
ModelHandlerInterface handler{&writer};
|
||||||
oxReturnError(model(&handler, val.get()));
|
OX_RETURN_ERROR(model(&handler, val.get()));
|
||||||
oxReturnError(writer.finalize());
|
OX_RETURN_ERROR(writer.finalize());
|
||||||
fieldSet = writeIdx != m_writer.tellp();
|
fieldSet = writeIdx != m_writer.tellp();
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
++m_field;
|
++m_field;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -298,21 +298,21 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const T *val, std::s
|
|||||||
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
// write the length
|
// write the length
|
||||||
const auto arrLen = mc::encodeInteger(len);
|
const auto arrLen = mc::encodeInteger(len);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(arrLen.data.data()), arrLen.length));
|
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(arrLen.data.data()), arrLen.length));
|
||||||
auto const writeIdx = m_writer.tellp();
|
auto const writeIdx = m_writer.tellp();
|
||||||
MetalClawWriter<Writer> writer(m_writer);
|
MetalClawWriter<Writer> writer(m_writer);
|
||||||
ModelHandlerInterface handler{&writer};
|
ModelHandlerInterface handler{&writer};
|
||||||
oxReturnError(handler.template setTypeInfo<T>("List", 0, {}, static_cast<std::size_t>(len)));
|
OX_RETURN_ERROR(handler.template setTypeInfo<T>("List", 0, {}, static_cast<std::size_t>(len)));
|
||||||
// write the array
|
// write the array
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
oxReturnError(handler.field("", &val[i]));
|
OX_RETURN_ERROR(handler.field("", &val[i]));
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
oxReturnError(writer.finalize());
|
OX_RETURN_ERROR(writer.finalize());
|
||||||
fieldSet = writeIdx != m_writer.tellp();
|
fieldSet = writeIdx != m_writer.tellp();
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
++m_field;
|
++m_field;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -326,30 +326,30 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const HashMap<String
|
|||||||
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
// write the length
|
// write the length
|
||||||
const auto arrLen = mc::encodeInteger(len);
|
const auto arrLen = mc::encodeInteger(len);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(arrLen.data.data()), arrLen.length));
|
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(arrLen.data.data()), arrLen.length));
|
||||||
// write map
|
// write map
|
||||||
MetalClawWriter<Writer> writer(m_writer);
|
MetalClawWriter<Writer> writer(m_writer);
|
||||||
ModelHandlerInterface handler{&writer};
|
ModelHandlerInterface handler{&writer};
|
||||||
// double len for both key and value
|
// double len for both key and value
|
||||||
oxReturnError(handler.setTypeInfo("Map", 0, {}, len * 2));
|
OX_RETURN_ERROR(handler.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) -> ox::Error {
|
constexpr auto loopBody = [](auto &handler, auto const&key, auto const&val) -> ox::Error {
|
||||||
const auto keyLen = key.len();
|
const auto keyLen = key.len();
|
||||||
auto wkey = ox_malloca(keyLen + 1, char, 0);
|
auto wkey = ox_malloca(keyLen + 1, char, 0);
|
||||||
memcpy(wkey.get(), key.c_str(), keyLen + 1);
|
memcpy(wkey.get(), key.c_str(), keyLen + 1);
|
||||||
oxReturnError(handler.fieldCString("", wkey.get(), keyLen));
|
OX_RETURN_ERROR(handler.fieldCString("", wkey.get(), keyLen));
|
||||||
oxRequireM(value, val.at(key));
|
OX_REQUIRE_M(value, val.at(key));
|
||||||
return handler.field("", value);
|
return handler.field("", value);
|
||||||
};
|
};
|
||||||
// write the array
|
// write the array
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
auto const&key = keys[i];
|
auto const&key = keys[i];
|
||||||
oxReturnError(loopBody(handler, key, *val));
|
OX_RETURN_ERROR(loopBody(handler, key, *val));
|
||||||
}
|
}
|
||||||
oxReturnError(writer.finalize());
|
OX_RETURN_ERROR(writer.finalize());
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
OX_RETURN_ERROR(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
++m_field;
|
++m_field;
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -362,7 +362,7 @@ constexpr ox::Error MetalClawWriter<Writer>::setTypeInfo(
|
|||||||
const Vector<String>&,
|
const Vector<String>&,
|
||||||
std::size_t fields) noexcept {
|
std::size_t fields) noexcept {
|
||||||
const auto fieldPresenceLen = (fields - 1) / 8 + 1;
|
const auto fieldPresenceLen = (fields - 1) / 8 + 1;
|
||||||
oxReturnError(m_writer.write(nullptr, fieldPresenceLen));
|
OX_RETURN_ERROR(m_writer.write(nullptr, fieldPresenceLen));
|
||||||
m_presenceMapBuff.resize(fieldPresenceLen);
|
m_presenceMapBuff.resize(fieldPresenceLen);
|
||||||
m_fieldPresence.setBuffer(m_presenceMapBuff.data(), m_presenceMapBuff.size());
|
m_fieldPresence.setBuffer(m_presenceMapBuff.data(), m_presenceMapBuff.size());
|
||||||
m_fieldPresence.setFields(static_cast<int>(fields));
|
m_fieldPresence.setFields(static_cast<int>(fields));
|
||||||
@ -372,33 +372,33 @@ constexpr ox::Error MetalClawWriter<Writer>::setTypeInfo(
|
|||||||
template<Writer_c Writer>
|
template<Writer_c Writer>
|
||||||
ox::Error MetalClawWriter<Writer>::finalize() noexcept {
|
ox::Error MetalClawWriter<Writer>::finalize() noexcept {
|
||||||
const auto end = m_writer.tellp();
|
const auto end = m_writer.tellp();
|
||||||
oxReturnError(m_writer.seekp(m_writerBeginP));
|
OX_RETURN_ERROR(m_writer.seekp(m_writerBeginP));
|
||||||
oxReturnError(m_writer.write(
|
OX_RETURN_ERROR(m_writer.write(
|
||||||
reinterpret_cast<const char*>(m_presenceMapBuff.data()),
|
reinterpret_cast<const char*>(m_presenceMapBuff.data()),
|
||||||
m_presenceMapBuff.size()));
|
m_presenceMapBuff.size()));
|
||||||
oxReturnError(m_writer.seekp(end));
|
OX_RETURN_ERROR(m_writer.seekp(end));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Buffer> writeMC(Writer_c auto &writer, const auto &val) noexcept {
|
Result<Buffer> writeMC(Writer_c auto &writer, const auto &val) noexcept {
|
||||||
MetalClawWriter mcWriter(writer);
|
MetalClawWriter mcWriter(writer);
|
||||||
ModelHandlerInterface handler{&mcWriter};
|
ModelHandlerInterface handler{&mcWriter};
|
||||||
oxReturnError(model(&handler, &val));
|
OX_RETURN_ERROR(model(&handler, &val));
|
||||||
oxReturnError(mcWriter.finalize());
|
OX_RETURN_ERROR(mcWriter.finalize());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Buffer> writeMC(auto const&val, std::size_t buffReserveSz = 2 * units::KB) noexcept {
|
Result<Buffer> writeMC(auto const&val, std::size_t buffReserveSz = 2 * units::KB) noexcept {
|
||||||
Buffer buff(buffReserveSz);
|
Buffer buff(buffReserveSz);
|
||||||
BufferWriter bw(&buff, 0);
|
BufferWriter bw(&buff, 0);
|
||||||
oxReturnError(writeMC(bw, val));
|
OX_RETURN_ERROR(writeMC(bw, val));
|
||||||
buff.resize(bw.tellp());
|
buff.resize(bw.tellp());
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error writeMC(char *buff, std::size_t buffLen, auto const&val, std::size_t *sizeOut = nullptr) noexcept {
|
Error writeMC(char *buff, std::size_t buffLen, auto const&val, std::size_t *sizeOut = nullptr) noexcept {
|
||||||
CharBuffWriter bw{{buff, buffLen}};
|
CharBuffWriter bw{{buff, buffLen}};
|
||||||
oxReturnError(writeMC(bw, val));
|
OX_RETURN_ERROR(writeMC(bw, val));
|
||||||
if (sizeOut) {
|
if (sizeOut) {
|
||||||
*sizeOut = bw.tellp();
|
*sizeOut = bw.tellp();
|
||||||
}
|
}
|
||||||
|
12
deps/ox/src/ox/model/def.hpp
vendored
12
deps/ox/src/ox/model/def.hpp
vendored
@ -11,9 +11,9 @@
|
|||||||
#include <ox/std/concepts.hpp>
|
#include <ox/std/concepts.hpp>
|
||||||
|
|
||||||
// oxModelFwdDecl is necessary because Apple-Clang is broken...
|
// oxModelFwdDecl is necessary because Apple-Clang is broken...
|
||||||
#define oxModelFwdDecl(modelName) constexpr ox::Error model(auto *io, ox::CommonPtrWith<modelName> auto *o) noexcept
|
#define OX_MODEL_FWD_DECL(modelName) constexpr ox::Error model(auto *io, ox::CommonPtrWith<modelName> auto *o) noexcept
|
||||||
#define oxModelBegin(modelName) constexpr ox::Error model(auto *io, [[maybe_unused]] ox::CommonPtrWith<modelName> auto *o) noexcept { oxReturnError(io->template setTypeInfo<modelName>());
|
#define OX_MODEL_BEGIN(modelName) constexpr ox::Error model(auto *io, [[maybe_unused]] ox::CommonPtrWith<modelName> auto *o) noexcept { OX_RETURN_ERROR(io->template setTypeInfo<modelName>());
|
||||||
#define oxModelEnd() return ox::Error(0); }
|
#define OX_MODEL_END() return ox::Error(0); }
|
||||||
#define oxModelField(fieldName) oxReturnError(io->field(#fieldName, &o->fieldName));
|
#define OX_MODEL_FIELD(fieldName) OX_RETURN_ERROR(io->field(#fieldName, &o->fieldName));
|
||||||
#define oxModelFieldRename(objFieldName, serFieldName) oxReturnError(io->field(#serFieldName, &o->objFieldName));
|
#define OX_MODEL_FIELD_RENAME(objFieldName, serFieldName) OX_RETURN_ERROR(io->field(#serFieldName, &o->objFieldName));
|
||||||
#define oxModelFriend(modelName) friend constexpr ox::Error model(auto *io, ox::CommonPtrWith<modelName> auto *o) noexcept
|
#define OX_MODEL_FRIEND(modelName) friend constexpr ox::Error model(auto *io, ox::CommonPtrWith<modelName> auto *o) noexcept
|
||||||
|
44
deps/ox/src/ox/model/desctypes.hpp
vendored
44
deps/ox/src/ox/model/desctypes.hpp
vendored
@ -76,20 +76,20 @@ struct Subscript {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, CommonPtrWith<Subscript> auto *type) noexcept {
|
constexpr Error model(T *io, CommonPtrWith<Subscript> auto *type) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<Subscript>());
|
OX_RETURN_ERROR(io->template setTypeInfo<Subscript>());
|
||||||
if constexpr(T::opType() == OpType::Reflect) {
|
if constexpr(T::opType() == OpType::Reflect) {
|
||||||
uint32_t st = 0;
|
uint32_t st = 0;
|
||||||
oxReturnError(io->field("subscriptType", &st));
|
OX_RETURN_ERROR(io->field("subscriptType", &st));
|
||||||
} else if constexpr(T::opType() == OpType::Write) {
|
} else if constexpr(T::opType() == OpType::Write) {
|
||||||
auto pt = type ? static_cast<uint8_t>(type->subscriptType) : 0;
|
auto pt = type ? static_cast<uint8_t>(type->subscriptType) : 0;
|
||||||
oxReturnError(io->field("subscriptType", &pt));
|
OX_RETURN_ERROR(io->field("subscriptType", &pt));
|
||||||
} else {
|
} else {
|
||||||
auto pt = type ? static_cast<uint32_t>(type->subscriptType) : 0;
|
auto pt = type ? static_cast<uint32_t>(type->subscriptType) : 0;
|
||||||
oxReturnError(io->field("subscriptType", &pt));
|
OX_RETURN_ERROR(io->field("subscriptType", &pt));
|
||||||
type->subscriptType = static_cast<Subscript::SubscriptType>(pt);
|
type->subscriptType = static_cast<Subscript::SubscriptType>(pt);
|
||||||
}
|
}
|
||||||
oxReturnError(io->field("length", &type->length));
|
OX_RETURN_ERROR(io->field("length", &type->length));
|
||||||
oxReturnError(io->field("smallSzLen", &type->smallSzLen));
|
OX_RETURN_ERROR(io->field("smallSzLen", &type->smallSzLen));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,37 +185,37 @@ constexpr auto buildTypeId(const DescriptorType &t) noexcept {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, CommonPtrWith<DescriptorType> auto *type) noexcept {
|
constexpr Error model(T *io, CommonPtrWith<DescriptorType> auto *type) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<DescriptorType>());
|
OX_RETURN_ERROR(io->template setTypeInfo<DescriptorType>());
|
||||||
oxReturnError(io->field("typeName", &type->typeName));
|
OX_RETURN_ERROR(io->field("typeName", &type->typeName));
|
||||||
oxReturnError(io->field("typeVersion", &type->typeVersion));
|
OX_RETURN_ERROR(io->field("typeVersion", &type->typeVersion));
|
||||||
if constexpr(T::opType() == OpType::Reflect) {
|
if constexpr(T::opType() == OpType::Reflect) {
|
||||||
uint8_t pt = 0;
|
uint8_t pt = 0;
|
||||||
oxReturnError(io->field("primitiveType", &pt));
|
OX_RETURN_ERROR(io->field("primitiveType", &pt));
|
||||||
} else if constexpr(T::opType() == OpType::Write) {
|
} else if constexpr(T::opType() == OpType::Write) {
|
||||||
auto pt = type ? static_cast<uint8_t>(type->primitiveType) : 0;
|
auto pt = type ? static_cast<uint8_t>(type->primitiveType) : 0;
|
||||||
oxReturnError(io->field("primitiveType", &pt));
|
OX_RETURN_ERROR(io->field("primitiveType", &pt));
|
||||||
} else {
|
} else {
|
||||||
auto pt = type ? static_cast<uint8_t>(type->primitiveType) : 0;
|
auto pt = type ? static_cast<uint8_t>(type->primitiveType) : 0;
|
||||||
oxReturnError(io->field("primitiveType", &pt));
|
OX_RETURN_ERROR(io->field("primitiveType", &pt));
|
||||||
type->primitiveType = static_cast<PrimitiveType>(pt);
|
type->primitiveType = static_cast<PrimitiveType>(pt);
|
||||||
}
|
}
|
||||||
oxReturnError(io->field("typeParams", &type->typeParams));
|
OX_RETURN_ERROR(io->field("typeParams", &type->typeParams));
|
||||||
oxReturnError(io->field("fieldList", &type->fieldList));
|
OX_RETURN_ERROR(io->field("fieldList", &type->fieldList));
|
||||||
oxReturnError(io->field("length", &type->length));
|
OX_RETURN_ERROR(io->field("length", &type->length));
|
||||||
oxReturnError(io->field("preloadable", &type->preloadable));
|
OX_RETURN_ERROR(io->field("preloadable", &type->preloadable));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, CommonPtrWith<DescriptorField> auto *field) noexcept {
|
constexpr Error model(T *io, CommonPtrWith<DescriptorField> auto *field) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<DescriptorField>());
|
OX_RETURN_ERROR(io->template setTypeInfo<DescriptorField>());
|
||||||
oxReturnError(io->field("typeId", &field->typeId));
|
OX_RETURN_ERROR(io->field("typeId", &field->typeId));
|
||||||
oxReturnError(io->field("fieldName", &field->fieldName));
|
OX_RETURN_ERROR(io->field("fieldName", &field->fieldName));
|
||||||
oxReturnError(io->field("subscriptLevels", &field->subscriptLevels));
|
OX_RETURN_ERROR(io->field("subscriptLevels", &field->subscriptLevels));
|
||||||
oxReturnError(io->field("subscriptStack", &field->subscriptStack));
|
OX_RETURN_ERROR(io->field("subscriptStack", &field->subscriptStack));
|
||||||
// defaultValue is unused now, but leave placeholder for backwards compatibility
|
// defaultValue is unused now, but leave placeholder for backwards compatibility
|
||||||
int defaultValue = 0;
|
int defaultValue = 0;
|
||||||
oxReturnError(io->field("defaultValue", &defaultValue));
|
OX_RETURN_ERROR(io->field("defaultValue", &defaultValue));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
deps/ox/src/ox/model/descwrite.hpp
vendored
6
deps/ox/src/ox/model/descwrite.hpp
vendored
@ -384,11 +384,11 @@ constexpr Result<DescriptorType*> buildTypeDef(TypeStore &typeStore) noexcept {
|
|||||||
if (std::is_constant_evaluated()) {
|
if (std::is_constant_evaluated()) {
|
||||||
std::allocator<T> a;
|
std::allocator<T> a;
|
||||||
T *t = a.allocate(1);
|
T *t = a.allocate(1);
|
||||||
oxReturnError(model(&handler, t));
|
OX_RETURN_ERROR(model(&handler, t));
|
||||||
a.deallocate(t, 1);
|
a.deallocate(t, 1);
|
||||||
} else {
|
} else {
|
||||||
auto t = ox_malloca(sizeof(T), T);
|
auto t = ox_malloca(sizeof(T), T);
|
||||||
oxReturnError(model(&handler, t.get()));
|
OX_RETURN_ERROR(model(&handler, t.get()));
|
||||||
}
|
}
|
||||||
return writer.definition();
|
return writer.definition();
|
||||||
}
|
}
|
||||||
@ -397,7 +397,7 @@ template<typename T>
|
|||||||
constexpr Result<DescriptorType*> buildTypeDef(TypeStore &typeStore, T &val) noexcept {
|
constexpr Result<DescriptorType*> buildTypeDef(TypeStore &typeStore, T &val) noexcept {
|
||||||
TypeDescWriter writer(&typeStore);
|
TypeDescWriter writer(&typeStore);
|
||||||
ModelHandlerInterface<TypeDescWriter, ox::OpType::Reflect> handler(&writer);
|
ModelHandlerInterface<TypeDescWriter, ox::OpType::Reflect> handler(&writer);
|
||||||
oxReturnError(model(&handler, &val));
|
OX_RETURN_ERROR(model(&handler, &val));
|
||||||
return writer.definition();
|
return writer.definition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
deps/ox/src/ox/model/modelvalue.cpp
vendored
2
deps/ox/src/ox/model/modelvalue.cpp
vendored
@ -12,7 +12,7 @@ namespace ox {
|
|||||||
|
|
||||||
static_assert([]() -> ox::Error {
|
static_assert([]() -> ox::Error {
|
||||||
ox::ModelValue v;
|
ox::ModelValue v;
|
||||||
oxReturnError(v.setType<int32_t>());
|
OX_RETURN_ERROR(v.setType<int32_t>());
|
||||||
if (v.type() != ModelValue::Type::SignedInteger32) {
|
if (v.type() != ModelValue::Type::SignedInteger32) {
|
||||||
return ox::Error(1, "type is wrong");
|
return ox::Error(1, "type is wrong");
|
||||||
}
|
}
|
||||||
|
46
deps/ox/src/ox/model/modelvalue.hpp
vendored
46
deps/ox/src/ox/model/modelvalue.hpp
vendored
@ -242,7 +242,7 @@ class ModelValueArray {
|
|||||||
m_vec.resize(sz);
|
m_vec.resize(sz);
|
||||||
if (sz > oldSz) {
|
if (sz > oldSz) {
|
||||||
for (auto i = oldSz; i < sz; ++i) {
|
for (auto i = oldSz; i < sz; ++i) {
|
||||||
oxReturnError(m_vec[i].setType(m_type, m_subscriptStack, m_typeSubscriptLevels));
|
OX_RETURN_ERROR(m_vec[i].setType(m_type, m_subscriptStack, m_typeSubscriptLevels));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
@ -401,7 +401,7 @@ class ModelValueVector {
|
|||||||
m_vec.resize(sz);
|
m_vec.resize(sz);
|
||||||
if (sz > oldSz) {
|
if (sz > oldSz) {
|
||||||
for (auto i = oldSz; i < sz; ++i) {
|
for (auto i = oldSz; i < sz; ++i) {
|
||||||
oxReturnError(m_vec[i].setType(m_type, m_subscriptStack, m_typeSubscriptLevels));
|
OX_RETURN_ERROR(m_vec[i].setType(m_type, m_subscriptStack, m_typeSubscriptLevels));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
@ -519,7 +519,7 @@ class ModelObject {
|
|||||||
ModelValue value;
|
ModelValue value;
|
||||||
};
|
};
|
||||||
protected:
|
protected:
|
||||||
oxModelFriend(ModelObject);
|
OX_MODEL_FRIEND(ModelObject);
|
||||||
friend ModelValue;
|
friend ModelValue;
|
||||||
Vector<UniquePtr<Field>> m_fieldsOrder;
|
Vector<UniquePtr<Field>> m_fieldsOrder;
|
||||||
HashMap<String, ModelValue*> m_fields;
|
HashMap<String, ModelValue*> m_fields;
|
||||||
@ -639,13 +639,13 @@ class ModelObject {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error set(const String &k, T &&val) noexcept {
|
constexpr Error set(const String &k, T &&val) noexcept {
|
||||||
oxRequire(t, m_fields.at(k));
|
OX_REQUIRE(t, m_fields.at(k));
|
||||||
*t = ox::forward<T>(val);
|
*t = ox::forward<T>(val);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ox::Result<ModelValue*> at(StringView const&k) noexcept {
|
constexpr ox::Result<ModelValue*> at(StringView const&k) noexcept {
|
||||||
oxRequire(v, m_fields.at(k));
|
OX_REQUIRE(v, m_fields.at(k));
|
||||||
return *v;
|
return *v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,7 +676,7 @@ class ModelObject {
|
|||||||
for (const auto &f : type->fieldList) {
|
for (const auto &f : type->fieldList) {
|
||||||
auto field = make_unique<Field>();
|
auto field = make_unique<Field>();
|
||||||
field->name = f.fieldName;
|
field->name = f.fieldName;
|
||||||
oxReturnError(field->value.setType(f.type, f.subscriptStack, f.subscriptLevels));
|
OX_RETURN_ERROR(field->value.setType(f.type, f.subscriptStack, f.subscriptLevels));
|
||||||
m_fields[field->name] = &field->value;
|
m_fields[field->name] = &field->value;
|
||||||
m_fieldsOrder.emplace_back(std::move(field));
|
m_fieldsOrder.emplace_back(std::move(field));
|
||||||
}
|
}
|
||||||
@ -722,7 +722,7 @@ class ModelUnion {
|
|||||||
|
|
||||||
static constexpr Result<UniquePtr<ModelUnion>> make(const DescriptorType *type) noexcept {
|
static constexpr Result<UniquePtr<ModelUnion>> make(const DescriptorType *type) noexcept {
|
||||||
UniquePtr<ModelUnion> out(new ModelUnion);
|
UniquePtr<ModelUnion> out(new ModelUnion);
|
||||||
oxReturnError(out->setType(type));
|
OX_RETURN_ERROR(out->setType(type));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -731,7 +731,7 @@ class ModelUnion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr ox::Result<ModelValue*> at(StringView const&k) noexcept {
|
constexpr ox::Result<ModelValue*> at(StringView const&k) noexcept {
|
||||||
oxRequire(v, m_fields.at(k));
|
OX_REQUIRE(v, m_fields.at(k));
|
||||||
return &(*v)->value;
|
return &(*v)->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,7 +763,7 @@ class ModelUnion {
|
|||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr Result<const ModelValue*> get(StringView const&k) const noexcept {
|
constexpr Result<const ModelValue*> get(StringView const&k) const noexcept {
|
||||||
oxRequire(t, m_fields.at(k));
|
OX_REQUIRE(t, m_fields.at(k));
|
||||||
return &(*t)->value;
|
return &(*t)->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,7 +799,7 @@ class ModelUnion {
|
|||||||
auto field = make_unique<Field>();
|
auto field = make_unique<Field>();
|
||||||
field->name = f.fieldName;
|
field->name = f.fieldName;
|
||||||
field->idx = i;
|
field->idx = i;
|
||||||
oxReturnError(field->value.setType(f.type, SubscriptStack{static_cast<size_t>(f.subscriptLevels)}, f.subscriptLevels));
|
OX_RETURN_ERROR(field->value.setType(f.type, SubscriptStack{static_cast<size_t>(f.subscriptLevels)}, f.subscriptLevels));
|
||||||
m_fields[field->name] = field.get();
|
m_fields[field->name] = field.get();
|
||||||
m_fieldsOrder.emplace_back(std::move(field));
|
m_fieldsOrder.emplace_back(std::move(field));
|
||||||
++i;
|
++i;
|
||||||
@ -967,19 +967,19 @@ constexpr std::size_t alignOf(const ModelValue &t) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error model(auto *h, CommonPtrWith<ModelObject> auto *obj) noexcept {
|
constexpr Error model(auto *h, CommonPtrWith<ModelObject> auto *obj) noexcept {
|
||||||
oxReturnError(h->template setTypeInfo<ModelObject>(
|
OX_RETURN_ERROR(h->template setTypeInfo<ModelObject>(
|
||||||
obj->typeName().c_str(), obj->typeVersion(), {}, obj->m_fieldsOrder.size()));
|
obj->typeName().c_str(), obj->typeVersion(), {}, obj->m_fieldsOrder.size()));
|
||||||
for (auto &f : obj->m_fieldsOrder) {
|
for (auto &f : obj->m_fieldsOrder) {
|
||||||
oxReturnError(h->field(f->name.c_str(), &f->value));
|
OX_RETURN_ERROR(h->field(f->name.c_str(), &f->value));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept {
|
constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept {
|
||||||
oxReturnError(h->template setTypeInfo<ModelUnion>(
|
OX_RETURN_ERROR(h->template setTypeInfo<ModelUnion>(
|
||||||
obj->typeName().c_str(), obj->typeVersion(), {}, obj->m_fieldsOrder.size()));
|
obj->typeName().c_str(), obj->typeVersion(), {}, obj->m_fieldsOrder.size()));
|
||||||
for (auto &f : obj->m_fieldsOrder) {
|
for (auto &f : obj->m_fieldsOrder) {
|
||||||
oxReturnError(h->field(f->name.c_str(), &f->value));
|
OX_RETURN_ERROR(h->field(f->name.c_str(), &f->value));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -1087,12 +1087,12 @@ constexpr Error ModelValue::setType(
|
|||||||
if (subscript.subscriptType == Subscript::SubscriptType::InlineArray) {
|
if (subscript.subscriptType == Subscript::SubscriptType::InlineArray) {
|
||||||
m_type = Type::InlineArray;
|
m_type = Type::InlineArray;
|
||||||
m_data.array = new ModelValueArray;
|
m_data.array = new ModelValueArray;
|
||||||
oxReturnError(m_data.array->setType(type, subscriptStack, subscriptLevels - 1));
|
OX_RETURN_ERROR(m_data.array->setType(type, subscriptStack, subscriptLevels - 1));
|
||||||
oxReturnError(m_data.array->setSize(static_cast<size_t>(subscript.length)));
|
OX_RETURN_ERROR(m_data.array->setSize(static_cast<size_t>(subscript.length)));
|
||||||
} else {
|
} else {
|
||||||
m_type = Type::Vector;
|
m_type = Type::Vector;
|
||||||
m_data.vec = new ModelValueVector;
|
m_data.vec = new ModelValueVector;
|
||||||
oxReturnError(m_data.vec->setType(type, subscriptStack, subscriptLevels - 1));
|
OX_RETURN_ERROR(m_data.vec->setType(type, subscriptStack, subscriptLevels - 1));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
} else if (type->typeName == types::Bool) {
|
} else if (type->typeName == types::Bool) {
|
||||||
@ -1121,12 +1121,12 @@ constexpr Error ModelValue::setType(
|
|||||||
} else if (type->primitiveType == PrimitiveType::Struct) {
|
} else if (type->primitiveType == PrimitiveType::Struct) {
|
||||||
m_type = Type::Object;
|
m_type = Type::Object;
|
||||||
m_data.obj = new ModelObject;
|
m_data.obj = new ModelObject;
|
||||||
oxReturnError(m_data.obj->setType(type));
|
OX_RETURN_ERROR(m_data.obj->setType(type));
|
||||||
} else if (type->primitiveType == PrimitiveType::Union) {
|
} else if (type->primitiveType == PrimitiveType::Union) {
|
||||||
m_type = Type::Union;
|
m_type = Type::Union;
|
||||||
oxRequireM(u, ModelUnion::make(type));
|
OX_REQUIRE_M(u, ModelUnion::make(type));
|
||||||
m_data.uni = u.release();
|
m_data.uni = u.release();
|
||||||
oxReturnError(m_data.uni->setType(type));
|
OX_RETURN_ERROR(m_data.uni->setType(type));
|
||||||
}
|
}
|
||||||
oxAssert(m_type != Type::Undefined, "No type set");
|
oxAssert(m_type != Type::Undefined, "No type set");
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
@ -1141,11 +1141,11 @@ constexpr Error ModelValue::setType() noexcept {
|
|||||||
// rather than using getValue<type>()
|
// rather than using getValue<type>()
|
||||||
if constexpr(type == Type::Object) {
|
if constexpr(type == Type::Object) {
|
||||||
m_data.obj = new ModelObject;
|
m_data.obj = new ModelObject;
|
||||||
oxReturnError(m_data.obj->setType(type));
|
OX_RETURN_ERROR(m_data.obj->setType(type));
|
||||||
} else if constexpr(type == Type::Union) {
|
} else if constexpr(type == Type::Union) {
|
||||||
oxRequireM(u, ModelUnion::make(type));
|
OX_REQUIRE_M(u, ModelUnion::make(type));
|
||||||
m_data.uni = u.release();
|
m_data.uni = u.release();
|
||||||
oxReturnError(m_data.uni->setType(type));
|
OX_RETURN_ERROR(m_data.uni->setType(type));
|
||||||
} else if constexpr(type == Type::String) {
|
} else if constexpr(type == Type::String) {
|
||||||
m_data.str = new String;
|
m_data.str = new String;
|
||||||
} else if constexpr(type == Type::Vector) {
|
} else if constexpr(type == Type::Vector) {
|
||||||
|
8
deps/ox/src/ox/model/test/tests.cpp
vendored
8
deps/ox/src/ox/model/test/tests.cpp
vendored
@ -17,8 +17,8 @@ struct TestType {
|
|||||||
static constexpr auto TypeVersion = 1;
|
static constexpr auto TypeVersion = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(TestType)
|
OX_MODEL_BEGIN(TestType)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
struct TestType2 {
|
struct TestType2 {
|
||||||
};
|
};
|
||||||
@ -38,12 +38,12 @@ std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
"ModelValue",
|
"ModelValue",
|
||||||
[] {
|
[] {
|
||||||
ox::ModelValue v;
|
ox::ModelValue v;
|
||||||
oxReturnError(v.setType<int32_t>());
|
OX_RETURN_ERROR(v.setType<int32_t>());
|
||||||
//v.m_type = ox::ModelValue::getType<int32_t>();
|
//v.m_type = ox::ModelValue::getType<int32_t>();
|
||||||
if (v.type() != ox::ModelValue::Type::SignedInteger32) {
|
if (v.type() != ox::ModelValue::Type::SignedInteger32) {
|
||||||
return ox::Error(1, "type is wrong");
|
return ox::Error(1, "type is wrong");
|
||||||
}
|
}
|
||||||
oxReturnError(v.set<int32_t>(5));
|
OX_RETURN_ERROR(v.set<int32_t>(5));
|
||||||
return ox::Error{};
|
return ox::Error{};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
8
deps/ox/src/ox/model/typestore.hpp
vendored
8
deps/ox/src/ox/model/typestore.hpp
vendored
@ -31,7 +31,7 @@ class TypeStore {
|
|||||||
constexpr Result<const DescriptorType*> get(const auto &name, int typeVersion,
|
constexpr Result<const DescriptorType*> get(const auto &name, int typeVersion,
|
||||||
const TypeParamPack &typeParams) const noexcept {
|
const TypeParamPack &typeParams) const noexcept {
|
||||||
const auto typeId = buildTypeId(name, typeVersion, typeParams);
|
const auto typeId = buildTypeId(name, typeVersion, typeParams);
|
||||||
oxRequire(out, m_cache.at(typeId));
|
OX_REQUIRE(out, m_cache.at(typeId));
|
||||||
return out->get();
|
return out->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ class TypeStore {
|
|||||||
constexpr auto typeName = ModelTypeName_v<T>;
|
constexpr auto typeName = ModelTypeName_v<T>;
|
||||||
constexpr auto typeVersion = ModelTypeVersion_v<T>;
|
constexpr auto typeVersion = ModelTypeVersion_v<T>;
|
||||||
const auto typeId = buildTypeId(typeName, typeVersion, {});
|
const auto typeId = buildTypeId(typeName, typeVersion, {});
|
||||||
oxRequire(out, m_cache.at(typeId));
|
OX_REQUIRE(out, m_cache.at(typeId));
|
||||||
return out->get();
|
return out->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,9 +56,9 @@ class TypeStore {
|
|||||||
auto [val, err] = m_cache.at(typeId);
|
auto [val, err] = m_cache.at(typeId);
|
||||||
if (err) {
|
if (err) {
|
||||||
if (!std::is_constant_evaluated()) {
|
if (!std::is_constant_evaluated()) {
|
||||||
oxRequireM(dt, loadDescriptor(typeId));
|
OX_REQUIRE_M(dt, loadDescriptor(typeId));
|
||||||
for (auto &f : dt->fieldList) {
|
for (auto &f : dt->fieldList) {
|
||||||
oxReturnError(this->getLoad(f.typeId).moveTo(f.type));
|
OX_RETURN_ERROR(this->getLoad(f.typeId).moveTo(f.type));
|
||||||
}
|
}
|
||||||
auto &out = m_cache[typeId];
|
auto &out = m_cache[typeId];
|
||||||
out = std::move(dt);
|
out = std::move(dt);
|
||||||
|
20
deps/ox/src/ox/model/walk.hpp
vendored
20
deps/ox/src/ox/model/walk.hpp
vendored
@ -50,7 +50,7 @@ constexpr DataWalker<Reader, T>::DataWalker(DescriptorType *type, T fieldHandler
|
|||||||
|
|
||||||
template<typename Reader, typename T>
|
template<typename Reader, typename T>
|
||||||
constexpr Result<const DescriptorType*> DataWalker<Reader, T>::type() const noexcept {
|
constexpr Result<const DescriptorType*> DataWalker<Reader, T>::type() const noexcept {
|
||||||
oxRequire(out, m_typeStack.back());
|
OX_REQUIRE(out, m_typeStack.back());
|
||||||
return *out;
|
return *out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,9 +87,9 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat
|
|||||||
walker->pushNamePath(field.fieldName);
|
walker->pushNamePath(field.fieldName);
|
||||||
if (field.subscriptLevels) {
|
if (field.subscriptLevels) {
|
||||||
// add array handling
|
// add array handling
|
||||||
oxRequire(arrayLen, rdr->arrayLength(field.fieldName.c_str(), true));
|
OX_REQUIRE(arrayLen, rdr->arrayLength(field.fieldName.c_str(), true));
|
||||||
auto child = rdr->child(field.fieldName.c_str());
|
auto child = rdr->child(field.fieldName.c_str());
|
||||||
oxReturnError(child.setTypeInfo(field.type->typeName.c_str(), field.type->typeVersion, field.type->typeParams, arrayLen));
|
OX_RETURN_ERROR(child.setTypeInfo(field.type->typeName.c_str(), field.type->typeVersion, field.type->typeParams, arrayLen));
|
||||||
DescriptorField f(field); // create mutable copy
|
DescriptorField f(field); // create mutable copy
|
||||||
--f.subscriptLevels;
|
--f.subscriptLevels;
|
||||||
String subscript;
|
String subscript;
|
||||||
@ -98,7 +98,7 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat
|
|||||||
subscript += static_cast<uint64_t>(i);
|
subscript += static_cast<uint64_t>(i);
|
||||||
subscript += "]";
|
subscript += "]";
|
||||||
walker->pushNamePath(subscript);
|
walker->pushNamePath(subscript);
|
||||||
oxReturnError(parseField(f, &child, walker));
|
OX_RETURN_ERROR(parseField(f, &child, walker));
|
||||||
walker->popNamePath();
|
walker->popNamePath();
|
||||||
}
|
}
|
||||||
rdr->nextField();
|
rdr->nextField();
|
||||||
@ -108,20 +108,20 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat
|
|||||||
case PrimitiveType::SignedInteger:
|
case PrimitiveType::SignedInteger:
|
||||||
case PrimitiveType::Bool:
|
case PrimitiveType::Bool:
|
||||||
case PrimitiveType::String:
|
case PrimitiveType::String:
|
||||||
oxReturnError(walker->read(field, rdr));
|
OX_RETURN_ERROR(walker->read(field, rdr));
|
||||||
break;
|
break;
|
||||||
case PrimitiveType::Struct:
|
case PrimitiveType::Struct:
|
||||||
case PrimitiveType::Union:
|
case PrimitiveType::Union:
|
||||||
if (rdr->fieldPresent(field.fieldName.c_str())) {
|
if (rdr->fieldPresent(field.fieldName.c_str())) {
|
||||||
auto child = rdr->child(field.fieldName.c_str());
|
auto child = rdr->child(field.fieldName.c_str());
|
||||||
walker->pushType(field.type);
|
walker->pushType(field.type);
|
||||||
oxReturnError(model(&child, walker));
|
OX_RETURN_ERROR(model(&child, walker));
|
||||||
walker->popType();
|
walker->popType();
|
||||||
rdr->nextField();
|
rdr->nextField();
|
||||||
} else {
|
} else {
|
||||||
// skip and discard absent field
|
// skip and discard absent field
|
||||||
int discard;
|
int discard;
|
||||||
oxReturnError(rdr->field(field.fieldName.c_str(), &discard));
|
OX_RETURN_ERROR(rdr->field(field.fieldName.c_str(), &discard));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -132,14 +132,14 @@ static constexpr Error parseField(const DescriptorField &field, Reader *rdr, Dat
|
|||||||
|
|
||||||
template<typename Reader, typename FH>
|
template<typename Reader, typename FH>
|
||||||
constexpr Error model(Reader *rdr, DataWalker<Reader, FH> *walker) noexcept {
|
constexpr Error model(Reader *rdr, DataWalker<Reader, FH> *walker) noexcept {
|
||||||
oxRequire(type, walker->type());
|
OX_REQUIRE(type, walker->type());
|
||||||
auto typeName = type->typeName.c_str();
|
auto typeName = type->typeName.c_str();
|
||||||
auto typeVersion = type->typeVersion;
|
auto typeVersion = type->typeVersion;
|
||||||
auto typeParams = type->typeParams;
|
auto typeParams = type->typeParams;
|
||||||
auto &fields = type->fieldList;
|
auto &fields = type->fieldList;
|
||||||
oxReturnError(rdr->setTypeInfo(typeName, typeVersion, typeParams, fields.size()));
|
OX_RETURN_ERROR(rdr->setTypeInfo(typeName, typeVersion, typeParams, fields.size()));
|
||||||
for (const auto &field : fields) {
|
for (const auto &field : fields) {
|
||||||
oxReturnError(parseField(field, rdr, walker));
|
OX_RETURN_ERROR(parseField(field, rdr, walker));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
2
deps/ox/src/ox/oc/read.cpp
vendored
2
deps/ox/src/ox/oc/read.cpp
vendored
@ -135,7 +135,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t b
|
|||||||
|
|
||||||
Error OrganicClawReader::field(const char *key, UUID *val) noexcept {
|
Error OrganicClawReader::field(const char *key, UUID *val) noexcept {
|
||||||
UUIDStr str;
|
UUIDStr str;
|
||||||
oxReturnError(field(key, &str));
|
OX_RETURN_ERROR(field(key, &str));
|
||||||
return UUID::fromString(str).moveTo(*val);
|
return UUID::fromString(str).moveTo(*val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
deps/ox/src/ox/oc/read.hpp
vendored
8
deps/ox/src/ox/oc/read.hpp
vendored
@ -152,7 +152,7 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept {
|
|||||||
} else if constexpr (isVector_v<T>) {
|
} else if constexpr (isVector_v<T>) {
|
||||||
const auto&srcVal = value(key);
|
const auto&srcVal = value(key);
|
||||||
const auto srcSize = srcVal.size();
|
const auto srcSize = srcVal.size();
|
||||||
oxReturnError(ox::resizeVector(*val, srcSize));
|
OX_RETURN_ERROR(ox::resizeVector(*val, srcSize));
|
||||||
err = field(key, val->data(), val->size());
|
err = field(key, val->data(), val->size());
|
||||||
} else if constexpr (isArray_v<T>) {
|
} else if constexpr (isArray_v<T>) {
|
||||||
const auto&srcVal = value(key);
|
const auto&srcVal = value(key);
|
||||||
@ -245,7 +245,7 @@ Error OrganicClawReader::field(const char *key, T *val, std::size_t valLen) noex
|
|||||||
ModelHandlerInterface handler{&r};
|
ModelHandlerInterface handler{&r};
|
||||||
for (decltype(srcSize) i = 0; i < srcSize; ++i) {
|
for (decltype(srcSize) i = 0; i < srcSize; ++i) {
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
oxReturnError(handler.field("", &val[i]));
|
OX_RETURN_ERROR(handler.field("", &val[i]));
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
@ -263,7 +263,7 @@ Error OrganicClawReader::field(const char *key, HashMap<String, T> *val) noexcep
|
|||||||
ModelHandlerInterface handler{&r};
|
ModelHandlerInterface handler{&r};
|
||||||
for (decltype(srcSize) i = 0; i < srcSize; ++i) {
|
for (decltype(srcSize) i = 0; i < srcSize; ++i) {
|
||||||
const auto k = keys[i].c_str();
|
const auto k = keys[i].c_str();
|
||||||
oxReturnError(handler.field(k, &val->operator[](k)));
|
OX_RETURN_ERROR(handler.field(k, &val->operator[](k)));
|
||||||
}
|
}
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
Result<T> readOC(BufferView buff) noexcept {
|
Result<T> readOC(BufferView buff) noexcept {
|
||||||
Result<T> val;
|
Result<T> val;
|
||||||
oxReturnError(readOC(buff, val.value));
|
OX_RETURN_ERROR(readOC(buff, val.value));
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
58
deps/ox/src/ox/oc/test/tests.cpp
vendored
58
deps/ox/src/ox/oc/test/tests.cpp
vendored
@ -74,44 +74,44 @@ struct TestStruct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestUnion> auto *obj) noexcept {
|
constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestUnion> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<TestUnion>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TestUnion>());
|
||||||
oxReturnError(io->field("Bool", &obj->Bool));
|
OX_RETURN_ERROR(io->field("Bool", &obj->Bool));
|
||||||
oxReturnError(io->field("Int", &obj->Int));
|
OX_RETURN_ERROR(io->field("Int", &obj->Int));
|
||||||
oxReturnError(io->fieldCString("String", &obj->String));
|
OX_RETURN_ERROR(io->fieldCString("String", &obj->String));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestStructNest> auto *obj) noexcept {
|
constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestStructNest> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<TestStructNest>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TestStructNest>());
|
||||||
oxReturnError(io->field("Bool", &obj->Bool));
|
OX_RETURN_ERROR(io->field("Bool", &obj->Bool));
|
||||||
oxReturnError(io->field("Int", &obj->Int));
|
OX_RETURN_ERROR(io->field("Int", &obj->Int));
|
||||||
oxReturnError(io->field("String", &obj->String));
|
OX_RETURN_ERROR(io->field("String", &obj->String));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestStruct> auto *obj) noexcept {
|
constexpr ox::Error model(auto *io, ox::CommonPtrWith<TestStruct> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<TestStruct>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TestStruct>());
|
||||||
oxReturnError(io->field("Bool", &obj->Bool));
|
OX_RETURN_ERROR(io->field("Bool", &obj->Bool));
|
||||||
oxReturnError(io->field("Int", &obj->Int));
|
OX_RETURN_ERROR(io->field("Int", &obj->Int));
|
||||||
oxReturnError(io->field("Int1", &obj->Int1));
|
OX_RETURN_ERROR(io->field("Int1", &obj->Int1));
|
||||||
oxReturnError(io->field("Int2", &obj->Int2));
|
OX_RETURN_ERROR(io->field("Int2", &obj->Int2));
|
||||||
oxReturnError(io->field("Int3", &obj->Int3));
|
OX_RETURN_ERROR(io->field("Int3", &obj->Int3));
|
||||||
oxReturnError(io->field("Int4", &obj->Int4));
|
OX_RETURN_ERROR(io->field("Int4", &obj->Int4));
|
||||||
oxReturnError(io->field("Int5", &obj->Int5));
|
OX_RETURN_ERROR(io->field("Int5", &obj->Int5));
|
||||||
oxReturnError(io->field("Int6", &obj->Int6));
|
OX_RETURN_ERROR(io->field("Int6", &obj->Int6));
|
||||||
oxReturnError(io->field("Int7", &obj->Int7));
|
OX_RETURN_ERROR(io->field("Int7", &obj->Int7));
|
||||||
oxReturnError(io->field("Int8", &obj->Int8));
|
OX_RETURN_ERROR(io->field("Int8", &obj->Int8));
|
||||||
oxReturnError(io->field("unionIdx", &obj->unionIdx));
|
OX_RETURN_ERROR(io->field("unionIdx", &obj->unionIdx));
|
||||||
if (io->opType() == ox::OpType::Reflect) {
|
if (io->opType() == ox::OpType::Reflect) {
|
||||||
oxReturnError(io->field("Union", ox::UnionView{&obj->Union, 0}));
|
OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, 0}));
|
||||||
} else {
|
} else {
|
||||||
oxReturnError(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx}));
|
OX_RETURN_ERROR(io->field("Union", ox::UnionView{&obj->Union, obj->unionIdx}));
|
||||||
}
|
}
|
||||||
oxReturnError(io->field("String", &obj->String));
|
OX_RETURN_ERROR(io->field("String", &obj->String));
|
||||||
oxReturnError(io->field("List", obj->List, 4));
|
OX_RETURN_ERROR(io->field("List", obj->List, 4));
|
||||||
oxReturnError(io->field("Map", &obj->Map));
|
OX_RETURN_ERROR(io->field("Map", &obj->Map));
|
||||||
oxReturnError(io->field("EmptyStruct", &obj->EmptyStruct));
|
OX_RETURN_ERROR(io->field("EmptyStruct", &obj->EmptyStruct));
|
||||||
oxReturnError(io->field("Struct", &obj->Struct));
|
OX_RETURN_ERROR(io->field("Struct", &obj->Struct));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
auto type = ox::buildTypeDef(typeStore, testIn);
|
auto type = ox::buildTypeDef(typeStore, testIn);
|
||||||
oxAssert(type.error, "Descriptor write failed");
|
oxAssert(type.error, "Descriptor write failed");
|
||||||
ox::ModelObject testOut;
|
ox::ModelObject testOut;
|
||||||
oxReturnError(testOut.setType(type.value));
|
OX_RETURN_ERROR(testOut.setType(type.value));
|
||||||
oxAssert(ox::readOC(dataBuff, 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");
|
||||||
@ -259,7 +259,7 @@ const std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
ox::TypeStore typeStore;
|
ox::TypeStore typeStore;
|
||||||
auto type = ox::buildTypeDef(typeStore, testIn);
|
auto type = ox::buildTypeDef(typeStore, testIn);
|
||||||
oxAssert(type.error, "Descriptor write failed");
|
oxAssert(type.error, "Descriptor write failed");
|
||||||
oxReturnError(ox::walkModel<ox::OrganicClawReader>(type.value, oc.data(), oc.size(),
|
OX_RETURN_ERROR(ox::walkModel<ox::OrganicClawReader>(type.value, oc.data(), oc.size(),
|
||||||
[](const ox::Vector<ox::FieldName>&, const ox::Vector<ox::String>&, const ox::DescriptorField &f,
|
[](const ox::Vector<ox::FieldName>&, const ox::Vector<ox::String>&, const ox::DescriptorField &f,
|
||||||
ox::OrganicClawReader *rdr) -> ox::Error {
|
ox::OrganicClawReader *rdr) -> ox::Error {
|
||||||
auto fieldName = f.fieldName.c_str();
|
auto fieldName = f.fieldName.c_str();
|
||||||
|
14
deps/ox/src/ox/oc/write.hpp
vendored
14
deps/ox/src/ox/oc/write.hpp
vendored
@ -122,8 +122,8 @@ class OrganicClawWriter {
|
|||||||
for (std::size_t i = 0; i < keys.size(); ++i) {
|
for (std::size_t i = 0; i < keys.size(); ++i) {
|
||||||
const auto k = keys[i].c_str();
|
const auto k = keys[i].c_str();
|
||||||
if (k) [[likely]] {
|
if (k) [[likely]] {
|
||||||
oxRequireM(value, val->at(k));
|
OX_REQUIRE_M(value, val->at(k));
|
||||||
oxReturnError(handler.field(k, value));
|
OX_RETURN_ERROR(handler.field(k, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value(key) = w.m_json;
|
value(key) = w.m_json;
|
||||||
@ -201,7 +201,7 @@ Error OrganicClawWriter::field(const char *key, const T *val, std::size_t len) n
|
|||||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
oxReturnError(handler.field({}, &val[i]));
|
OX_RETURN_ERROR(handler.field({}, &val[i]));
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
value(key) = w.m_json;
|
value(key) = w.m_json;
|
||||||
@ -227,7 +227,7 @@ Error OrganicClawWriter::field(const char *key, const T *val) noexcept {
|
|||||||
} else if (val && targetValid()) {
|
} else if (val && targetValid()) {
|
||||||
OrganicClawWriter w;
|
OrganicClawWriter w;
|
||||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||||
oxReturnError(model(&handler, val));
|
OX_RETURN_ERROR(model(&handler, val));
|
||||||
if (!w.m_json.empty() || m_json.isArray()) {
|
if (!w.m_json.empty() || m_json.isArray()) {
|
||||||
value(key) = w.m_json;
|
value(key) = w.m_json;
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
|
|||||||
if (targetValid()) {
|
if (targetValid()) {
|
||||||
OrganicClawWriter w(val.idx());
|
OrganicClawWriter w(val.idx());
|
||||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||||
oxReturnError(model(&handler, val.get()));
|
OX_RETURN_ERROR(model(&handler, val.get()));
|
||||||
if (!w.m_json.isNull()) {
|
if (!w.m_json.isNull()) {
|
||||||
value(key) = w.m_json;
|
value(key) = w.m_json;
|
||||||
}
|
}
|
||||||
@ -253,7 +253,7 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
|
|||||||
Result<ox::Buffer> writeOC(const auto &val) noexcept {
|
Result<ox::Buffer> writeOC(const auto &val) noexcept {
|
||||||
OrganicClawWriter writer;
|
OrganicClawWriter writer;
|
||||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
|
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
|
||||||
oxReturnError(model(&handler, &val));
|
OX_RETURN_ERROR(model(&handler, &val));
|
||||||
Json::StreamWriterBuilder const jsonBuilder;
|
Json::StreamWriterBuilder const jsonBuilder;
|
||||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||||
Result<Buffer> buff;
|
Result<Buffer> buff;
|
||||||
@ -265,7 +265,7 @@ Result<ox::Buffer> writeOC(const auto &val) noexcept {
|
|||||||
Result<ox::String> writeOCString(const auto &val) noexcept {
|
Result<ox::String> writeOCString(const auto &val) noexcept {
|
||||||
OrganicClawWriter writer;
|
OrganicClawWriter writer;
|
||||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
|
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
|
||||||
oxReturnError(model(&handler, &val));
|
OX_RETURN_ERROR(model(&handler, &val));
|
||||||
Json::StreamWriterBuilder const jsonBuilder;
|
Json::StreamWriterBuilder const jsonBuilder;
|
||||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||||
Result<ox::String> buff;
|
Result<ox::String> buff;
|
||||||
|
@ -63,7 +63,7 @@ struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>, OpT
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error field(StringViewCR, const T *val, std::size_t cnt) noexcept {
|
constexpr ox::Error field(StringViewCR, const T *val, std::size_t cnt) noexcept {
|
||||||
for (std::size_t i = 0; i < cnt; ++i) {
|
for (std::size_t i = 0; i < cnt; ++i) {
|
||||||
oxReturnError(field(nullptr, &val[i]));
|
OX_RETURN_ERROR(field(nullptr, &val[i]));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
68
deps/ox/src/ox/preloader/preloader.hpp
vendored
68
deps/ox/src/ox/preloader/preloader.hpp
vendored
@ -162,7 +162,7 @@ constexpr ox::Error Preloader<PlatSpec>::field(StringViewCR, const ox::UnionView
|
|||||||
if (!unionCheckAndIt()) {
|
if (!unionCheckAndIt()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
oxReturnError(pad(val.get()));
|
OX_RETURN_ERROR(pad(val.get()));
|
||||||
m_unionIdx.emplace_back(val.idx());
|
m_unionIdx.emplace_back(val.idx());
|
||||||
const auto err = preload<PlatSpec, U>(this, val.get());
|
const auto err = preload<PlatSpec, U>(this, val.get());
|
||||||
m_unionIdx.pop_back();
|
m_unionIdx.pop_back();
|
||||||
@ -175,13 +175,13 @@ constexpr ox::Error Preloader<PlatSpec>::field(StringViewCR name, const T *val)
|
|||||||
if (!unionCheckAndIt()) {
|
if (!unionCheckAndIt()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
oxReturnError(pad(val));
|
OX_RETURN_ERROR(pad(val));
|
||||||
if constexpr(ox::is_integral_v<T>) {
|
if constexpr(ox::is_integral_v<T>) {
|
||||||
return ox::serialize(m_writer, PlatSpec::correctEndianness(*val));
|
return ox::serialize(m_writer, PlatSpec::correctEndianness(*val));
|
||||||
} else if constexpr(ox::is_pointer_v<T>) {
|
} else if constexpr(ox::is_pointer_v<T>) {
|
||||||
const PtrType a = startAlloc(sizeOf<PlatSpec>(val), alignOf<PlatSpec>(*val), m_writer.tellp()) + PlatSpec::RomStart;
|
const PtrType a = startAlloc(sizeOf<PlatSpec>(val), alignOf<PlatSpec>(*val), m_writer.tellp()) + PlatSpec::RomStart;
|
||||||
oxReturnError(field(name, *val));
|
OX_RETURN_ERROR(field(name, *val));
|
||||||
oxReturnError(endAlloc());
|
OX_RETURN_ERROR(endAlloc());
|
||||||
return ox::serialize(m_writer, PlatSpec::correctEndianness(a));
|
return ox::serialize(m_writer, PlatSpec::correctEndianness(a));
|
||||||
} else if constexpr(ox::isVector_v<T>) {
|
} else if constexpr(ox::isVector_v<T>) {
|
||||||
return fieldVector(name, val);
|
return fieldVector(name, val);
|
||||||
@ -211,19 +211,19 @@ constexpr ox::Error Preloader<PlatSpec>::field(StringViewCR, const ox::BasicStri
|
|||||||
.size = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(sz)),
|
.size = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(sz)),
|
||||||
.cap = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(sz)),
|
.cap = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(sz)),
|
||||||
};
|
};
|
||||||
oxReturnError(pad(&vecVal));
|
OX_RETURN_ERROR(pad(&vecVal));
|
||||||
const auto restore = m_writer.tellp();
|
const auto restore = m_writer.tellp();
|
||||||
std::size_t a = 0;
|
std::size_t a = 0;
|
||||||
if (sz && sz >= SmallStringSize) {
|
if (sz && sz >= SmallStringSize) {
|
||||||
oxReturnError(ox::allocate(m_writer, sz).moveTo(a));
|
OX_RETURN_ERROR(ox::allocate(m_writer, sz).moveTo(a));
|
||||||
} else {
|
} else {
|
||||||
a = restore;
|
a = restore;
|
||||||
}
|
}
|
||||||
vecVal.items = PlatSpec::correctEndianness(static_cast<PtrType>(a) + PlatSpec::RomStart);
|
vecVal.items = PlatSpec::correctEndianness(static_cast<PtrType>(a) + PlatSpec::RomStart);
|
||||||
oxReturnError(m_writer.seekp(a));
|
OX_RETURN_ERROR(m_writer.seekp(a));
|
||||||
oxReturnError(m_writer.write(val->data(), sz));
|
OX_RETURN_ERROR(m_writer.write(val->data(), sz));
|
||||||
oxReturnError(m_writer.seekp(restore));
|
OX_RETURN_ERROR(m_writer.seekp(restore));
|
||||||
oxReturnError(serialize(m_writer, vecVal));
|
OX_RETURN_ERROR(serialize(m_writer, vecVal));
|
||||||
m_ptrs.emplace_back(restore + offsetof(VecMap, items), vecVal.items);
|
m_ptrs.emplace_back(restore + offsetof(VecMap, items), vecVal.items);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -234,12 +234,12 @@ constexpr ox::Error Preloader<PlatSpec>::field(StringViewCR name, const ox::Arra
|
|||||||
if (!unionCheckAndIt()) {
|
if (!unionCheckAndIt()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
oxReturnError(pad(&(*val)[0]));
|
OX_RETURN_ERROR(pad(&(*val)[0]));
|
||||||
// serialize the Array elements
|
// serialize the Array elements
|
||||||
if constexpr(sz) {
|
if constexpr(sz) {
|
||||||
m_unionIdx.emplace_back(-1);
|
m_unionIdx.emplace_back(-1);
|
||||||
for (std::size_t i = 0; i < val->size(); ++i) {
|
for (std::size_t i = 0; i < val->size(); ++i) {
|
||||||
oxReturnError(this->interface()->field(name, &(*val)[i]));
|
OX_RETURN_ERROR(this->interface()->field(name, &(*val)[i]));
|
||||||
}
|
}
|
||||||
m_unionIdx.pop_back();
|
m_unionIdx.pop_back();
|
||||||
}
|
}
|
||||||
@ -253,11 +253,11 @@ constexpr ox::Error Preloader<PlatSpec>::field(StringViewCR, const T **val, std:
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (cnt) {
|
if (cnt) {
|
||||||
oxReturnError(pad(*val));
|
OX_RETURN_ERROR(pad(*val));
|
||||||
// serialize the array
|
// serialize the array
|
||||||
m_unionIdx.emplace_back(-1);
|
m_unionIdx.emplace_back(-1);
|
||||||
for (std::size_t i = 0; i < cnt; ++i) {
|
for (std::size_t i = 0; i < cnt; ++i) {
|
||||||
oxReturnError(this->interface()->field(nullptr, &val[i]));
|
OX_RETURN_ERROR(this->interface()->field(nullptr, &val[i]));
|
||||||
}
|
}
|
||||||
m_unionIdx.pop_back();
|
m_unionIdx.pop_back();
|
||||||
}
|
}
|
||||||
@ -267,11 +267,11 @@ constexpr ox::Error Preloader<PlatSpec>::field(StringViewCR, const T **val, std:
|
|||||||
template<typename PlatSpec>
|
template<typename PlatSpec>
|
||||||
constexpr ox::Result<std::size_t> Preloader<PlatSpec>::startAlloc(size_t sz, size_t align) noexcept {
|
constexpr ox::Result<std::size_t> Preloader<PlatSpec>::startAlloc(size_t sz, size_t align) noexcept {
|
||||||
m_allocStack.emplace_back(static_cast<typename PlatSpec::PtrType>(m_writer.tellp()));
|
m_allocStack.emplace_back(static_cast<typename PlatSpec::PtrType>(m_writer.tellp()));
|
||||||
oxReturnError(m_writer.seekp(0, ox::ios_base::end));
|
OX_RETURN_ERROR(m_writer.seekp(0, ox::ios_base::end));
|
||||||
auto const padding = calcPadding(align);
|
auto const padding = calcPadding(align);
|
||||||
oxRequireM(a, ox::allocate(m_writer, sz + padding));
|
OX_REQUIRE_M(a, ox::allocate(m_writer, sz + padding));
|
||||||
a += padding;
|
a += padding;
|
||||||
oxReturnError(m_writer.seekp(a));
|
OX_RETURN_ERROR(m_writer.seekp(a));
|
||||||
m_allocStart.push_back(a);
|
m_allocStart.push_back(a);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@ -280,11 +280,11 @@ template<typename PlatSpec>
|
|||||||
constexpr ox::Result<std::size_t> Preloader<PlatSpec>::startAlloc(
|
constexpr ox::Result<std::size_t> Preloader<PlatSpec>::startAlloc(
|
||||||
std::size_t sz, size_t align, std::size_t restore) noexcept {
|
std::size_t sz, size_t align, std::size_t restore) noexcept {
|
||||||
m_allocStack.emplace_back(restore, ox::ios_base::beg);
|
m_allocStack.emplace_back(restore, ox::ios_base::beg);
|
||||||
oxReturnError(m_writer.seekp(0, ox::ios_base::end));
|
OX_RETURN_ERROR(m_writer.seekp(0, ox::ios_base::end));
|
||||||
auto const padding = calcPadding(align);
|
auto const padding = calcPadding(align);
|
||||||
oxRequireM(a, ox::allocate(m_writer, sz + padding));
|
OX_REQUIRE_M(a, ox::allocate(m_writer, sz + padding));
|
||||||
a += padding;
|
a += padding;
|
||||||
oxReturnError(m_writer.seekp(a));
|
OX_RETURN_ERROR(m_writer.seekp(a));
|
||||||
m_allocStart.push_back(a);
|
m_allocStart.push_back(a);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@ -295,7 +295,7 @@ constexpr ox::Error Preloader<PlatSpec>::endAlloc() noexcept {
|
|||||||
return m_writer.seekp(0, ox::ios_base::end);
|
return m_writer.seekp(0, ox::ios_base::end);
|
||||||
}
|
}
|
||||||
const auto &si = *m_allocStack.back().unwrap();
|
const auto &si = *m_allocStack.back().unwrap();
|
||||||
oxReturnError(m_writer.seekp(static_cast<ox::ssize_t>(si.restore), si.seekdir));
|
OX_RETURN_ERROR(m_writer.seekp(static_cast<ox::ssize_t>(si.restore), si.seekdir));
|
||||||
m_allocStack.pop_back();
|
m_allocStack.pop_back();
|
||||||
m_allocStart.pop_back();
|
m_allocStart.pop_back();
|
||||||
return {};
|
return {};
|
||||||
@ -304,12 +304,12 @@ constexpr ox::Error Preloader<PlatSpec>::endAlloc() noexcept {
|
|||||||
template<typename PlatSpec>
|
template<typename PlatSpec>
|
||||||
constexpr ox::Error Preloader<PlatSpec>::offsetPtrs(std::size_t offset) noexcept {
|
constexpr ox::Error Preloader<PlatSpec>::offsetPtrs(std::size_t offset) noexcept {
|
||||||
for (const auto &p : m_ptrs) {
|
for (const auto &p : m_ptrs) {
|
||||||
oxReturnError(m_writer.seekp(p.loc));
|
OX_RETURN_ERROR(m_writer.seekp(p.loc));
|
||||||
const auto val = PlatSpec::template correctEndianness<typename PlatSpec::PtrType>(
|
const auto val = PlatSpec::template correctEndianness<typename PlatSpec::PtrType>(
|
||||||
static_cast<typename PlatSpec::PtrType>(p.value + offset));
|
static_cast<typename PlatSpec::PtrType>(p.value + offset));
|
||||||
oxReturnError(ox::serialize(m_writer, val));
|
OX_RETURN_ERROR(ox::serialize(m_writer, val));
|
||||||
}
|
}
|
||||||
oxReturnError(m_writer.seekp(0, ox::ios_base::end));
|
OX_RETURN_ERROR(m_writer.seekp(0, ox::ios_base::end));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,39 +354,39 @@ constexpr ox::Error Preloader<PlatSpec>::fieldVector(
|
|||||||
template<typename PlatSpec>
|
template<typename PlatSpec>
|
||||||
constexpr ox::Error Preloader<PlatSpec>::fieldVector(
|
constexpr ox::Error Preloader<PlatSpec>::fieldVector(
|
||||||
StringViewCR, const auto *val, ox::VectorMemMap<PlatSpec> vecVal) noexcept {
|
StringViewCR, const auto *val, ox::VectorMemMap<PlatSpec> vecVal) noexcept {
|
||||||
oxReturnError(pad(&vecVal));
|
OX_RETURN_ERROR(pad(&vecVal));
|
||||||
const auto vecValPt = m_writer.tellp();
|
const auto vecValPt = m_writer.tellp();
|
||||||
// serialize the Vector elements
|
// serialize the Vector elements
|
||||||
if (val->size()) {
|
if (val->size()) {
|
||||||
const auto sz = sizeOf<PlatSpec>(&(*val)[0]) * val->size();
|
const auto sz = sizeOf<PlatSpec>(&(*val)[0]) * val->size();
|
||||||
const auto align = alignOf<PlatSpec>((*val)[0]);
|
const auto align = alignOf<PlatSpec>((*val)[0]);
|
||||||
oxReturnError(m_writer.seekp(0, ox::ios_base::end));
|
OX_RETURN_ERROR(m_writer.seekp(0, ox::ios_base::end));
|
||||||
auto const padding = calcPadding(align);
|
auto const padding = calcPadding(align);
|
||||||
oxRequireM(p, ox::allocate(m_writer, sz + padding));
|
OX_REQUIRE_M(p, ox::allocate(m_writer, sz + padding));
|
||||||
p += padding;
|
p += padding;
|
||||||
oxReturnError(m_writer.seekp(p));
|
OX_RETURN_ERROR(m_writer.seekp(p));
|
||||||
m_unionIdx.emplace_back(-1);
|
m_unionIdx.emplace_back(-1);
|
||||||
for (std::size_t i = 0; i < val->size(); ++i) {
|
for (std::size_t i = 0; i < val->size(); ++i) {
|
||||||
oxReturnError(this->interface()->field(nullptr, &val->operator[](i)));
|
OX_RETURN_ERROR(this->interface()->field(nullptr, &val->operator[](i)));
|
||||||
}
|
}
|
||||||
m_unionIdx.pop_back();
|
m_unionIdx.pop_back();
|
||||||
vecVal.items = PlatSpec::correctEndianness(
|
vecVal.items = PlatSpec::correctEndianness(
|
||||||
static_cast<typename PlatSpec::size_t>(p + PlatSpec::RomStart));
|
static_cast<typename PlatSpec::size_t>(p + PlatSpec::RomStart));
|
||||||
oxReturnError(m_writer.seekp(vecValPt));
|
OX_RETURN_ERROR(m_writer.seekp(vecValPt));
|
||||||
} else {
|
} else {
|
||||||
vecVal.items = 0;
|
vecVal.items = 0;
|
||||||
}
|
}
|
||||||
// serialize the Vector
|
// serialize the Vector
|
||||||
oxReturnError(serialize(m_writer, vecVal));
|
OX_RETURN_ERROR(serialize(m_writer, vecVal));
|
||||||
m_ptrs.emplace_back(m_writer.tellp() - PtrSize, vecVal.items);
|
m_ptrs.emplace_back(m_writer.tellp() - PtrSize, vecVal.items);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename PlatSpec>
|
template<typename PlatSpec>
|
||||||
constexpr ox::Error Preloader<PlatSpec>::fieldArray(StringViewCR, ox::ModelValueArray const*val) noexcept {
|
constexpr ox::Error Preloader<PlatSpec>::fieldArray(StringViewCR, ox::ModelValueArray const*val) noexcept {
|
||||||
oxReturnError(pad(&(*val)[0]));
|
OX_RETURN_ERROR(pad(&(*val)[0]));
|
||||||
for (auto const&v : *val) {
|
for (auto const&v : *val) {
|
||||||
oxReturnError(this->interface()->field({}, &v));
|
OX_RETURN_ERROR(this->interface()->field({}, &v));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -405,7 +405,7 @@ constexpr size_t Preloader<PlatSpec>::calcPadding(size_t align) const noexcept {
|
|||||||
|
|
||||||
template<typename PlatSpec, typename T>
|
template<typename PlatSpec, typename T>
|
||||||
constexpr ox::Error preload(Preloader<PlatSpec> *pl, ox::CommonPtrWith<T> auto *obj) noexcept {
|
constexpr ox::Error preload(Preloader<PlatSpec> *pl, ox::CommonPtrWith<T> auto *obj) noexcept {
|
||||||
oxReturnError(model(pl->interface(), obj));
|
OX_RETURN_ERROR(model(pl->interface(), obj));
|
||||||
return pl->pad(obj);
|
return pl->pad(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
deps/ox/src/ox/preloader/sizecatcher.hpp
vendored
4
deps/ox/src/ox/preloader/sizecatcher.hpp
vendored
@ -74,7 +74,7 @@ template<typename T, bool force>
|
|||||||
constexpr ox::Error SizeCatcher<PlatSpec>::field(const char*, const UnionView<T, force> val) noexcept {
|
constexpr ox::Error SizeCatcher<PlatSpec>::field(const char*, const UnionView<T, force> val) noexcept {
|
||||||
pad(val.get());
|
pad(val.get());
|
||||||
UnionSizeCatcher<PlatSpec> sc;
|
UnionSizeCatcher<PlatSpec> sc;
|
||||||
oxReturnError(model(sc.interface(), val.get()));
|
OX_RETURN_ERROR(model(sc.interface(), val.get()));
|
||||||
m_size += sc.size();
|
m_size += sc.size();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ template<typename PlatSpec>
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error SizeCatcher<PlatSpec>::field(const char*, const T **val, std::size_t cnt) noexcept {
|
constexpr ox::Error SizeCatcher<PlatSpec>::field(const char*, const T **val, std::size_t cnt) noexcept {
|
||||||
for (std::size_t i = 0; i < cnt; ++i) {
|
for (std::size_t i = 0; i < cnt; ++i) {
|
||||||
oxReturnError(field("", &val[i]));
|
OX_RETURN_ERROR(field("", &val[i]));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class UnionSizeCatcher: public ModelHandlerBase<UnionSizeCatcher<PlatSpec>, OpTy
|
|||||||
template<typename T, bool force>
|
template<typename T, bool force>
|
||||||
constexpr ox::Error field(StringViewCR, const UnionView<T, force> val) noexcept {
|
constexpr ox::Error field(StringViewCR, const UnionView<T, force> val) noexcept {
|
||||||
UnionSizeCatcher<PlatSpec> sc;
|
UnionSizeCatcher<PlatSpec> sc;
|
||||||
oxReturnError(model(sc.interface(), val.get()));
|
OX_RETURN_ERROR(model(sc.interface(), val.get()));
|
||||||
m_size += sc.size();
|
m_size += sc.size();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ template<typename PlatSpec>
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr ox::Error UnionSizeCatcher<PlatSpec>::field(StringViewCR, const T **val, std::size_t cnt) noexcept {
|
constexpr ox::Error UnionSizeCatcher<PlatSpec>::field(StringViewCR, const T **val, std::size_t cnt) noexcept {
|
||||||
for (std::size_t i = 0; i < cnt; ++i) {
|
for (std::size_t i = 0; i < cnt; ++i) {
|
||||||
oxReturnError(field("", &val[i]));
|
OX_RETURN_ERROR(field("", &val[i]));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
10
deps/ox/src/ox/std/bounds.hpp
vendored
10
deps/ox/src/ox/std/bounds.hpp
vendored
@ -126,11 +126,11 @@ constexpr void Bounds::set(const Point &pt1, const Point &pt2) noexcept {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<Bounds> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<Bounds> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<Bounds>());
|
OX_RETURN_ERROR(io->template setTypeInfo<Bounds>());
|
||||||
oxReturnError(io->field("x", &obj->x));
|
OX_RETURN_ERROR(io->field("x", &obj->x));
|
||||||
oxReturnError(io->field("y", &obj->y));
|
OX_RETURN_ERROR(io->field("y", &obj->y));
|
||||||
oxReturnError(io->field("width", &obj->width));
|
OX_RETURN_ERROR(io->field("width", &obj->width));
|
||||||
oxReturnError(io->field("height", &obj->height));
|
OX_RETURN_ERROR(io->field("height", &obj->height));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
deps/ox/src/ox/std/def.hpp
vendored
12
deps/ox/src/ox/std/def.hpp
vendored
@ -37,13 +37,13 @@
|
|||||||
|
|
||||||
// Error handling
|
// Error handling
|
||||||
|
|
||||||
#define oxReturnError(x) { if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] return _ox_error; } (void) 0
|
#define OX_RETURN_ERROR(x) { if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] return _ox_error; } (void) 0
|
||||||
#define oxThrowError(x) { if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] throw ox::Exception(_ox_error); } (void) 0
|
#define OX_THROW_ERROR(x) { if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] throw ox::Exception(_ox_error); } (void) 0
|
||||||
#define oxConcatImpl(a, b) a##b
|
#define OX_CONCAT_IMPL(a, b) a##b
|
||||||
#define oxConcat(a, b) oxConcatImpl(a, b)
|
#define OX_CONCAT(a, b) OX_CONCAT_IMPL(a, b)
|
||||||
// oxRequire Mutable
|
// oxRequire Mutable
|
||||||
#define oxRequireM(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__))
|
#define OX_REQUIRE_M(out, x) auto [out, OX_CONCAT(oxRequire_err_, __LINE__)] = x; OX_RETURN_ERROR(OX_CONCAT(oxRequire_err_, __LINE__))
|
||||||
#define oxRequire(out, x) const oxRequireM(out, x)
|
#define OX_REQUIRE(out, x) const OX_REQUIRE_M(out, x)
|
||||||
|
|
||||||
|
|
||||||
// Asserts
|
// Asserts
|
||||||
|
2
deps/ox/src/ox/std/defer.hpp
vendored
2
deps/ox/src/ox/std/defer.hpp
vendored
@ -31,4 +31,4 @@ class Defer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define oxDefer ox::Defer const oxConcat(oxDefer_, __LINE__) =
|
#define OX_DEFER ox::Defer const OX_CONCAT(oxDefer_, __LINE__) =
|
||||||
|
6
deps/ox/src/ox/std/point.hpp
vendored
6
deps/ox/src/ox/std/point.hpp
vendored
@ -189,9 +189,9 @@ constexpr bool Point::operator!=(const Point &p) const noexcept {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<Point> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<Point> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<Point>());
|
OX_RETURN_ERROR(io->template setTypeInfo<Point>());
|
||||||
oxReturnError(io->field("x", &obj->x));
|
OX_RETURN_ERROR(io->field("x", &obj->x));
|
||||||
oxReturnError(io->field("y", &obj->y));
|
OX_RETURN_ERROR(io->field("y", &obj->y));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
deps/ox/src/ox/std/serialize.hpp
vendored
10
deps/ox/src/ox/std/serialize.hpp
vendored
@ -63,10 +63,10 @@ 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 ox::Error serialize(Writer_c auto &w, const VectorMemMap<PlatSpec> &vm) noexcept {
|
||||||
oxReturnError(w.write(nullptr, vm.smallVecSize));
|
OX_RETURN_ERROR(w.write(nullptr, vm.smallVecSize));
|
||||||
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.size)));
|
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.size)));
|
||||||
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.cap)));
|
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.cap)));
|
||||||
oxReturnError(serialize(w, PlatSpec::correctEndianness(vm.items)));
|
OX_RETURN_ERROR(serialize(w, PlatSpec::correctEndianness(vm.items)));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ template<typename T>
|
|||||||
constexpr ox::Result<ox::Array<char, sizeof(T)>> serialize(const T &in) noexcept {
|
constexpr ox::Result<ox::Array<char, sizeof(T)>> serialize(const T &in) noexcept {
|
||||||
ox::Array<char, sizeof(T)> out = {};
|
ox::Array<char, sizeof(T)> out = {};
|
||||||
CharBuffWriter w(out);
|
CharBuffWriter w(out);
|
||||||
oxReturnError(serialize(w, in));
|
OX_RETURN_ERROR(serialize(w, in));
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
6
deps/ox/src/ox/std/size.hpp
vendored
6
deps/ox/src/ox/std/size.hpp
vendored
@ -190,9 +190,9 @@ constexpr bool Size::operator!=(const Size &p) const noexcept {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<Size> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<Size> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<Size>());
|
OX_RETURN_ERROR(io->template setTypeInfo<Size>());
|
||||||
oxReturnError(io->field("width", &obj->width));
|
OX_RETURN_ERROR(io->field("width", &obj->width));
|
||||||
oxReturnError(io->field("height", &obj->height));
|
OX_RETURN_ERROR(io->field("height", &obj->height));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
deps/ox/src/ox/std/smallmap.hpp
vendored
4
deps/ox/src/ox/std/smallmap.hpp
vendored
@ -247,8 +247,8 @@ constexpr typename SmallMap<K, T, SmallSz>::Pair &SmallMap<K, T, SmallSz>::acces
|
|||||||
template<typename T, typename K, typename V, size_t SmallSz>
|
template<typename T, typename K, typename V, size_t SmallSz>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<SmallMap<K, V, SmallSz>> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<SmallMap<K, V, SmallSz>> auto *obj) noexcept {
|
||||||
using Map = SmallMap<K, V, SmallSz>;
|
using Map = SmallMap<K, V, SmallSz>;
|
||||||
oxReturnError(io->template setTypeInfo<Map>());
|
OX_RETURN_ERROR(io->template setTypeInfo<Map>());
|
||||||
oxReturnError(io->field("pairs", &obj->m_pairs));
|
OX_RETURN_ERROR(io->field("pairs", &obj->m_pairs));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
deps/ox/src/ox/std/strconv.hpp
vendored
6
deps/ox/src/ox/std/strconv.hpp
vendored
@ -24,7 +24,7 @@ constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept {
|
|||||||
constexpr auto base = 10;
|
constexpr auto base = 10;
|
||||||
auto it = 0;
|
auto it = 0;
|
||||||
if (val < 0) {
|
if (val < 0) {
|
||||||
oxReturnError(writer.put('-'));
|
OX_RETURN_ERROR(writer.put('-'));
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
while (mod) {
|
while (mod) {
|
||||||
@ -37,13 +37,13 @@ constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept {
|
|||||||
start = 'a';
|
start = 'a';
|
||||||
digit -= 10;
|
digit -= 10;
|
||||||
}
|
}
|
||||||
oxReturnError(writer.put(static_cast<char>(start + digit)));
|
OX_RETURN_ERROR(writer.put(static_cast<char>(start + digit)));
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 0 is a special case
|
// 0 is a special case
|
||||||
oxReturnError(writer.put('0'));
|
OX_RETURN_ERROR(writer.put('0'));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
18
deps/ox/src/ox/std/test/tests.cpp
vendored
18
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -136,10 +136,10 @@ OX_CLANG_NOWARN_END
|
|||||||
ox::CharBuffWriter bw(buff);
|
ox::CharBuffWriter bw(buff);
|
||||||
oxAssert(ox::writeItoa(5, bw), "ox::writeItoa returned Error");
|
oxAssert(ox::writeItoa(5, bw), "ox::writeItoa returned Error");
|
||||||
oxExpect(ox::StringView(buff.data()), ox::StringView("5"));
|
oxExpect(ox::StringView(buff.data()), ox::StringView("5"));
|
||||||
oxReturnError(bw.seekp(0));
|
OX_RETURN_ERROR(bw.seekp(0));
|
||||||
oxAssert(ox::writeItoa(50, bw), "ox::writeItoa returned Error");
|
oxAssert(ox::writeItoa(50, bw), "ox::writeItoa returned Error");
|
||||||
oxExpect(ox::StringView(buff.data()), ox::StringView("50"));
|
oxExpect(ox::StringView(buff.data()), ox::StringView("50"));
|
||||||
oxReturnError(bw.seekp(0));
|
OX_RETURN_ERROR(bw.seekp(0));
|
||||||
oxAssert(ox::writeItoa(500, bw), "ox::writeItoa returned Error");
|
oxAssert(ox::writeItoa(500, bw), "ox::writeItoa returned Error");
|
||||||
oxExpect(ox::StringView(buff.data()), ox::StringView("500"));
|
oxExpect(ox::StringView(buff.data()), ox::StringView("500"));
|
||||||
return ox::Error{};
|
return ox::Error{};
|
||||||
@ -173,10 +173,10 @@ OX_CLANG_NOWARN_END
|
|||||||
"IString",
|
"IString",
|
||||||
[]() {
|
[]() {
|
||||||
ox::IString<5> s;
|
ox::IString<5> s;
|
||||||
oxReturnError(s.append("A"));
|
OX_RETURN_ERROR(s.append("A"));
|
||||||
oxReturnError(s.append("B"));
|
OX_RETURN_ERROR(s.append("B"));
|
||||||
oxReturnError(s.append("9"));
|
OX_RETURN_ERROR(s.append("9"));
|
||||||
oxReturnError(s.append("C"));
|
OX_RETURN_ERROR(s.append("C"));
|
||||||
oxAssert(s == "AB9C", "IString append broken");
|
oxAssert(s == "AB9C", "IString append broken");
|
||||||
s = "asdf";
|
s = "asdf";
|
||||||
oxAssert(s == "asdf", "String assign broken");
|
oxAssert(s == "asdf", "String assign broken");
|
||||||
@ -227,8 +227,8 @@ OX_CLANG_NOWARN_END
|
|||||||
oxAssert(v.empty(), "Vector::empty() is broken");
|
oxAssert(v.empty(), "Vector::empty() is broken");
|
||||||
auto insertTest = [&v](int val, std::size_t size) {
|
auto insertTest = [&v](int val, std::size_t size) {
|
||||||
v.push_back(val);
|
v.push_back(val);
|
||||||
oxReturnError(ox::Error(v.size() != size, "Vector size incorrect"));
|
OX_RETURN_ERROR(ox::Error(v.size() != size, "Vector size incorrect"));
|
||||||
oxReturnError(ox::Error(v[v.size() - 1] != val, "Vector value wrong"));
|
OX_RETURN_ERROR(ox::Error(v[v.size() - 1] != val, "Vector value wrong"));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
};
|
};
|
||||||
oxAssert(insertTest(42, 1), "Vector insertion failed");
|
oxAssert(insertTest(42, 1), "Vector insertion failed");
|
||||||
@ -386,7 +386,7 @@ OX_CLANG_NOWARN_END
|
|||||||
"UUID",
|
"UUID",
|
||||||
[] {
|
[] {
|
||||||
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
|
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
|
||||||
oxRequire(uuid, ox::UUID::fromString(uuidStr));
|
OX_REQUIRE(uuid, ox::UUID::fromString(uuidStr));
|
||||||
oxExpect(uuid.toString(), uuidStr);
|
oxExpect(uuid.toString(), uuidStr);
|
||||||
oxExpect(ox::UUID{}.isNull(), true);
|
oxExpect(ox::UUID{}.isNull(), true);
|
||||||
oxExpect(ox::UUID::fromString(uuidStr).value.isNull(), false);
|
oxExpect(ox::UUID::fromString(uuidStr).value.isNull(), false);
|
||||||
|
32
deps/ox/src/ox/std/trace.hpp
vendored
32
deps/ox/src/ox/std/trace.hpp
vendored
@ -48,12 +48,12 @@ struct TraceMsgRcv {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<TraceMsgRcv> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<TraceMsgRcv> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<TraceMsgRcv>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TraceMsgRcv>());
|
||||||
oxReturnError(io->field("file", &obj->file));
|
OX_RETURN_ERROR(io->field("file", &obj->file));
|
||||||
oxReturnError(io->field("line", &obj->line));
|
OX_RETURN_ERROR(io->field("line", &obj->line));
|
||||||
oxReturnError(io->field("time", &obj->time));
|
OX_RETURN_ERROR(io->field("time", &obj->time));
|
||||||
oxReturnError(io->field("ch", &obj->ch));
|
OX_RETURN_ERROR(io->field("ch", &obj->ch));
|
||||||
oxReturnError(io->field("msg", &obj->msg));
|
OX_RETURN_ERROR(io->field("msg", &obj->msg));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,12 +69,12 @@ struct TraceMsg {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<TraceMsg> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<TraceMsg> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<TraceMsg>());
|
OX_RETURN_ERROR(io->template setTypeInfo<TraceMsg>());
|
||||||
oxReturnError(io->fieldCString("file", &obj->file));
|
OX_RETURN_ERROR(io->fieldCString("file", &obj->file));
|
||||||
oxReturnError(io->field("line", &obj->line));
|
OX_RETURN_ERROR(io->field("line", &obj->line));
|
||||||
oxReturnError(io->field("time", &obj->time));
|
OX_RETURN_ERROR(io->field("time", &obj->time));
|
||||||
oxReturnError(io->fieldCString("ch", &obj->ch));
|
OX_RETURN_ERROR(io->fieldCString("ch", &obj->ch));
|
||||||
oxReturnError(io->field("msg", &obj->msg));
|
OX_RETURN_ERROR(io->field("msg", &obj->msg));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ struct InitTraceMsgRcv {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<InitTraceMsgRcv> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<InitTraceMsgRcv> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<InitTraceMsgRcv>());
|
OX_RETURN_ERROR(io->template setTypeInfo<InitTraceMsgRcv>());
|
||||||
oxReturnError(io->field("appName", &obj->appName));
|
OX_RETURN_ERROR(io->field("appName", &obj->appName));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +101,8 @@ struct InitTraceMsg {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<InitTraceMsg> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<InitTraceMsg> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<InitTraceMsg>());
|
OX_RETURN_ERROR(io->template setTypeInfo<InitTraceMsg>());
|
||||||
oxReturnError(io->field("appName", &obj->appName));
|
OX_RETURN_ERROR(io->field("appName", &obj->appName));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
deps/ox/src/ox/std/uuid.hpp
vendored
14
deps/ox/src/ox/std/uuid.hpp
vendored
@ -143,7 +143,7 @@ class UUID {
|
|||||||
if (seg.len() != 2) {
|
if (seg.len() != 2) {
|
||||||
return ox::Error(1, "Invalid UUID");
|
return ox::Error(1, "Invalid UUID");
|
||||||
}
|
}
|
||||||
oxRequire(val, detail::fromHex(seg));
|
OX_REQUIRE(val, detail::fromHex(seg));
|
||||||
out.m_value[valueI] = val;
|
out.m_value[valueI] = val;
|
||||||
i += 2;
|
i += 2;
|
||||||
++valueI;
|
++valueI;
|
||||||
@ -175,13 +175,13 @@ class UUID {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
printChars(writer, m_value, 4, valueI);
|
printChars(writer, m_value, 4, valueI);
|
||||||
oxReturnError(writer.put('-'));
|
OX_RETURN_ERROR(writer.put('-'));
|
||||||
printChars(writer, m_value, 2, valueI);
|
printChars(writer, m_value, 2, valueI);
|
||||||
oxReturnError(writer.put('-'));
|
OX_RETURN_ERROR(writer.put('-'));
|
||||||
printChars(writer, m_value, 2, valueI);
|
printChars(writer, m_value, 2, valueI);
|
||||||
oxReturnError(writer.put('-'));
|
OX_RETURN_ERROR(writer.put('-'));
|
||||||
printChars(writer, m_value, 2, valueI);
|
printChars(writer, m_value, 2, valueI);
|
||||||
oxReturnError(writer.put('-'));
|
OX_RETURN_ERROR(writer.put('-'));
|
||||||
printChars(writer, m_value, 6, valueI);
|
printChars(writer, m_value, 6, valueI);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -217,8 +217,8 @@ struct hash<ox::UUID> {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<UUID> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<UUID> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<UUID>());
|
OX_RETURN_ERROR(io->template setTypeInfo<UUID>());
|
||||||
oxReturnError(io->field("value", &obj->m_value));
|
OX_RETURN_ERROR(io->field("value", &obj->m_value));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
deps/ox/src/ox/std/vec.cpp
vendored
4
deps/ox/src/ox/std/vec.cpp
vendored
@ -6,15 +6,13 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ox/std/defines.hpp>
|
|
||||||
|
|
||||||
#include "vec.hpp"
|
#include "vec.hpp"
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
static_assert([] {
|
static_assert([] {
|
||||||
Vec2 v(1, 2);
|
Vec2 v(1, 2);
|
||||||
return v.x == 1 && v.y == 2 && v.size() == 2;
|
return v.x == 1 && v.y == 2;
|
||||||
}());
|
}());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
21
deps/ox/src/ox/std/vec.hpp
vendored
21
deps/ox/src/ox/std/vec.hpp
vendored
@ -12,13 +12,9 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ox/model/def.hpp>
|
#include <ox/std/concepts.hpp>
|
||||||
#include <ox/std/assert.hpp>
|
|
||||||
#include <ox/std/bit.hpp>
|
|
||||||
#include <ox/std/def.hpp>
|
#include <ox/std/def.hpp>
|
||||||
#include <ox/std/error.hpp>
|
#include <ox/std/error.hpp>
|
||||||
#include <ox/std/iterator.hpp>
|
|
||||||
#include <ox/std/math.hpp>
|
|
||||||
#include <ox/std/types.hpp>
|
#include <ox/std/types.hpp>
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
@ -61,15 +57,6 @@ class Vec2 {
|
|||||||
return !operator==(v);
|
return !operator==(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit constexpr operator class Point() const noexcept;
|
|
||||||
|
|
||||||
explicit constexpr operator class Size() const noexcept;
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
constexpr std::size_t size() const noexcept {
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Vec2 operator+(float i) const noexcept {
|
constexpr Vec2 operator+(float i) const noexcept {
|
||||||
return {x + i, y + i};
|
return {x + i, y + i};
|
||||||
}
|
}
|
||||||
@ -113,9 +100,9 @@ class Vec2 {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr Error model(T *io, ox::CommonPtrWith<Vec2> auto *obj) noexcept {
|
constexpr Error model(T *io, ox::CommonPtrWith<Vec2> auto *obj) noexcept {
|
||||||
oxReturnError(io->template setTypeInfo<Vec2>());
|
OX_RETURN_ERROR(io->template setTypeInfo<Vec2>());
|
||||||
oxReturnError(io->field("x", &obj->x));
|
OX_RETURN_ERROR(io->field("x", &obj->x));
|
||||||
oxReturnError(io->field("y", &obj->y));
|
OX_RETURN_ERROR(io->field("y", &obj->y));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
deps/ox/src/ox/std/writer.hpp
vendored
6
deps/ox/src/ox/std/writer.hpp
vendored
@ -74,10 +74,10 @@ class WriterT: public Writer_v {
|
|||||||
*/
|
*/
|
||||||
constexpr ox::Result<std::size_t> allocate(Writer_c auto &writer, std::size_t sz) noexcept {
|
constexpr ox::Result<std::size_t> allocate(Writer_c auto &writer, std::size_t sz) noexcept {
|
||||||
const auto p = writer.tellp();
|
const auto p = writer.tellp();
|
||||||
oxReturnError(writer.seekp(0, ios_base::end));
|
OX_RETURN_ERROR(writer.seekp(0, ios_base::end));
|
||||||
const auto out = writer.tellp();
|
const auto out = writer.tellp();
|
||||||
oxReturnError(writer.write(nullptr, sz));
|
OX_RETURN_ERROR(writer.write(nullptr, sz));
|
||||||
oxReturnError(writer.seekp(p));
|
OX_RETURN_ERROR(writer.seekp(p));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,18 +32,18 @@ struct Sprite {
|
|||||||
unsigned priority = 0;
|
unsigned priority = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(Sprite)
|
OX_MODEL_BEGIN(Sprite)
|
||||||
oxModelField(idx)
|
OX_MODEL_FIELD(idx)
|
||||||
oxModelField(x)
|
OX_MODEL_FIELD(x)
|
||||||
oxModelField(y)
|
OX_MODEL_FIELD(y)
|
||||||
oxModelField(enabled)
|
OX_MODEL_FIELD(enabled)
|
||||||
oxModelField(tileIdx)
|
OX_MODEL_FIELD(tileIdx)
|
||||||
oxModelField(spriteShape)
|
OX_MODEL_FIELD(spriteShape)
|
||||||
oxModelField(spriteSize)
|
OX_MODEL_FIELD(spriteSize)
|
||||||
oxModelField(flipX)
|
OX_MODEL_FIELD(flipX)
|
||||||
oxModelField(bpp)
|
OX_MODEL_FIELD(bpp)
|
||||||
oxModelField(priority)
|
OX_MODEL_FIELD(priority)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
struct BgTile {
|
struct BgTile {
|
||||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.BgTile";
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.BgTile";
|
||||||
@ -54,12 +54,12 @@ struct BgTile {
|
|||||||
unsigned flipY = false;
|
unsigned flipY = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(BgTile)
|
OX_MODEL_BEGIN(BgTile)
|
||||||
oxModelField(tileIdx)
|
OX_MODEL_FIELD(tileIdx)
|
||||||
oxModelField(palBank)
|
OX_MODEL_FIELD(palBank)
|
||||||
oxModelField(horizontalFlip)
|
OX_MODEL_FIELD(horizontalFlip)
|
||||||
oxModelField(verticalFlip)
|
OX_MODEL_FIELD(verticalFlip)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
struct TileSheetSetEntrySection {
|
struct TileSheetSetEntrySection {
|
||||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSetEntrySection";
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSetEntrySection";
|
||||||
@ -72,10 +72,10 @@ struct TileSheetSetEntrySection {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(TileSheetSetEntrySection)
|
OX_MODEL_BEGIN(TileSheetSetEntrySection)
|
||||||
oxModelField(begin)
|
OX_MODEL_FIELD(begin)
|
||||||
oxModelField(tiles)
|
OX_MODEL_FIELD(tiles)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
struct TileSheetSetEntry {
|
struct TileSheetSetEntry {
|
||||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSetEntry";
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSetEntry";
|
||||||
@ -84,10 +84,10 @@ struct TileSheetSetEntry {
|
|||||||
ox::Vector<TileSheetSetEntrySection> sections;
|
ox::Vector<TileSheetSetEntrySection> sections;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(TileSheetSetEntry)
|
OX_MODEL_BEGIN(TileSheetSetEntry)
|
||||||
oxModelField(tilesheet)
|
OX_MODEL_FIELD(tilesheet)
|
||||||
oxModelField(sections)
|
OX_MODEL_FIELD(sections)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
struct TileSheetSet {
|
struct TileSheetSet {
|
||||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSet";
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSet";
|
||||||
@ -97,10 +97,10 @@ struct TileSheetSet {
|
|||||||
ox::Vector<TileSheetSetEntry> entries;
|
ox::Vector<TileSheetSetEntry> entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(TileSheetSet)
|
OX_MODEL_BEGIN(TileSheetSet)
|
||||||
oxModelField(bpp)
|
OX_MODEL_FIELD(bpp)
|
||||||
oxModelField(entries)
|
OX_MODEL_FIELD(entries)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
void addEntry(TileSheetSet &set, ox::FileAddress path, int32_t begin = 0, int32_t size = -1) noexcept;
|
void addEntry(TileSheetSet &set, ox::FileAddress path, int32_t begin = 0, int32_t size = -1) noexcept;
|
||||||
|
|
||||||
|
@ -26,12 +26,12 @@ struct PaletteColorV1 {
|
|||||||
constexpr operator Color16() const noexcept { return color16(r, g, b, a); }
|
constexpr operator Color16() const noexcept { return color16(r, g, b, a); }
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(PaletteColorV1)
|
OX_MODEL_BEGIN(PaletteColorV1)
|
||||||
oxModelField(r)
|
OX_MODEL_FIELD(r)
|
||||||
oxModelField(g)
|
OX_MODEL_FIELD(g)
|
||||||
oxModelField(b)
|
OX_MODEL_FIELD(b)
|
||||||
oxModelField(a)
|
OX_MODEL_FIELD(a)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
using PaletteColor = PaletteColorV1;
|
using PaletteColor = PaletteColorV1;
|
||||||
|
|
||||||
@ -53,10 +53,10 @@ struct PalettePageV1 {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(PalettePageV1)
|
OX_MODEL_BEGIN(PalettePageV1)
|
||||||
oxModelField(name)
|
OX_MODEL_FIELD(name)
|
||||||
oxModelField(colors)
|
OX_MODEL_FIELD(colors)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
using PalettePage = PalettePageV1;
|
using PalettePage = PalettePageV1;
|
||||||
|
|
||||||
@ -67,9 +67,9 @@ struct NostalgiaPalette {
|
|||||||
ox::Vector<Color16> colors = {};
|
ox::Vector<Color16> colors = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(NostalgiaPalette)
|
OX_MODEL_BEGIN(NostalgiaPalette)
|
||||||
oxModelField(colors)
|
OX_MODEL_FIELD(colors)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
|
|
||||||
struct PaletteV1 {
|
struct PaletteV1 {
|
||||||
@ -78,9 +78,9 @@ struct PaletteV1 {
|
|||||||
ox::Vector<Color16> colors;
|
ox::Vector<Color16> colors;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(PaletteV1)
|
OX_MODEL_BEGIN(PaletteV1)
|
||||||
oxModelField(colors)
|
OX_MODEL_FIELD(colors)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
|
|
||||||
struct PaletteV2 {
|
struct PaletteV2 {
|
||||||
@ -90,9 +90,9 @@ struct PaletteV2 {
|
|||||||
ox::Vector<ox::Vector<Color16>> pages;
|
ox::Vector<ox::Vector<Color16>> pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(PaletteV2)
|
OX_MODEL_BEGIN(PaletteV2)
|
||||||
oxModelField(pages)
|
OX_MODEL_FIELD(pages)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
|
|
||||||
struct PaletteV3 {
|
struct PaletteV3 {
|
||||||
@ -110,14 +110,14 @@ struct PaletteV3 {
|
|||||||
ox::Vector<ox::Vector<Color16>> pages;
|
ox::Vector<ox::Vector<Color16>> pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(PaletteV3::ColorInfo)
|
OX_MODEL_BEGIN(PaletteV3::ColorInfo)
|
||||||
oxModelField(name)
|
OX_MODEL_FIELD(name)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(PaletteV3)
|
OX_MODEL_BEGIN(PaletteV3)
|
||||||
oxModelField(colorInfo)
|
OX_MODEL_FIELD(colorInfo)
|
||||||
oxModelField(pages)
|
OX_MODEL_FIELD(pages)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool valid(PaletteV3 const&p) noexcept {
|
constexpr bool valid(PaletteV3 const&p) noexcept {
|
||||||
@ -144,10 +144,10 @@ struct PaletteV4 {
|
|||||||
ox::Vector<PalettePageV1> pages;
|
ox::Vector<PalettePageV1> pages;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(PaletteV4)
|
OX_MODEL_BEGIN(PaletteV4)
|
||||||
oxModelField(colorNames)
|
OX_MODEL_FIELD(colorNames)
|
||||||
oxModelField(pages)
|
OX_MODEL_FIELD(pages)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool valid(PaletteV4 const&p) noexcept {
|
constexpr bool valid(PaletteV4 const&p) noexcept {
|
||||||
@ -176,9 +176,9 @@ struct CompactPaletteV1 {
|
|||||||
ox::Vector<ox::Vector<Color16>> pages{};
|
ox::Vector<ox::Vector<Color16>> pages{};
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(CompactPaletteV1)
|
OX_MODEL_BEGIN(CompactPaletteV1)
|
||||||
oxModelField(pages)
|
OX_MODEL_FIELD(pages)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr bool valid(CompactPaletteV1 const&p) noexcept {
|
constexpr bool valid(CompactPaletteV1 const&p) noexcept {
|
||||||
|
@ -437,65 +437,65 @@ ox::Pair<uint8_t> get2Pixels8Bpp(
|
|||||||
CompactTileSheet const&ts,
|
CompactTileSheet const&ts,
|
||||||
size_t idx) noexcept;
|
size_t idx) noexcept;
|
||||||
|
|
||||||
oxModelBegin(TileSheetV1)
|
OX_MODEL_BEGIN(TileSheetV1)
|
||||||
oxModelField(bpp)
|
OX_MODEL_FIELD(bpp)
|
||||||
oxModelField(rows)
|
OX_MODEL_FIELD(rows)
|
||||||
oxModelField(columns)
|
OX_MODEL_FIELD(columns)
|
||||||
oxModelField(defaultPalette)
|
OX_MODEL_FIELD(defaultPalette)
|
||||||
oxModelField(pal)
|
OX_MODEL_FIELD(pal)
|
||||||
oxModelField(pixels)
|
OX_MODEL_FIELD(pixels)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(TileSheetV2::SubSheet)
|
OX_MODEL_BEGIN(TileSheetV2::SubSheet)
|
||||||
oxModelField(name)
|
OX_MODEL_FIELD(name)
|
||||||
oxModelField(rows)
|
OX_MODEL_FIELD(rows)
|
||||||
oxModelField(columns)
|
OX_MODEL_FIELD(columns)
|
||||||
oxModelField(subsheets)
|
OX_MODEL_FIELD(subsheets)
|
||||||
oxModelField(pixels)
|
OX_MODEL_FIELD(pixels)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(TileSheetV2)
|
OX_MODEL_BEGIN(TileSheetV2)
|
||||||
oxModelField(bpp)
|
OX_MODEL_FIELD(bpp)
|
||||||
oxModelField(defaultPalette)
|
OX_MODEL_FIELD(defaultPalette)
|
||||||
oxModelField(subsheet)
|
OX_MODEL_FIELD(subsheet)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(TileSheetV3::SubSheet)
|
OX_MODEL_BEGIN(TileSheetV3::SubSheet)
|
||||||
oxModelField(name)
|
OX_MODEL_FIELD(name)
|
||||||
oxModelField(rows)
|
OX_MODEL_FIELD(rows)
|
||||||
oxModelField(columns)
|
OX_MODEL_FIELD(columns)
|
||||||
oxModelField(subsheets)
|
OX_MODEL_FIELD(subsheets)
|
||||||
oxModelField(pixels)
|
OX_MODEL_FIELD(pixels)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(TileSheetV3)
|
OX_MODEL_BEGIN(TileSheetV3)
|
||||||
oxModelField(bpp)
|
OX_MODEL_FIELD(bpp)
|
||||||
oxModelField(idIt)
|
OX_MODEL_FIELD(idIt)
|
||||||
oxModelField(defaultPalette)
|
OX_MODEL_FIELD(defaultPalette)
|
||||||
oxModelField(subsheet)
|
OX_MODEL_FIELD(subsheet)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(TileSheetV4::SubSheet)
|
OX_MODEL_BEGIN(TileSheetV4::SubSheet)
|
||||||
oxModelField(id)
|
OX_MODEL_FIELD(id)
|
||||||
oxModelField(name)
|
OX_MODEL_FIELD(name)
|
||||||
oxModelField(rows)
|
OX_MODEL_FIELD(rows)
|
||||||
oxModelField(columns)
|
OX_MODEL_FIELD(columns)
|
||||||
oxModelField(subsheets)
|
OX_MODEL_FIELD(subsheets)
|
||||||
oxModelField(pixels)
|
OX_MODEL_FIELD(pixels)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(TileSheetV4)
|
OX_MODEL_BEGIN(TileSheetV4)
|
||||||
oxModelField(bpp)
|
OX_MODEL_FIELD(bpp)
|
||||||
oxModelField(idIt)
|
OX_MODEL_FIELD(idIt)
|
||||||
oxModelField(defaultPalette)
|
OX_MODEL_FIELD(defaultPalette)
|
||||||
oxModelField(subsheet)
|
OX_MODEL_FIELD(subsheet)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(CompactTileSheetV1)
|
OX_MODEL_BEGIN(CompactTileSheetV1)
|
||||||
oxModelField(bpp)
|
OX_MODEL_FIELD(bpp)
|
||||||
oxModelField(defaultPalette)
|
OX_MODEL_FIELD(defaultPalette)
|
||||||
oxModelField(pixels)
|
OX_MODEL_FIELD(pixels)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
ox::Vector<uint32_t> resizeTileSheetData(
|
ox::Vector<uint32_t> resizeTileSheetData(
|
||||||
ox::Vector<uint32_t> const&srcPixels,
|
ox::Vector<uint32_t> const&srcPixels,
|
||||||
|
@ -21,7 +21,7 @@ ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
|
|||||||
|
|
||||||
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||||
auto ctx = ox::make_unique<Context>(tctx);
|
auto ctx = ox::make_unique<Context>(tctx);
|
||||||
oxReturnError(initGfx(*ctx, params));
|
OX_RETURN_ERROR(initGfx(*ctx, params));
|
||||||
return ContextUPtr(std::move(ctx));
|
return ContextUPtr(std::move(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ static ox::Error loadTileSheetSet(
|
|||||||
size_t tileWriteIdx = 0;
|
size_t tileWriteIdx = 0;
|
||||||
size_t const bppMod = set.bpp == 4;
|
size_t const bppMod = set.bpp == 4;
|
||||||
for (auto const&entry : set.entries) {
|
for (auto const&entry : set.entries) {
|
||||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), entry.tilesheet));
|
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), entry.tilesheet));
|
||||||
if (set.bpp != ts->bpp && ts->bpp == 8) {
|
if (set.bpp != ts->bpp && ts->bpp == 8) {
|
||||||
return ox::Error(1, "cannot load an 8 BPP tilesheet into a 4 BPP CBB");
|
return ox::Error(1, "cannot load an 8 BPP tilesheet into a 4 BPP CBB");
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ ox::Error loadBgTileSheet(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (paletteBank.has_value() && ts.defaultPalette) {
|
if (paletteBank.has_value() && ts.defaultPalette) {
|
||||||
oxReturnError(loadBgPalette(ctx, *paletteBank, ts.defaultPalette));
|
OX_RETURN_ERROR(loadBgPalette(ctx, *paletteBank, ts.defaultPalette));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ ox::Error loadBgTileSheet(
|
|||||||
unsigned const cbb,
|
unsigned const cbb,
|
||||||
TileSheetSet const&set) noexcept {
|
TileSheetSet const&set) noexcept {
|
||||||
auto const bpp = static_cast<unsigned>(set.bpp);
|
auto const bpp = static_cast<unsigned>(set.bpp);
|
||||||
oxReturnError(loadTileSheetSet(ctx, MEM_BG_TILES[cbb], set));
|
OX_RETURN_ERROR(loadTileSheetSet(ctx, MEM_BG_TILES[cbb], set));
|
||||||
// update bpp of all bgs with the updated cbb
|
// update bpp of all bgs with the updated cbb
|
||||||
ctx.cbbData[cbb].bpp = bpp;
|
ctx.cbbData[cbb].bpp = bpp;
|
||||||
teagba::iterateBgCtl([bpp, cbb](volatile BgCtl &bgCtl) {
|
teagba::iterateBgCtl([bpp, cbb](volatile BgCtl &bgCtl) {
|
||||||
@ -178,7 +178,7 @@ ox::Error loadSpriteTileSheet(
|
|||||||
MEM_SPRITE_TILES[i] = v;
|
MEM_SPRITE_TILES[i] = v;
|
||||||
}
|
}
|
||||||
if (loadDefaultPalette && ts.defaultPalette) {
|
if (loadDefaultPalette && ts.defaultPalette) {
|
||||||
oxReturnError(loadSpritePalette(ctx, ts.defaultPalette));
|
OX_RETURN_ERROR(loadSpritePalette(ctx, ts.defaultPalette));
|
||||||
}
|
}
|
||||||
setSpritesBpp(static_cast<unsigned>(ts.bpp));
|
setSpritesBpp(static_cast<unsigned>(ts.bpp));
|
||||||
return {};
|
return {};
|
||||||
@ -188,7 +188,7 @@ ox::Error loadSpriteTileSheet(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
TileSheetSet const&set) noexcept {
|
TileSheetSet const&set) noexcept {
|
||||||
auto const bpp = static_cast<unsigned>(set.bpp);
|
auto const bpp = static_cast<unsigned>(set.bpp);
|
||||||
oxReturnError(loadTileSheetSet(ctx, {MEM_SPRITE_TILES, 32 * ox::units::KB}, set));
|
OX_RETURN_ERROR(loadTileSheetSet(ctx, {MEM_SPRITE_TILES, 32 * ox::units::KB}, set));
|
||||||
setSpritesBpp(bpp);
|
setSpritesBpp(bpp);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ ox::Error loadBgPalette(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
size_t palBank,
|
size_t palBank,
|
||||||
ox::StringViewCR palettePath) noexcept {
|
ox::StringViewCR palettePath) noexcept {
|
||||||
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
|
OX_REQUIRE(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
|
||||||
return loadBgPalette(ctx, palBank, *pal, 0);
|
return loadBgPalette(ctx, palBank, *pal, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,21 +30,21 @@ ox::Error loadBgPalette(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
size_t palBank,
|
size_t palBank,
|
||||||
ox::FileAddress const&paletteAddr) noexcept {
|
ox::FileAddress const&paletteAddr) noexcept {
|
||||||
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), paletteAddr));
|
OX_REQUIRE(pal, keel::readObj<CompactPalette>(keelCtx(ctx), paletteAddr));
|
||||||
return loadBgPalette(ctx, palBank, *pal, 0);
|
return loadBgPalette(ctx, palBank, *pal, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error loadSpritePalette(
|
ox::Error loadSpritePalette(
|
||||||
Context &ctx,
|
Context &ctx,
|
||||||
ox::StringViewCR palettePath) noexcept {
|
ox::StringViewCR palettePath) noexcept {
|
||||||
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
|
OX_REQUIRE(pal, keel::readObj<CompactPalette>(keelCtx(ctx), palettePath));
|
||||||
return loadSpritePalette(ctx, *pal, 0);
|
return loadSpritePalette(ctx, *pal, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error loadSpritePalette(
|
ox::Error loadSpritePalette(
|
||||||
Context &ctx,
|
Context &ctx,
|
||||||
ox::FileAddress const&paletteAddr) noexcept {
|
ox::FileAddress const&paletteAddr) noexcept {
|
||||||
oxRequire(pal, keel::readObj<CompactPalette>(keelCtx(ctx), paletteAddr));
|
OX_REQUIRE(pal, keel::readObj<CompactPalette>(keelCtx(ctx), paletteAddr));
|
||||||
return loadSpritePalette(ctx, *pal, 0);
|
return loadSpritePalette(ctx, *pal, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ ox::Error loadBgTileSheet(
|
|||||||
size_t dstTileIdx,
|
size_t dstTileIdx,
|
||||||
size_t srcTileIdx,
|
size_t srcTileIdx,
|
||||||
size_t tileCnt) noexcept {
|
size_t tileCnt) noexcept {
|
||||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsAddr));
|
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsAddr));
|
||||||
return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt);
|
return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ ox::Error loadBgTileSheet(
|
|||||||
size_t dstTileIdx,
|
size_t dstTileIdx,
|
||||||
size_t srcTileIdx,
|
size_t srcTileIdx,
|
||||||
size_t tileCnt) noexcept {
|
size_t tileCnt) noexcept {
|
||||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsPath));
|
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tsPath));
|
||||||
return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt);
|
return loadBgTileSheet(ctx, cbb, *ts, dstTileIdx, srcTileIdx, tileCnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ ox::Error loadBgTileSheet(
|
|||||||
unsigned cbb,
|
unsigned cbb,
|
||||||
ox::StringViewCR tilesheetPath,
|
ox::StringViewCR tilesheetPath,
|
||||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
||||||
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
|
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ ox::Error loadBgTileSheet(
|
|||||||
unsigned cbb,
|
unsigned cbb,
|
||||||
ox::FileAddress const&tilesheetAddr,
|
ox::FileAddress const&tilesheetAddr,
|
||||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||||
oxRequire(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
OX_REQUIRE(ts, keel::readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
||||||
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
|
return loadBgTileSheet(ctx, cbb, *ts, paletteBank);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ ox::Error loadSpriteTileSheet(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
ox::StringViewCR tilesheetPath,
|
ox::StringViewCR tilesheetPath,
|
||||||
bool loadDefaultPalette) noexcept {
|
bool loadDefaultPalette) noexcept {
|
||||||
oxRequire(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
OX_REQUIRE(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetPath));
|
||||||
return loadSpriteTileSheet(ctx, *ts, loadDefaultPalette);
|
return loadSpriteTileSheet(ctx, *ts, loadDefaultPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ ox::Error loadSpriteTileSheet(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
ox::FileAddress const&tilesheetAddr,
|
ox::FileAddress const&tilesheetAddr,
|
||||||
bool loadDefaultPalette) noexcept {
|
bool loadDefaultPalette) noexcept {
|
||||||
oxRequire(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
OX_REQUIRE(ts, readObj<CompactTileSheet>(keelCtx(ctx), tilesheetAddr));
|
||||||
return loadSpriteTileSheet(ctx, *ts, loadDefaultPalette);
|
return loadSpriteTileSheet(ctx, *ts, loadDefaultPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ ox::Error initConsole(Context &ctx) noexcept {
|
|||||||
constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Charset.npal");
|
constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Charset.npal");
|
||||||
setBgStatus(ctx, 0b0001);
|
setBgStatus(ctx, 0b0001);
|
||||||
setBgCbb(ctx, 0, 0);
|
setBgCbb(ctx, 0, 0);
|
||||||
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr));
|
OX_RETURN_ERROR(loadBgTileSheet(ctx, 0, TilesheetAddr));
|
||||||
return loadBgPalette(ctx, 0, PaletteAddr);
|
return loadBgPalette(ctx, 0, PaletteAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ static class: public keel::Module {
|
|||||||
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>(
|
OX_RETURN_ERROR(keel::convertBuffToBuff<CompactTileSheet>(
|
||||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ static class: public keel::Module {
|
|||||||
typeId == ox::ModelTypeId_v<PaletteV2> ||
|
typeId == ox::ModelTypeId_v<PaletteV2> ||
|
||||||
typeId == ox::ModelTypeId_v<PaletteV3> ||
|
typeId == ox::ModelTypeId_v<PaletteV3> ||
|
||||||
typeId == ox::ModelTypeId_v<PaletteV4>) {
|
typeId == ox::ModelTypeId_v<PaletteV4>) {
|
||||||
oxReturnError(keel::convertBuffToBuff<CompactPalette>(
|
OX_RETURN_ERROR(keel::convertBuffToBuff<CompactPalette>(
|
||||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ Context::~Context() noexcept {
|
|||||||
|
|
||||||
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||||
auto ctx = ox::make_unique<Context>(tctx, params);
|
auto ctx = ox::make_unique<Context>(tctx, params);
|
||||||
oxReturnError(initGfx(*ctx, params));
|
OX_RETURN_ERROR(initGfx(*ctx, params));
|
||||||
return ContextUPtr(ctx.release());
|
return ContextUPtr(ctx.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,8 +464,8 @@ ox::Error initGfx(
|
|||||||
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
|
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, gl::GlslVersion);
|
||||||
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
|
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, gl::GlslVersion);
|
||||||
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
|
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, gl::GlslVersion);
|
||||||
oxReturnError(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(ctx.bgShader));
|
OX_RETURN_ERROR(glutils::buildShaderProgram(bgVshad, bgFshad).moveTo(ctx.bgShader));
|
||||||
oxReturnError(
|
OX_RETURN_ERROR(
|
||||||
glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(ctx.spriteShader));
|
glutils::buildShaderProgram(spriteVshad, spriteFshad).moveTo(ctx.spriteShader));
|
||||||
for (auto &cbb : ctx.cbbs) {
|
for (auto &cbb : ctx.cbbs) {
|
||||||
initBackgroundBufferset(ctx.bgShader, cbb);
|
initBackgroundBufferset(ctx.bgShader, cbb);
|
||||||
@ -538,8 +538,8 @@ static ox::Result<TileSheetData> buildSetTsd(
|
|||||||
TileSheetData setTsd;
|
TileSheetData setTsd;
|
||||||
setTsd.width = TileWidth;
|
setTsd.width = TileWidth;
|
||||||
for (auto const&entry : set.entries) {
|
for (auto const&entry : set.entries) {
|
||||||
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, entry.tilesheet));
|
OX_REQUIRE(tilesheet, readObj<CompactTileSheet>(kctx, entry.tilesheet));
|
||||||
oxRequire(tsd, normalizeTileSheet(*tilesheet));
|
OX_REQUIRE(tsd, normalizeTileSheet(*tilesheet));
|
||||||
for (auto const&s : entry.sections) {
|
for (auto const&s : entry.sections) {
|
||||||
auto const size = s.tiles * PixelsPerTile;
|
auto const size = s.tiles * PixelsPerTile;
|
||||||
for (auto i = 0; i < size; ++i) {
|
for (auto i = 0; i < size; ++i) {
|
||||||
@ -604,9 +604,9 @@ ox::Error loadBgTileSheet(
|
|||||||
ox::Optional<unsigned> const&paletteBank) noexcept {
|
ox::Optional<unsigned> const&paletteBank) noexcept {
|
||||||
auto const bytesPerTile = static_cast<uint64_t>(PixelsPerTile / (1 + (ts.bpp == 4)));
|
auto const bytesPerTile = static_cast<uint64_t>(PixelsPerTile / (1 + (ts.bpp == 4)));
|
||||||
auto const tiles = ts.pixels.size() / bytesPerTile;
|
auto const tiles = ts.pixels.size() / bytesPerTile;
|
||||||
oxReturnError(loadBgTileSheet(ctx, cbb, ts, 0, 0, tiles));
|
OX_RETURN_ERROR(loadBgTileSheet(ctx, cbb, ts, 0, 0, tiles));
|
||||||
if (paletteBank.has_value() && ts.defaultPalette) {
|
if (paletteBank.has_value() && ts.defaultPalette) {
|
||||||
oxReturnError(loadBgPalette(ctx, *paletteBank, ts.defaultPalette));
|
OX_RETURN_ERROR(loadBgPalette(ctx, *paletteBank, ts.defaultPalette));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -615,7 +615,7 @@ ox::Error loadBgTileSheet(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
unsigned cbb,
|
unsigned cbb,
|
||||||
TileSheetSet const&set) noexcept {
|
TileSheetSet const&set) noexcept {
|
||||||
oxRequire(setTsd, buildSetTsd(ctx, set));
|
OX_REQUIRE(setTsd, buildSetTsd(ctx, set));
|
||||||
ctx.cbbs[cbb].tex = renderer::createTexture(setTsd.width, setTsd.height, setTsd.pixels.data());
|
ctx.cbbs[cbb].tex = renderer::createTexture(setTsd.width, setTsd.height, setTsd.pixels.data());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -624,11 +624,11 @@ ox::Error loadSpriteTileSheet(
|
|||||||
Context &ctx,
|
Context &ctx,
|
||||||
CompactTileSheet const&ts,
|
CompactTileSheet const&ts,
|
||||||
bool loadDefaultPalette) noexcept {
|
bool loadDefaultPalette) noexcept {
|
||||||
oxRequire(tsd, normalizeTileSheet(ts));
|
OX_REQUIRE(tsd, normalizeTileSheet(ts));
|
||||||
oxTracef("nostalgia.core.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", tsd.width, tsd.height);
|
oxTracef("nostalgia.core.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", tsd.width, tsd.height);
|
||||||
ctx.spriteBlocks.tex = renderer::createTexture(tsd.width, tsd.height, tsd.pixels.data());
|
ctx.spriteBlocks.tex = renderer::createTexture(tsd.width, tsd.height, tsd.pixels.data());
|
||||||
if (loadDefaultPalette) {
|
if (loadDefaultPalette) {
|
||||||
oxReturnError(loadSpritePalette(ctx, ts.defaultPalette));
|
OX_RETURN_ERROR(loadSpritePalette(ctx, ts.defaultPalette));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -636,7 +636,7 @@ ox::Error loadSpriteTileSheet(
|
|||||||
ox::Error loadSpriteTileSheet(
|
ox::Error loadSpriteTileSheet(
|
||||||
Context &ctx,
|
Context &ctx,
|
||||||
TileSheetSet const&set) noexcept {
|
TileSheetSet const&set) noexcept {
|
||||||
oxRequire(setTsd, buildSetTsd(ctx, set));
|
OX_REQUIRE(setTsd, buildSetTsd(ctx, set));
|
||||||
ctx.spriteBlocks.tex = renderer::createTexture(setTsd.width, setTsd.height, setTsd.pixels.data());
|
ctx.spriteBlocks.tex = renderer::createTexture(setTsd.width, setTsd.height, setTsd.pixels.data());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ ox::Error AddColorCommand::redo() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error AddColorCommand::undo() noexcept {
|
ox::Error AddColorCommand::undo() noexcept {
|
||||||
oxReturnError(m_pal.colorNames.erase(m_idx));
|
OX_RETURN_ERROR(m_pal.colorNames.erase(m_idx));
|
||||||
for (auto &page : m_pal.pages) {
|
for (auto &page : m_pal.pages) {
|
||||||
oxReturnError(page.colors.erase(m_idx));
|
OX_RETURN_ERROR(page.colors.erase(m_idx));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ int RemoveColorCommand::commandId() const noexcept {
|
|||||||
|
|
||||||
ox::Error RemoveColorCommand::redo() noexcept {
|
ox::Error RemoveColorCommand::redo() noexcept {
|
||||||
m_colorInfo = std::move(m_pal.colorNames[m_idx]);
|
m_colorInfo = std::move(m_pal.colorNames[m_idx]);
|
||||||
oxReturnError(m_pal.colorNames.erase(m_idx));
|
OX_RETURN_ERROR(m_pal.colorNames.erase(m_idx));
|
||||||
for (auto &page : m_pal.pages) {
|
for (auto &page : m_pal.pages) {
|
||||||
oxReturnError(page.colors.erase(m_idx));
|
OX_RETURN_ERROR(page.colors.erase(m_idx));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ ox::Error AddSubSheetCommand::undo() noexcept {
|
|||||||
--m_img.idIt;
|
--m_img.idIt;
|
||||||
} else {
|
} else {
|
||||||
for (auto idx = m_addedSheets.rbegin(); idx != m_addedSheets.rend(); ++idx) {
|
for (auto idx = m_addedSheets.rbegin(); idx != m_addedSheets.rend(); ++idx) {
|
||||||
oxReturnError(rmSubSheet(m_img, *idx));
|
OX_RETURN_ERROR(rmSubSheet(m_img, *idx));
|
||||||
--m_img.idIt;
|
--m_img.idIt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,14 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
oxModelFwdDecl(class TileSheetClipboard);
|
OX_MODEL_FWD_DECL(class TileSheetClipboard);
|
||||||
|
|
||||||
class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
|
class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
|
||||||
public:
|
public:
|
||||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard";
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard";
|
||||||
static constexpr auto TypeVersion = 1;
|
static constexpr auto TypeVersion = 1;
|
||||||
|
|
||||||
oxModelFriend(TileSheetClipboard);
|
OX_MODEL_FRIEND(TileSheetClipboard);
|
||||||
|
|
||||||
struct Pixel {
|
struct Pixel {
|
||||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard.Pixel";
|
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard.Pixel";
|
||||||
@ -36,14 +36,14 @@ class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
|
|||||||
ox::Vector<Pixel> const&pixels() const noexcept;
|
ox::Vector<Pixel> const&pixels() const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(TileSheetClipboard::Pixel)
|
OX_MODEL_BEGIN(TileSheetClipboard::Pixel)
|
||||||
oxModelField(colorIdx)
|
OX_MODEL_FIELD(colorIdx)
|
||||||
oxModelField(pt)
|
OX_MODEL_FIELD(pt)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
oxModelBegin(TileSheetClipboard)
|
OX_MODEL_BEGIN(TileSheetClipboard)
|
||||||
oxModelFieldRename(m_pixels, pixels)
|
OX_MODEL_FIELD_RENAME(m_pixels, pixels)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
class CutPasteCommand: public TileSheetCommand {
|
class CutPasteCommand: public TileSheetCommand {
|
||||||
private:
|
private:
|
||||||
|
@ -16,7 +16,7 @@ core::RmSubSheetCommand::RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetId
|
|||||||
ox::Error RmSubSheetCommand::redo() noexcept {
|
ox::Error RmSubSheetCommand::redo() noexcept {
|
||||||
auto &parent = getSubSheet(m_img, m_parentIdx);
|
auto &parent = getSubSheet(m_img, m_parentIdx);
|
||||||
m_sheet = std::move(parent.subsheets[*m_idx.back().value]);
|
m_sheet = std::move(parent.subsheets[*m_idx.back().value]);
|
||||||
oxReturnError(parent.subsheets.erase(*m_idx.back().value).error);
|
OX_RETURN_ERROR(parent.subsheets.erase(*m_idx.back().value).error);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ struct TileSheetEditorConfig {
|
|||||||
TileSheet::SubSheetIdx activeSubsheet{};
|
TileSheet::SubSheetIdx activeSubsheet{};
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(TileSheetEditorConfig)
|
OX_MODEL_BEGIN(TileSheetEditorConfig)
|
||||||
oxModelFieldRename(activeSubsheet, active_subsheet)
|
OX_MODEL_FIELD_RENAME(activeSubsheet, active_subsheet)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
static ox::Vector<uint32_t> normalizePixelSizes(
|
static ox::Vector<uint32_t> normalizePixelSizes(
|
||||||
ox::Vector<uint8_t> const&inPixels,
|
ox::Vector<uint8_t> const&inPixels,
|
||||||
@ -346,7 +346,7 @@ void TileSheetEditorImGui::showSubsheetEditor() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexcept {
|
ox::Error TileSheetEditorImGui::exportSubhseetToPng(int const scale) const noexcept {
|
||||||
oxRequire(path, studio::saveFile({{"PNG", "png"}}));
|
OX_REQUIRE(path, studio::saveFile({{"PNG", "png"}}));
|
||||||
// subsheet to png
|
// subsheet to png
|
||||||
auto const&img = m_model.img();
|
auto const&img = m_model.img();
|
||||||
auto const&s = m_model.activeSubSheet();
|
auto const&s = m_model.activeSubSheet();
|
||||||
|
@ -132,7 +132,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error TileSheetEditorModel::setPalette(ox::StringView path) noexcept {
|
ox::Error TileSheetEditorModel::setPalette(ox::StringView path) noexcept {
|
||||||
oxRequire(uuid, keelCtx(m_tctx).pathToUuid.at(path));
|
OX_REQUIRE(uuid, keelCtx(m_tctx).pathToUuid.at(path));
|
||||||
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString()));
|
pushCommand(ox::make<PaletteChangeCommand>(activeSubSheetIdx(), m_img, uuid->toString()));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(studio::UndoCommand const*cmd)
|
|||||||
m_updated = true;
|
m_updated = true;
|
||||||
const auto cmdId = cmd->commandId();
|
const auto cmdId = cmd->commandId();
|
||||||
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
|
if (static_cast<CommandId>(cmdId) == CommandId::PaletteChange) {
|
||||||
oxReturnError(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal));
|
OX_RETURN_ERROR(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal));
|
||||||
m_palettePage = ox::min<size_t>(m_pal->pages.size(), 0);
|
m_palettePage = ox::min<size_t>(m_pal->pages.size(), 0);
|
||||||
paletteChanged.emit();
|
paletteChanged.emit();
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@ TileSheetEditorView::TileSheetEditorView(studio::StudioContext &sctx, ox::String
|
|||||||
m_pixelsDrawer(m_model) {
|
m_pixelsDrawer(m_model) {
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
// build shaders
|
// build shaders
|
||||||
oxThrowError(m_pixelsDrawer.buildShader());
|
OX_THROW_ERROR(m_pixelsDrawer.buildShader());
|
||||||
oxThrowError(m_pixelGridDrawer.buildShader());
|
OX_THROW_ERROR(m_pixelGridDrawer.buildShader());
|
||||||
m_model.activeSubsheetChanged.connect(this, &TileSheetEditorView::setActiveSubsheet);
|
m_model.activeSubsheetChanged.connect(this, &TileSheetEditorView::setActiveSubsheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ unsigned pixelCnt(TileSheet::SubSheet const&ss, int8_t pBpp) noexcept {
|
|||||||
|
|
||||||
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, int8_t pBpp, ox::Size const&sz) noexcept {
|
ox::Error resizeSubsheet(TileSheet::SubSheet &ss, int8_t pBpp, ox::Size const&sz) noexcept {
|
||||||
ox::Vector<uint8_t> out;
|
ox::Vector<uint8_t> out;
|
||||||
oxReturnError(setPixelCount(out, pBpp, static_cast<size_t>(sz.width * sz.height) * PixelsPerTile));
|
OX_RETURN_ERROR(setPixelCount(out, pBpp, static_cast<size_t>(sz.width * sz.height) * PixelsPerTile));
|
||||||
auto const w = ox::min<int32_t>(ss.columns, sz.width) * TileWidth;
|
auto const w = ox::min<int32_t>(ss.columns, sz.width) * TileWidth;
|
||||||
auto const h = ox::min<int32_t>(ss.rows, sz.height) * TileHeight;
|
auto const h = ox::min<int32_t>(ss.rows, sz.height) * TileHeight;
|
||||||
for (auto x = 0; x < w; ++x) {
|
for (auto x = 0; x < w; ++x) {
|
||||||
|
@ -16,8 +16,8 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
"readWriteTileSheet",
|
"readWriteTileSheet",
|
||||||
[]() -> ox::Error {
|
[]() -> ox::Error {
|
||||||
core::TileSheet in;
|
core::TileSheet in;
|
||||||
oxRequire(buff, ox::writeMC(in));
|
OX_REQUIRE(buff, ox::writeMC(in));
|
||||||
oxRequire(out, ox::readMC<core::TileSheet>(buff));
|
OX_REQUIRE(out, ox::readMC<core::TileSheet>(buff));
|
||||||
oxAssert(in.subsheet.name == out.subsheet.name, "subsheet.name serialization broken");
|
oxAssert(in.subsheet.name == out.subsheet.name, "subsheet.name serialization broken");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -57,12 +57,12 @@ struct TileDoc {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(TileDoc)
|
OX_MODEL_BEGIN(TileDoc)
|
||||||
oxModelFieldRename(subsheetId, subsheet_id)
|
OX_MODEL_FIELD_RENAME(subsheetId, subsheet_id)
|
||||||
oxModelFieldRename(subsheetPath, subsheet_path)
|
OX_MODEL_FIELD_RENAME(subsheetPath, subsheet_path)
|
||||||
oxModelField(type)
|
OX_MODEL_FIELD(type)
|
||||||
oxModelFieldRename(layerAttachments, layer_attachments)
|
OX_MODEL_FIELD_RENAME(layerAttachments, layer_attachments)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
struct SceneDoc {
|
struct SceneDoc {
|
||||||
|
|
||||||
@ -95,11 +95,11 @@ struct SceneDoc {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(SceneDoc)
|
OX_MODEL_BEGIN(SceneDoc)
|
||||||
oxModelField(tilesheet)
|
OX_MODEL_FIELD(tilesheet)
|
||||||
oxModelField(palettes)
|
OX_MODEL_FIELD(palettes)
|
||||||
oxModelField(tiles)
|
OX_MODEL_FIELD(tiles)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
|
|
||||||
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
|
||||||
@ -215,14 +215,14 @@ struct SceneStatic {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(SceneStatic)
|
OX_MODEL_BEGIN(SceneStatic)
|
||||||
oxModelField(tilesheet)
|
OX_MODEL_FIELD(tilesheet)
|
||||||
oxModelField(palettes)
|
OX_MODEL_FIELD(palettes)
|
||||||
oxModelField(columns)
|
OX_MODEL_FIELD(columns)
|
||||||
oxModelField(rows)
|
OX_MODEL_FIELD(rows)
|
||||||
oxModelField(tileMapIdx)
|
OX_MODEL_FIELD(tileMapIdx)
|
||||||
oxModelField(tileType)
|
OX_MODEL_FIELD(tileType)
|
||||||
oxModelField(layerAttachments)
|
OX_MODEL_FIELD(layerAttachments)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ ox::Error SceneDocToSceneStaticConverter::convert(
|
|||||||
keel::Context &ctx,
|
keel::Context &ctx,
|
||||||
SceneDoc &src,
|
SceneDoc &src,
|
||||||
SceneStatic &dst) const noexcept {
|
SceneStatic &dst) const noexcept {
|
||||||
oxRequire(ts, keel::readObj<core::TileSheet>(ctx, src.tilesheet));
|
OX_REQUIRE(ts, keel::readObj<core::TileSheet>(ctx, src.tilesheet));
|
||||||
const auto layerCnt = src.tiles.size();
|
const auto layerCnt = src.tiles.size();
|
||||||
dst.setLayerCnt(layerCnt);
|
dst.setLayerCnt(layerCnt);
|
||||||
dst.tilesheet = ox::FileAddress(src.tilesheet);
|
dst.tilesheet = ox::FileAddress(src.tilesheet);
|
||||||
@ -53,8 +53,8 @@ ox::Error SceneDocToSceneStaticConverter::convert(
|
|||||||
for (const auto &srcTile : row) {
|
for (const auto &srcTile : row) {
|
||||||
auto dstTile = dstLayer.tile(tileIdx);
|
auto dstTile = dstLayer.tile(tileIdx);
|
||||||
dstTile.tileType = srcTile.type;
|
dstTile.tileType = srcTile.type;
|
||||||
oxRequire(path, srcTile.getSubsheetPath(*ts));
|
OX_REQUIRE(path, srcTile.getSubsheetPath(*ts));
|
||||||
oxRequire(mapIdx, getTileOffset(*ts, path));
|
OX_REQUIRE(mapIdx, getTileOffset(*ts, path));
|
||||||
dstTile.tileMapIdx = static_cast<uint16_t>(mapIdx);
|
dstTile.tileMapIdx = static_cast<uint16_t>(mapIdx);
|
||||||
setLayerAttachments(layerIdx, srcTile, dstTile);
|
setLayerAttachments(layerIdx, srcTile, dstTile);
|
||||||
++tileIdx;
|
++tileIdx;
|
||||||
|
@ -17,8 +17,8 @@ ox::Error Scene::setupDisplay(core::Context &ctx) const noexcept {
|
|||||||
return ox::Error(1, "Scene has no palettes");
|
return ox::Error(1, "Scene has no palettes");
|
||||||
}
|
}
|
||||||
auto const&palette = m_sceneStatic.palettes[0];
|
auto const&palette = m_sceneStatic.palettes[0];
|
||||||
oxReturnError(core::loadBgTileSheet(ctx, 0, m_sceneStatic.tilesheet));
|
OX_RETURN_ERROR(core::loadBgTileSheet(ctx, 0, m_sceneStatic.tilesheet));
|
||||||
oxReturnError(core::loadBgPalette(ctx, 0, palette));
|
OX_RETURN_ERROR(core::loadBgPalette(ctx, 0, palette));
|
||||||
// disable all backgrounds
|
// disable all backgrounds
|
||||||
core::setBgStatus(ctx, 0);
|
core::setBgStatus(ctx, 0);
|
||||||
for (auto layerNo = 0u; auto const&layer : m_sceneStatic.tileMapIdx) {
|
for (auto layerNo = 0u; auto const&layer : m_sceneStatic.tileMapIdx) {
|
||||||
|
@ -48,7 +48,7 @@ void SceneEditorImGui::onActivated() noexcept {
|
|||||||
|
|
||||||
ox::Error SceneEditorImGui::saveItem() noexcept {
|
ox::Error SceneEditorImGui::saveItem() noexcept {
|
||||||
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
const auto sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||||
oxReturnError(sctx->project->writeObj(itemPath(), m_editor.scene()));
|
OX_RETURN_ERROR(sctx->project->writeObj(itemPath(), m_editor.scene()));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ constexpr auto K1HdrSz = 40;
|
|||||||
ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept;
|
ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) 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;"));
|
OX_RETURN_ERROR(write(writer, "K1;"));
|
||||||
oxReturnError(uuid.toString(writer));
|
OX_RETURN_ERROR(uuid.toString(writer));
|
||||||
return writer.put(';');
|
return writer.put(';');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,8 +29,8 @@ ox::Result<T> readAsset(ox::BufferView buff) noexcept {
|
|||||||
offset = K1HdrSz; // the size of K1 headers
|
offset = K1HdrSz; // the size of K1 headers
|
||||||
}
|
}
|
||||||
auto out = ox::readClaw<T>(buff + offset);
|
auto out = ox::readClaw<T>(buff + offset);
|
||||||
oxReturnError(out);
|
OX_RETURN_ERROR(out);
|
||||||
oxReturnError(ensureValid(out.value));
|
OX_RETURN_ERROR(ensureValid(out.value));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ class AssetManager {
|
|||||||
AssetTypeManager(Loader loader) noexcept: m_loader(loader) {}
|
AssetTypeManager(Loader loader) noexcept: m_loader(loader) {}
|
||||||
|
|
||||||
ox::Result<AssetRef<T>> getAsset(ox::StringView const assetId) const noexcept {
|
ox::Result<AssetRef<T>> getAsset(ox::StringView const assetId) const noexcept {
|
||||||
oxRequire(out, m_cache.at(assetId));
|
OX_REQUIRE(out, m_cache.at(assetId));
|
||||||
if (!out || !*out) {
|
if (!out || !*out) {
|
||||||
return ox::Error(1, "asset is null");
|
return ox::Error(1, "asset is null");
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ class AssetManager {
|
|||||||
|
|
||||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
|
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
|
||||||
auto &p = m_cache[assetId];
|
auto &p = m_cache[assetId];
|
||||||
oxRequireM(obj, m_loader(assetId));
|
OX_REQUIRE_M(obj, m_loader(assetId));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
||||||
} else {
|
} else {
|
||||||
@ -226,7 +226,7 @@ class AssetManager {
|
|||||||
|
|
||||||
ox::Error reloadAsset(ox::StringView const assetId) noexcept {
|
ox::Error reloadAsset(ox::StringView const assetId) noexcept {
|
||||||
auto &p = m_cache[assetId];
|
auto &p = m_cache[assetId];
|
||||||
oxRequireM(obj, m_loader(assetId));
|
OX_REQUIRE_M(obj, m_loader(assetId));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
||||||
} else {
|
} else {
|
||||||
@ -274,7 +274,7 @@ class AssetManager {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<AssetRef<T>> getAsset(ox::StringView assetId) noexcept {
|
ox::Result<AssetRef<T>> getAsset(ox::StringView assetId) noexcept {
|
||||||
oxRequire(m, getTypeManager<T>());
|
OX_REQUIRE(m, getTypeManager<T>());
|
||||||
return m->getAsset(assetId);
|
return m->getAsset(assetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,8 +285,8 @@ class AssetManager {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView assetId) noexcept {
|
ox::Result<AssetRef<T>> loadAsset(ox::StringView assetId) noexcept {
|
||||||
oxRequire(m, getTypeManager<T>());
|
OX_REQUIRE(m, getTypeManager<T>());
|
||||||
oxRequire(out, m->loadAsset(assetId));
|
OX_REQUIRE(out, m->loadAsset(assetId));
|
||||||
m_fileUpdated[assetId].connect(m, &AssetTypeManager<T>::reloadAsset);
|
m_fileUpdated[assetId].connect(m, &AssetTypeManager<T>::reloadAsset);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,9 @@ struct PreloadPtr {
|
|||||||
uint64_t preloadAddr = 0;
|
uint64_t preloadAddr = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(PreloadPtr)
|
OX_MODEL_BEGIN(PreloadPtr)
|
||||||
oxModelField(preloadAddr)
|
OX_MODEL_FIELD(preloadAddr)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&addr) noexcept;
|
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&addr) noexcept;
|
||||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR path) noexcept;
|
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR path) noexcept;
|
||||||
@ -63,14 +63,14 @@ namespace detail {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr auto makeLoader(Context &ctx) {
|
constexpr auto makeLoader(Context &ctx) {
|
||||||
return [&ctx](ox::StringView assetId) -> ox::Result<T> {
|
return [&ctx](ox::StringView assetId) -> ox::Result<T> {
|
||||||
oxRequire(p, ctx.uuidToPath.at(assetId));
|
OX_REQUIRE(p, ctx.uuidToPath.at(assetId));
|
||||||
oxRequire(buff, ctx.rom->read(*p));
|
OX_REQUIRE(buff, ctx.rom->read(*p));
|
||||||
auto [obj, err] = readAsset<T>(buff);
|
auto [obj, err] = readAsset<T>(buff);
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {
|
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
oxReturnError(convert<T>(ctx, buff, &obj));
|
OX_RETURN_ERROR(convert<T>(ctx, buff, &obj));
|
||||||
}
|
}
|
||||||
return std::move(obj);
|
return std::move(obj);
|
||||||
};
|
};
|
||||||
@ -97,7 +97,7 @@ ox::Result<keel::AssetRef<T>> readObjFile(
|
|||||||
auto [cached, err] = ctx.assetManager.getAsset<T>(assetId);
|
auto [cached, err] = ctx.assetManager.getAsset<T>(assetId);
|
||||||
if (err) {
|
if (err) {
|
||||||
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
|
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
|
||||||
oxReturnError(ctx.assetManager.loadAsset<T>(assetId).moveTo(cached));
|
OX_RETURN_ERROR(ctx.assetManager.loadAsset<T>(assetId).moveTo(cached));
|
||||||
}
|
}
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ ox::Result<keel::AssetRef<T>> readObjNoCache(
|
|||||||
keel::Context &ctx,
|
keel::Context &ctx,
|
||||||
ox::StringViewCR assetId) noexcept {
|
ox::StringViewCR assetId) noexcept {
|
||||||
if constexpr(ox::preloadable<T>::value) {
|
if constexpr(ox::preloadable<T>::value) {
|
||||||
oxRequire(addr, getPreloadAddr(ctx, assetId));
|
OX_REQUIRE(addr, getPreloadAddr(ctx, assetId));
|
||||||
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
||||||
} else {
|
} else {
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
@ -139,11 +139,11 @@ ox::Result<keel::AssetRef<T>> readObj(
|
|||||||
ox::FileAddress const&file,
|
ox::FileAddress const&file,
|
||||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
oxRequire(assetId, file.getPath());
|
OX_REQUIRE(assetId, file.getPath());
|
||||||
return readObj<T>(ctx, ox::StringView(assetId), forceLoad);
|
return readObj<T>(ctx, ox::StringView(assetId), forceLoad);
|
||||||
#else
|
#else
|
||||||
if constexpr(ox::preloadable<T>::value) {
|
if constexpr(ox::preloadable<T>::value) {
|
||||||
oxRequire(addr, getPreloadAddr(ctx, file));
|
OX_REQUIRE(addr, getPreloadAddr(ctx, file));
|
||||||
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
||||||
} else {
|
} else {
|
||||||
return ox::Error(1);
|
return ox::Error(1);
|
||||||
@ -157,7 +157,7 @@ ox::Error writeObj(
|
|||||||
ox::FileAddress const&file,
|
ox::FileAddress const&file,
|
||||||
T const&obj,
|
T const&obj,
|
||||||
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept {
|
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept {
|
||||||
oxRequire(objBuff, ox::writeClaw(obj, fmt));
|
OX_REQUIRE(objBuff, ox::writeClaw(obj, fmt));
|
||||||
return ctx.rom->write(file, objBuff.data(), objBuff.size());
|
return ctx.rom->write(file, objBuff.data(), objBuff.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@ struct ManifestEntry {
|
|||||||
ox::String type;
|
ox::String type;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(ManifestEntry)
|
OX_MODEL_BEGIN(ManifestEntry)
|
||||||
oxModelField(inode)
|
OX_MODEL_FIELD(inode)
|
||||||
oxModelField(preloaded)
|
OX_MODEL_FIELD(preloaded)
|
||||||
oxModelField(type)
|
OX_MODEL_FIELD(type)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
struct Manifest {
|
struct Manifest {
|
||||||
static constexpr auto TypeName = "net.drinkingtea.keel.Manifest";
|
static constexpr auto TypeName = "net.drinkingtea.keel.Manifest";
|
||||||
@ -32,9 +32,9 @@ struct Manifest {
|
|||||||
ox::HashMap<ox::String, ManifestEntry> files;
|
ox::HashMap<ox::String, ManifestEntry> files;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(Manifest)
|
OX_MODEL_BEGIN(Manifest)
|
||||||
oxModelField(files)
|
OX_MODEL_FIELD(files)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
|
|
||||||
class Context;
|
class Context;
|
||||||
@ -113,24 +113,24 @@ ox::Error preloadObj(
|
|||||||
ox::Preloader<PlatSpec> &pl,
|
ox::Preloader<PlatSpec> &pl,
|
||||||
ox::StringView const path) noexcept {
|
ox::StringView const path) noexcept {
|
||||||
// load file
|
// load file
|
||||||
oxRequireM(buff, romFs.read(path));
|
OX_REQUIRE_M(buff, romFs.read(path));
|
||||||
oxRequireM(obj, keel::readAsset(ts, buff));
|
OX_REQUIRE_M(obj, keel::readAsset(ts, buff));
|
||||||
if (obj.type()->preloadable) {
|
if (obj.type()->preloadable) {
|
||||||
// preload
|
// preload
|
||||||
auto const size = ox::sizeOf<GbaPlatSpec>(&obj);
|
auto const size = ox::sizeOf<GbaPlatSpec>(&obj);
|
||||||
auto const alignment = ox::alignOf<GbaPlatSpec>(obj);
|
auto const alignment = ox::alignOf<GbaPlatSpec>(obj);
|
||||||
oxRequire(a, pl.startAlloc(size, alignment));
|
OX_REQUIRE(a, pl.startAlloc(size, alignment));
|
||||||
auto const err = ox::preload<GbaPlatSpec, ox::ModelObject>(&pl, &obj);
|
auto const err = ox::preload<GbaPlatSpec, ox::ModelObject>(&pl, &obj);
|
||||||
oxReturnError(pl.endAlloc());
|
OX_RETURN_ERROR(pl.endAlloc());
|
||||||
oxReturnError(err);
|
OX_RETURN_ERROR(err);
|
||||||
keel::PreloadPtr const p{.preloadAddr = a};
|
keel::PreloadPtr const p{.preloadAddr = a};
|
||||||
oxReturnError(ox::writeMC(p).moveTo(buff));
|
OX_RETURN_ERROR(ox::writeMC(p).moveTo(buff));
|
||||||
oxOutf("preloaded {} as a {} @ {} to {}\n", path, obj.type()->typeName, a, a + size);
|
oxOutf("preloaded {} as a {} @ {} to {}\n", path, obj.type()->typeName, a, a + size);
|
||||||
} else {
|
} else {
|
||||||
// strip the Claw header (it is not needed after preloading) and write back out to dest fs
|
// strip the Claw header (it is not needed after preloading) and write back out to dest fs
|
||||||
oxReturnError(ox::writeMC(obj).moveTo(buff));
|
OX_RETURN_ERROR(ox::writeMC(obj).moveTo(buff));
|
||||||
}
|
}
|
||||||
oxReturnError(romFs.write(path, buff.data(), buff.size()));
|
OX_RETURN_ERROR(romFs.write(path, buff.data(), buff.size()));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,13 +145,13 @@ ox::Error preloadDir(
|
|||||||
ox::StringViewCR path) noexcept {
|
ox::StringViewCR path) noexcept {
|
||||||
// copy
|
// copy
|
||||||
oxTracef("pack.preload", "path: {}", path);
|
oxTracef("pack.preload", "path: {}", path);
|
||||||
oxRequire(fileList, romFs.ls(path));
|
OX_REQUIRE(fileList, romFs.ls(path));
|
||||||
for (auto const&name : fileList) {
|
for (auto const&name : fileList) {
|
||||||
auto const filePath = ox::sfmt("{}{}", path, name);
|
auto const filePath = ox::sfmt("{}{}", path, name);
|
||||||
oxRequire(stat, romFs.stat(filePath));
|
OX_REQUIRE(stat, romFs.stat(filePath));
|
||||||
if (stat.fileType == ox::FileType::Directory) {
|
if (stat.fileType == ox::FileType::Directory) {
|
||||||
auto const dir = ox::sfmt("{}{}/", path, name);
|
auto const dir = ox::sfmt("{}{}/", path, name);
|
||||||
oxReturnError(preloadDir(manifest, ts, romFs, pl, dir));
|
OX_RETURN_ERROR(preloadDir(manifest, ts, romFs, pl, dir));
|
||||||
} else {
|
} else {
|
||||||
auto const err = preloadObj(ts, romFs, pl, filePath);
|
auto const err = preloadObj(ts, romFs, pl, filePath);
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -177,14 +177,14 @@ ox::Error appendBinary(ox::Buffer &binBuff, ox::SpanView<char> const&fsBuff, ox:
|
|||||||
static_assert(mediaHdr.bytes() == hdrSize);
|
static_assert(mediaHdr.bytes() == hdrSize);
|
||||||
static_assert(preloadHdr.bytes() == hdrSize);
|
static_assert(preloadHdr.bytes() == hdrSize);
|
||||||
ox::BufferWriter w(&binBuff);
|
ox::BufferWriter w(&binBuff);
|
||||||
oxReturnError(padbin(w, hdrSize));
|
OX_RETURN_ERROR(padbin(w, hdrSize));
|
||||||
oxReturnError(w.write(mediaHdr.data(), mediaHdr.bytes()));
|
OX_RETURN_ERROR(w.write(mediaHdr.data(), mediaHdr.bytes()));
|
||||||
oxReturnError(w.write(fsBuff.data(), fsBuff.size()));
|
OX_RETURN_ERROR(w.write(fsBuff.data(), fsBuff.size()));
|
||||||
oxReturnError(padbin(w, hdrSize));
|
OX_RETURN_ERROR(padbin(w, hdrSize));
|
||||||
oxReturnError(w.write(preloadHdr.data(), preloadHdr.bytes()));
|
OX_RETURN_ERROR(w.write(preloadHdr.data(), preloadHdr.bytes()));
|
||||||
oxReturnError(pl.offsetPtrs(binBuff.size()));
|
OX_RETURN_ERROR(pl.offsetPtrs(binBuff.size()));
|
||||||
auto const&plBuff = pl.buff();
|
auto const&plBuff = pl.buff();
|
||||||
oxReturnError(w.write(plBuff.data(), plBuff.size()));
|
OX_RETURN_ERROR(w.write(plBuff.data(), plBuff.size()));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,15 +110,15 @@ class Converter: public BaseConverter {
|
|||||||
ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(
|
ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(
|
||||||
keel::Context &ctx, Wrap &src) const noexcept final {
|
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)));
|
OX_RETURN_ERROR(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst)));
|
||||||
return {std::move(dst)};
|
return {std::move(dst)};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
||||||
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
|
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
|
||||||
oxRequireM(src, readAsset<SrcType>(srcBuff));
|
OX_REQUIRE_M(src, readAsset<SrcType>(srcBuff));
|
||||||
auto dst = makeWrap<DstType>();
|
auto dst = makeWrap<DstType>();
|
||||||
oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst)));
|
OX_RETURN_ERROR(convert(ctx, src, wrapCast<DstType>(*dst)));
|
||||||
return {std::move(dst)};
|
return {std::move(dst)};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ template<typename DstType>
|
|||||||
ox::Result<DstType> convert(keel::Context &ctx, ox::BufferView const&srcBuffer) noexcept {
|
ox::Result<DstType> convert(keel::Context &ctx, ox::BufferView const&srcBuffer) 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));
|
OX_REQUIRE(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
||||||
return std::move(wrapCast<DstType>(out));
|
return std::move(wrapCast<DstType>(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ template<typename DstType>
|
|||||||
ox::Error convert(keel::Context &ctx, ox::BufferView const&buff, DstType *outObj) noexcept {
|
ox::Error convert(keel::Context &ctx, ox::BufferView const&buff, DstType *outObj) 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(outPtr, convert(ctx, buff, DstTypeName, DstTypeVersion));
|
OX_REQUIRE(outPtr, convert(ctx, buff, DstTypeName, DstTypeVersion));
|
||||||
*outObj = std::move(wrapCast<DstType>(*outPtr));
|
*outObj = std::move(wrapCast<DstType>(*outPtr));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -155,14 +155,14 @@ ox::Result<ox::Buffer> convertBuffToBuff(
|
|||||||
keel::Context &ctx, ox::BufferView const&srcBuffer, ox::ClawFormat fmt) noexcept {
|
keel::Context &ctx, ox::BufferView 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));
|
OX_REQUIRE(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
||||||
return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
|
return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
|
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
|
||||||
ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept {
|
ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept {
|
||||||
if (typeId == ox::ModelTypeId_v<From>) {
|
if (typeId == ox::ModelTypeId_v<From>) {
|
||||||
oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
|
OX_RETURN_ERROR(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -43,7 +43,7 @@ ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept {
|
|||||||
return ox::Error(1, "Buffer too small for expected data");
|
return ox::Error(1, "Buffer too small for expected data");
|
||||||
}
|
}
|
||||||
buff += offset;
|
buff += offset;
|
||||||
oxReturnError(ox::readClawHeader(buff).moveTo(out.value.clawHdr));
|
OX_RETURN_ERROR(ox::readClawHeader(buff).moveTo(out.value.clawHdr));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ ox::Error init(
|
|||||||
|
|
||||||
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
|
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
|
||||||
auto ctx = ox::make_unique<Context>();
|
auto ctx = ox::make_unique<Context>();
|
||||||
oxReturnError(keel::init(*ctx, std::move(fs), appName));
|
OX_RETURN_ERROR(keel::init(*ctx, std::move(fs), appName));
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,19 +48,19 @@ void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uui
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
||||||
oxRequire(files, ctx.rom->ls(path));
|
OX_REQUIRE(files, ctx.rom->ls(path));
|
||||||
for (auto const&f : files) {
|
for (auto const&f : files) {
|
||||||
oxRequireM(filePath, ox::join("/", ox::Array<ox::StringView, 2>{path, f}));
|
OX_REQUIRE_M(filePath, ox::join("/", ox::Array<ox::StringView, 2>{path, f}));
|
||||||
oxRequire(stat, ctx.rom->stat(filePath));
|
OX_REQUIRE(stat, ctx.rom->stat(filePath));
|
||||||
if (stat.fileType == ox::FileType::NormalFile) {
|
if (stat.fileType == ox::FileType::NormalFile) {
|
||||||
oxRequire(data, ctx.rom->read(filePath));
|
OX_REQUIRE(data, ctx.rom->read(filePath));
|
||||||
auto const [hdr, err] = readAssetHeader(data);
|
auto const [hdr, err] = readAssetHeader(data);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
createUuidMapping(ctx, filePath, hdr.uuid);
|
createUuidMapping(ctx, filePath, hdr.uuid);
|
||||||
}
|
}
|
||||||
} else if (stat.fileType == ox::FileType::Directory) {
|
} else if (stat.fileType == ox::FileType::Directory) {
|
||||||
if (!beginsWith(f, ".")) {
|
if (!beginsWith(f, ".")) {
|
||||||
oxReturnError(buildUuidMap(ctx, filePath));
|
OX_RETURN_ERROR(buildUuidMap(ctx, filePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ ox::Error buildUuidMap(Context &ctx) noexcept {
|
|||||||
|
|
||||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
|
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
oxRequire(out, ctx.pathToUuid.at(path));
|
OX_REQUIRE(out, ctx.pathToUuid.at(path));
|
||||||
return *out;
|
return *out;
|
||||||
#else
|
#else
|
||||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||||
@ -84,7 +84,7 @@ ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::UUID> getUuid(Context &ctx, ox::FileAddress const&fileAddr) noexcept {
|
ox::Result<ox::UUID> getUuid(Context &ctx, ox::FileAddress const&fileAddr) noexcept {
|
||||||
oxRequire(path, fileAddr.getPath());
|
OX_REQUIRE(path, fileAddr.getPath());
|
||||||
return getUuid(ctx, path);
|
return getUuid(ctx, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,11 +98,11 @@ ox::Result<ox::UUID> getUuid(Context &ctx, ox::StringView path) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::CStringView> getPath(Context &ctx, ox::FileAddress const&fileAddr) noexcept {
|
ox::Result<ox::CStringView> getPath(Context &ctx, ox::FileAddress const&fileAddr) noexcept {
|
||||||
oxRequire(path, fileAddr.getPath());
|
OX_REQUIRE(path, fileAddr.getPath());
|
||||||
if (beginsWith(path, "uuid://")) {
|
if (beginsWith(path, "uuid://")) {
|
||||||
auto const uuid = substr(path, 7);
|
auto const uuid = substr(path, 7);
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid));
|
||||||
return ox::CStringView{*out};
|
return ox::CStringView{*out};
|
||||||
#else
|
#else
|
||||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||||
@ -116,7 +116,7 @@ ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringView fileId) noexce
|
|||||||
if (beginsWith(fileId, "uuid://")) {
|
if (beginsWith(fileId, "uuid://")) {
|
||||||
auto const uuid = substr(fileId, 7);
|
auto const uuid = substr(fileId, 7);
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid));
|
||||||
return ox::CStringView{*out};
|
return ox::CStringView{*out};
|
||||||
#else
|
#else
|
||||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||||
@ -129,7 +129,7 @@ ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringView fileId) noexce
|
|||||||
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept {
|
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept {
|
||||||
uuid = substr(uuid, 7);
|
uuid = substr(uuid, 7);
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid));
|
||||||
return ox::CStringView(*out);
|
return ox::CStringView(*out);
|
||||||
#else
|
#else
|
||||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||||
@ -138,7 +138,7 @@ ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noe
|
|||||||
|
|
||||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::StringViewCR uuid) noexcept {
|
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::StringViewCR uuid) noexcept {
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid));
|
||||||
return ox::CStringView(*out);
|
return ox::CStringView(*out);
|
||||||
#else
|
#else
|
||||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||||
@ -147,7 +147,7 @@ ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::StringViewCR uuid) noex
|
|||||||
|
|
||||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
|
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
oxRequireM(out, ctx.uuidToPath.at(uuid.toString()));
|
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid.toString()));
|
||||||
return ox::CStringView(*out);
|
return ox::CStringView(*out);
|
||||||
#else
|
#else
|
||||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||||
@ -158,7 +158,7 @@ ox::Error reloadAsset(keel::Context &ctx, ox::StringView assetId) noexcept {
|
|||||||
ox::UUIDStr uuidStr;
|
ox::UUIDStr uuidStr;
|
||||||
if (beginsWith(assetId, "uuid://")) {
|
if (beginsWith(assetId, "uuid://")) {
|
||||||
assetId = substr(assetId, 7);
|
assetId = substr(assetId, 7);
|
||||||
oxRequire(p, keel::uuidToPath(ctx, assetId));
|
OX_REQUIRE(p, keel::uuidToPath(ctx, assetId));
|
||||||
} else {
|
} else {
|
||||||
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
|
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
|
||||||
if (!uuidErr) {
|
if (!uuidErr) {
|
||||||
@ -207,18 +207,18 @@ void unloadRom(char*) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR path) noexcept {
|
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR path) noexcept {
|
||||||
oxRequire(stat, ctx.rom->stat(path));
|
OX_REQUIRE(stat, ctx.rom->stat(path));
|
||||||
oxRequire(buff, static_cast<ox::MemFS&>(*ctx.rom).directAccess(path));
|
OX_REQUIRE(buff, static_cast<ox::MemFS&>(*ctx.rom).directAccess(path));
|
||||||
PreloadPtr p;
|
PreloadPtr p;
|
||||||
oxReturnError(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
|
OX_RETURN_ERROR(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&addr) noexcept {
|
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&addr) noexcept {
|
||||||
oxRequire(stat, ctx.rom->stat(addr));
|
OX_REQUIRE(stat, ctx.rom->stat(addr));
|
||||||
oxRequire(buff, static_cast<ox::MemFS&>(*ctx.rom).directAccess(addr));
|
OX_REQUIRE(buff, static_cast<ox::MemFS&>(*ctx.rom).directAccess(addr));
|
||||||
PreloadPtr p;
|
PreloadPtr p;
|
||||||
oxReturnError(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
|
OX_RETURN_ERROR(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept {
|
|||||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept {
|
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept {
|
||||||
auto const lastDot = ox::lastIndexOf(path, '.');
|
auto const lastDot = ox::lastIndexOf(path, '.');
|
||||||
if (!lastDot.error && substr(path, lastDot.value) == ".oxfs") {
|
if (!lastDot.error && substr(path, lastDot.value) == ".oxfs") {
|
||||||
oxRequire(rom, loadRom(path));
|
OX_REQUIRE(rom, loadRom(path));
|
||||||
return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};
|
return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};
|
||||||
} else {
|
} else {
|
||||||
#ifdef OX_HAS_PASSTHROUGHFS
|
#ifdef OX_HAS_PASSTHROUGHFS
|
||||||
|
@ -43,7 +43,7 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
|
|||||||
static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
||||||
for (auto const mod : keel::modules()) {
|
for (auto const mod : keel::modules()) {
|
||||||
for (auto gen : mod->types()) {
|
for (auto gen : mod->types()) {
|
||||||
oxReturnError(gen(ts));
|
OX_RETURN_ERROR(gen(ts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
@ -55,33 +55,37 @@ static ox::Error pack(
|
|||||||
ox::StringView argManifest,
|
ox::StringView argManifest,
|
||||||
ox::StringView projectDataDir) noexcept {
|
ox::StringView projectDataDir) noexcept {
|
||||||
ox::Buffer dstBuff(32 * ox::units::MB);
|
ox::Buffer dstBuff(32 * ox::units::MB);
|
||||||
oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
||||||
ox::FileSystem32 dst(dstBuff);
|
ox::FileSystem32 dst(dstBuff);
|
||||||
oxRequire(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
OX_REQUIRE(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
||||||
keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir));
|
keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir));
|
||||||
oxReturnError(generateTypes(ts));
|
OX_RETURN_ERROR(generateTypes(ts));
|
||||||
keel::Manifest manifest;
|
keel::Manifest manifest;
|
||||||
oxReturnError(keel::pack(manifest, *ctx, ts, dst));
|
OX_RETURN_ERROR(keel::pack(manifest, *ctx, ts, dst));
|
||||||
oxRequireM(pl, keel::GbaPreloader::make());
|
OX_REQUIRE_M(pl, keel::GbaPreloader::make());
|
||||||
oxReturnError(preload(manifest, ts, dst, *pl));
|
OX_RETURN_ERROR(preload(manifest, ts, dst, *pl));
|
||||||
oxReturnError(dst.resize());
|
OX_RETURN_ERROR(dst.resize());
|
||||||
// resize buffer
|
// resize buffer
|
||||||
oxRequire(dstSize, dst.size());
|
OX_REQUIRE(dstSize, dst.size());
|
||||||
dstBuff.resize(dstSize);
|
dstBuff.resize(dstSize);
|
||||||
// concatenate ROM segments
|
// concatenate ROM segments
|
||||||
oxRequireM(romBuff, readFileBuff(argRomBin));
|
OX_REQUIRE_M(romBuff, readFileBuff(argRomBin));
|
||||||
oxOutf("Input exe size: {} bytes\n", romBuff.size());
|
oxOutf("Input exe size: {} bytes\n", romBuff.size());
|
||||||
oxOutf("Dest FS size: {} bytes\n", dstSize);
|
oxOutf("Dest FS size: {} bytes\n", dstSize);
|
||||||
oxOutf("Preload buff size: {} bytes\n", pl->buff().size());
|
oxOutf("Preload buff size: {} bytes\n", pl->buff().size());
|
||||||
oxReturnError(appendBinary(romBuff, dstBuff, *pl));
|
OX_RETURN_ERROR(appendBinary(romBuff, dstBuff, *pl));
|
||||||
oxOutf("Final ROM buff size: {} bytes\n", romBuff.size());
|
oxOutf("Final ROM buff size: {} bytes\n", romBuff.size());
|
||||||
oxReturnError(writeFileBuff(argRomBin, romBuff));
|
OX_RETURN_ERROR(writeFileBuff(argRomBin, romBuff));
|
||||||
oxRequire(manifestJson, ox::writeOCString(manifest));
|
OX_REQUIRE(manifestJson, ox::writeOCString(manifest));
|
||||||
oxReturnError(writeFileBuff(argManifest, {manifestJson.data(), manifestJson.len()}));
|
OX_RETURN_ERROR(writeFileBuff(argManifest, {manifestJson.data(), manifestJson.len()}));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ox::Error run(ox::SpanView<char const*> argv, ox::StringView projectDataDir) noexcept {
|
ox::Error run(
|
||||||
|
[[maybe_unused]] ox::StringView project,
|
||||||
|
[[maybe_unused]] ox::StringView appName,
|
||||||
|
ox::StringView projectDataDir,
|
||||||
|
ox::SpanView<ox::CString> argv) noexcept {
|
||||||
ox::ClArgs const args(argv);
|
ox::ClArgs const args(argv);
|
||||||
auto const argSrc = args.getString("src", "");
|
auto const argSrc = args.getString("src", "");
|
||||||
auto const argRomBin = args.getString("rom-bin", "");
|
auto const argRomBin = args.getString("rom-bin", "");
|
||||||
@ -96,11 +100,3 @@ static ox::Error run(ox::SpanView<char const*> argv, ox::StringView projectDataD
|
|||||||
}
|
}
|
||||||
return pack(argSrc, argRomBin, argManifest, projectDataDir);
|
return pack(argSrc, argRomBin, argManifest, projectDataDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error run(
|
|
||||||
[[maybe_unused]] ox::StringView project,
|
|
||||||
[[maybe_unused]] ox::StringView appName,
|
|
||||||
ox::StringView projectDataDir,
|
|
||||||
ox::SpanView<ox::CString> argv) noexcept {
|
|
||||||
return ::run(argv, projectDataDir);
|
|
||||||
}
|
|
||||||
|
@ -15,19 +15,19 @@ static ox::Error pathToInode(
|
|||||||
ox::FileSystem &dest,
|
ox::FileSystem &dest,
|
||||||
ox::ModelObject &obj) noexcept {
|
ox::ModelObject &obj) noexcept {
|
||||||
auto &o = obj;
|
auto &o = obj;
|
||||||
oxRequire(typeVal, o.at("type"));
|
OX_REQUIRE(typeVal, o.at("type"));
|
||||||
auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
|
auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
|
||||||
oxRequire(dataVal, o.at("data"));
|
OX_REQUIRE(dataVal, o.at("data"));
|
||||||
auto &data = dataVal->get<ox::ModelUnion>();
|
auto &data = dataVal->get<ox::ModelUnion>();
|
||||||
ox::String path;
|
ox::String path;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ox::FileAddressType::Path: {
|
case ox::FileAddressType::Path: {
|
||||||
oxRequire(pathVal, data.at("path"));
|
OX_REQUIRE(pathVal, data.at("path"));
|
||||||
path = pathVal->get<ox::String>();
|
path = pathVal->get<ox::String>();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ox::FileAddressType::ConstPath: {
|
case ox::FileAddressType::ConstPath: {
|
||||||
oxRequire(pathVal, data.at("constPath"));
|
OX_REQUIRE(pathVal, data.at("constPath"));
|
||||||
path = pathVal->get<ox::String>();
|
path = pathVal->get<ox::String>();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -37,10 +37,10 @@ static ox::Error pathToInode(
|
|||||||
}
|
}
|
||||||
if (beginsWith(path, "uuid://")) {
|
if (beginsWith(path, "uuid://")) {
|
||||||
auto const uuid = ox::substr(path, 7);
|
auto const uuid = ox::substr(path, 7);
|
||||||
oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
|
OX_RETURN_ERROR(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
|
||||||
}
|
}
|
||||||
oxRequire(s, dest.stat(path));
|
OX_REQUIRE(s, dest.stat(path));
|
||||||
oxReturnError(typeVal->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
|
OX_RETURN_ERROR(typeVal->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
|
||||||
oxOutf("\tpath to inode: {} => {}\n", path, s.inode);
|
oxOutf("\tpath to inode: {} => {}\n", path, s.inode);
|
||||||
return data.set(2, s.inode);
|
return data.set(2, s.inode);
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ static ox::Error transformFileAddressesVec(
|
|||||||
ox::FileSystem &dest,
|
ox::FileSystem &dest,
|
||||||
ox::ModelValueVector &v) noexcept {
|
ox::ModelValueVector &v) noexcept {
|
||||||
for (auto &f : v) {
|
for (auto &f : v) {
|
||||||
oxReturnError(transformFileAddresses(ctx, dest, f));
|
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, f));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ static ox::Error transformFileAddressesObj(
|
|||||||
}
|
}
|
||||||
for (auto &f : obj) {
|
for (auto &f : obj) {
|
||||||
auto &v = f->value;
|
auto &v = f->value;
|
||||||
oxReturnError(transformFileAddresses(ctx, dest, v));
|
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, v));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -96,12 +96,12 @@ static ox::Error performPackTransforms(
|
|||||||
ManifestEntry &entry,
|
ManifestEntry &entry,
|
||||||
Context &ctx,
|
Context &ctx,
|
||||||
ox::Buffer &clawData) noexcept {
|
ox::Buffer &clawData) noexcept {
|
||||||
oxRequireM(typeId, readAssetTypeId(clawData));
|
OX_REQUIRE_M(typeId, readAssetTypeId(clawData));
|
||||||
for (auto const tr : packTransforms(ctx)) {
|
for (auto const tr : packTransforms(ctx)) {
|
||||||
bool changed{};
|
bool changed{};
|
||||||
oxReturnError(tr(ctx, clawData, typeId).moveTo(changed));
|
OX_RETURN_ERROR(tr(ctx, clawData, typeId).moveTo(changed));
|
||||||
if (changed) {
|
if (changed) {
|
||||||
oxReturnError(readAssetTypeId(clawData).moveTo(typeId));
|
OX_RETURN_ERROR(readAssetTypeId(clawData).moveTo(typeId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entry.type = ox::String{typeId};
|
entry.type = ox::String{typeId};
|
||||||
@ -115,17 +115,17 @@ static ox::Error doTransformations(
|
|||||||
ox::FileSystem &dest,
|
ox::FileSystem &dest,
|
||||||
ox::StringViewCR filePath) noexcept {
|
ox::StringViewCR filePath) noexcept {
|
||||||
// load file
|
// load file
|
||||||
oxRequire(s, dest.stat(filePath));
|
OX_REQUIRE(s, dest.stat(filePath));
|
||||||
// do transformations
|
// do transformations
|
||||||
oxRequireM(buff, dest.read(s.inode));
|
OX_REQUIRE_M(buff, dest.read(s.inode));
|
||||||
oxReturnError(keel::performPackTransforms(manifest.files[filePath], ctx, buff));
|
OX_RETURN_ERROR(keel::performPackTransforms(manifest.files[filePath], ctx, buff));
|
||||||
// transform FileAddresses
|
// transform FileAddresses
|
||||||
oxRequireM(obj, keel::readAsset(ts, buff));
|
OX_REQUIRE_M(obj, keel::readAsset(ts, buff));
|
||||||
oxOutf("transforming {}\n", filePath);
|
oxOutf("transforming {}\n", filePath);
|
||||||
oxReturnError(transformFileAddressesObj(ctx, dest, obj));
|
OX_RETURN_ERROR(transformFileAddressesObj(ctx, dest, obj));
|
||||||
oxReturnError(ox::writeClaw(obj).moveTo(buff));
|
OX_RETURN_ERROR(ox::writeClaw(obj).moveTo(buff));
|
||||||
// write file to dest
|
// write file to dest
|
||||||
oxReturnError(dest.write(s.inode, buff));
|
OX_RETURN_ERROR(dest.write(s.inode, buff));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,13 +139,13 @@ static ox::Error transformClaw(
|
|||||||
ox::StringViewCR path) noexcept {
|
ox::StringViewCR path) noexcept {
|
||||||
// copy
|
// copy
|
||||||
oxTracef("pack.transformClaw", "path: {}", path);
|
oxTracef("pack.transformClaw", "path: {}", path);
|
||||||
oxRequire(fileList, dest.ls(path));
|
OX_REQUIRE(fileList, dest.ls(path));
|
||||||
for (auto const&name : fileList) {
|
for (auto const&name : fileList) {
|
||||||
auto const filePath = ox::sfmt("{}{}", path, name);
|
auto const filePath = ox::sfmt("{}{}", path, name);
|
||||||
oxRequire(stat, dest.stat(filePath));
|
OX_REQUIRE(stat, dest.stat(filePath));
|
||||||
if (stat.fileType == ox::FileType::Directory) {
|
if (stat.fileType == ox::FileType::Directory) {
|
||||||
auto const dir = ox::sfmt("{}{}/", path, name);
|
auto const dir = ox::sfmt("{}{}/", path, name);
|
||||||
oxReturnError(transformClaw(manifest, ctx, ts, dest, dir));
|
OX_RETURN_ERROR(transformClaw(manifest, ctx, ts, dest, dir));
|
||||||
} else {
|
} else {
|
||||||
auto const err = doTransformations(manifest, ctx, ts, dest, filePath);
|
auto const err = doTransformations(manifest, ctx, ts, dest, filePath);
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -166,28 +166,28 @@ static ox::Error copy(
|
|||||||
oxOutf("{}copying directory: {}\n", logPrefix, path);
|
oxOutf("{}copying directory: {}\n", logPrefix, path);
|
||||||
auto const childLogPrefix = ox::sfmt("{}\t", logPrefix);
|
auto const childLogPrefix = ox::sfmt("{}\t", logPrefix);
|
||||||
// copy
|
// copy
|
||||||
oxRequire(fileList, src.ls(path));
|
OX_REQUIRE(fileList, src.ls(path));
|
||||||
for (auto const&name : fileList) {
|
for (auto const&name : fileList) {
|
||||||
auto const currentFile = ox::sfmt("{}{}", path, name);
|
auto const currentFile = ox::sfmt("{}{}", path, name);
|
||||||
if (beginsWith(name, ".")) {
|
if (beginsWith(name, ".")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
oxRequire(srcStat, src.stat(currentFile));
|
OX_REQUIRE(srcStat, src.stat(currentFile));
|
||||||
if (srcStat.fileType == ox::FileType::Directory) {
|
if (srcStat.fileType == ox::FileType::Directory) {
|
||||||
oxReturnError(dest.mkdir(currentFile, true));
|
OX_RETURN_ERROR(dest.mkdir(currentFile, true));
|
||||||
oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
|
OX_RETURN_ERROR(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
|
||||||
} else {
|
} else {
|
||||||
// load file
|
// load file
|
||||||
oxOutf("{}copying file: {}...", childLogPrefix, currentFile);
|
oxOutf("{}copying file: {}...", childLogPrefix, currentFile);
|
||||||
ox::StringView status = "failed";
|
ox::StringView status = "failed";
|
||||||
oxDefer [&status] {
|
OX_DEFER [&status] {
|
||||||
oxOutf(" {}\n", status);
|
oxOutf(" {}\n", status);
|
||||||
};
|
};
|
||||||
oxRequireM(buff, src.read(currentFile));
|
OX_REQUIRE_M(buff, src.read(currentFile));
|
||||||
// write file to dest
|
// write file to dest
|
||||||
oxReturnError(dest.write(currentFile, buff));
|
OX_RETURN_ERROR(dest.write(currentFile, buff));
|
||||||
status = "OK";
|
status = "OK";
|
||||||
oxRequire(dstStat, dest.stat(currentFile));
|
OX_REQUIRE(dstStat, dest.stat(currentFile));
|
||||||
manifest.files[currentFile] = {
|
manifest.files[currentFile] = {
|
||||||
.inode = dstStat.inode,
|
.inode = dstStat.inode,
|
||||||
.type = ox::String{keel::readAssetTypeId(buff).or_value({})},
|
.type = ox::String{keel::readAssetTypeId(buff).or_value({})},
|
||||||
@ -202,9 +202,9 @@ ox::Error pack(
|
|||||||
keel::Context &ctx,
|
keel::Context &ctx,
|
||||||
ox::TypeStore &ts,
|
ox::TypeStore &ts,
|
||||||
ox::FileSystem &dest) noexcept {
|
ox::FileSystem &dest) noexcept {
|
||||||
oxReturnError(copy(manifest, *ctx.rom, dest, "/"));
|
OX_RETURN_ERROR(copy(manifest, *ctx.rom, dest, "/"));
|
||||||
oxOut("Doing transforms\n");
|
oxOut("Doing transforms\n");
|
||||||
oxReturnError(transformClaw(manifest, ctx, ts, dest, "/"));
|
OX_RETURN_ERROR(transformClaw(manifest, ctx, ts, dest, "/"));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ ox::Result<ox::UPtr<Wrap>> convert(
|
|||||||
ox::BufferView const&srcBuffer,
|
ox::BufferView const&srcBuffer,
|
||||||
ox::StringViewCR dstTypeName,
|
ox::StringViewCR dstTypeName,
|
||||||
int dstTypeVersion) noexcept {
|
int dstTypeVersion) noexcept {
|
||||||
oxRequire(hdr, readAssetHeader(srcBuffer));
|
OX_REQUIRE(hdr, readAssetHeader(srcBuffer));
|
||||||
return convert(
|
return convert(
|
||||||
ctx,
|
ctx,
|
||||||
converters(ctx),
|
converters(ctx),
|
||||||
|
@ -13,9 +13,9 @@ TypeStore::TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept:
|
|||||||
|
|
||||||
ox::Result<ox::UPtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::StringView const typeId) noexcept {
|
ox::Result<ox::UPtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::StringView const typeId) noexcept {
|
||||||
auto const path = ox::sfmt("{}/{}", m_descPath, typeId);
|
auto const path = ox::sfmt("{}/{}", m_descPath, typeId);
|
||||||
oxRequire(buff, m_fs.read(path));
|
OX_REQUIRE(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));
|
OX_RETURN_ERROR(ox::readClaw<ox::DescriptorType>(buff, *dt));
|
||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
|||||||
[]() -> ox::Error {
|
[]() -> ox::Error {
|
||||||
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
|
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
|
||||||
constexpr ox::StringView hdr = "K1;8d814442-f46e-4cc3-8edc-ca3c01cc86db;";
|
constexpr ox::StringView hdr = "K1;8d814442-f46e-4cc3-8edc-ca3c01cc86db;";
|
||||||
oxRequire(uuid, ox::UUID::fromString(uuidStr));
|
OX_REQUIRE(uuid, ox::UUID::fromString(uuidStr));
|
||||||
ox::Array<char, hdr.len()> buff;
|
ox::Array<char, hdr.len()> buff;
|
||||||
ox::CharBuffWriter bw(buff);
|
ox::CharBuffWriter bw(buff);
|
||||||
oxReturnError(keel::writeUuidHeader(bw, uuid));
|
OX_RETURN_ERROR(keel::writeUuidHeader(bw, uuid));
|
||||||
oxExpect(ox::StringView(buff.data(), buff.size()), hdr);
|
oxExpect(ox::StringView(buff.data(), buff.size()), hdr);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ static ox::Error runApp(
|
|||||||
ox::StringViewCR appName,
|
ox::StringViewCR appName,
|
||||||
ox::StringViewCR projectDataDir,
|
ox::StringViewCR projectDataDir,
|
||||||
ox::UPtr<ox::FileSystem> &&fs) noexcept {
|
ox::UPtr<ox::FileSystem> &&fs) noexcept {
|
||||||
oxRequireM(ctx, turbine::init(std::move(fs), appName));
|
OX_REQUIRE_M(ctx, turbine::init(std::move(fs), appName));
|
||||||
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
|
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
|
||||||
turbine::setKeyEventHandler(*ctx, keyEventHandler);
|
turbine::setKeyEventHandler(*ctx, keyEventHandler);
|
||||||
turbine::setRefreshWithin(*ctx, 0);
|
turbine::setRefreshWithin(*ctx, 0);
|
||||||
|
@ -16,16 +16,16 @@ static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
|
|||||||
ox::StringView path,
|
ox::StringView path,
|
||||||
ProjectTreeModel *parent) noexcept {
|
ProjectTreeModel *parent) noexcept {
|
||||||
auto const fs = explorer.romFs();
|
auto const fs = explorer.romFs();
|
||||||
oxRequire(stat, fs->stat(path));
|
OX_REQUIRE(stat, fs->stat(path));
|
||||||
auto out = ox::make_unique<ProjectTreeModel>(explorer, ox::String(name), parent);
|
auto out = ox::make_unique<ProjectTreeModel>(explorer, ox::String(name), parent);
|
||||||
if (stat.fileType == ox::FileType::Directory) {
|
if (stat.fileType == ox::FileType::Directory) {
|
||||||
oxRequireM(children, fs->ls(path));
|
OX_REQUIRE_M(children, fs->ls(path));
|
||||||
std::sort(children.begin(), children.end());
|
std::sort(children.begin(), children.end());
|
||||||
ox::Vector<ox::UniquePtr<ProjectTreeModel>> outChildren;
|
ox::Vector<ox::UniquePtr<ProjectTreeModel>> outChildren;
|
||||||
for (auto const&childName : children) {
|
for (auto const&childName : children) {
|
||||||
if (childName[0] != '.') {
|
if (childName[0] != '.') {
|
||||||
auto const childPath = ox::sfmt("{}/{}", path, childName);
|
auto const childPath = ox::sfmt("{}/{}", path, childName);
|
||||||
oxRequireM(child, buildProjectTreeModel(explorer, childName, childPath, out.get()));
|
OX_REQUIRE_M(child, buildProjectTreeModel(explorer, childName, childPath, out.get()));
|
||||||
outChildren.emplace_back(std::move(child));
|
outChildren.emplace_back(std::move(child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ void ProjectExplorer::setModel(ox::UPtr<ProjectTreeModel> &&model) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ox::Error ProjectExplorer::refreshProjectTreeModel(ox::StringViewCR) noexcept {
|
ox::Error ProjectExplorer::refreshProjectTreeModel(ox::StringViewCR) noexcept {
|
||||||
oxRequireM(model, buildProjectTreeModel(*this, "Project", "/", nullptr));
|
OX_REQUIRE_M(model, buildProjectTreeModel(*this, "Project", "/", nullptr));
|
||||||
setModel(std::move(model));
|
setModel(std::move(model));
|
||||||
return ox::Error(0);
|
return ox::Error(0);
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,12 @@ struct StudioConfig {
|
|||||||
bool showProjectExplorer = true;
|
bool showProjectExplorer = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
oxModelBegin(StudioConfig)
|
OX_MODEL_BEGIN(StudioConfig)
|
||||||
oxModelFieldRename(activeTabItemName, active_tab_item_name)
|
OX_MODEL_FIELD_RENAME(activeTabItemName, active_tab_item_name)
|
||||||
oxModelFieldRename(projectPath, project_path)
|
OX_MODEL_FIELD_RENAME(projectPath, project_path)
|
||||||
oxModelFieldRename(openFiles, open_files)
|
OX_MODEL_FIELD_RENAME(openFiles, open_files)
|
||||||
oxModelFieldRename(showProjectExplorer, show_project_explorer)
|
OX_MODEL_FIELD_RENAME(showProjectExplorer, show_project_explorer)
|
||||||
oxModelEnd()
|
OX_MODEL_END()
|
||||||
|
|
||||||
StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept:
|
StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept:
|
||||||
m_sctx(*this, ctx),
|
m_sctx(*this, ctx),
|
||||||
@ -222,7 +222,7 @@ void StudioUI::drawTabs() noexcept {
|
|||||||
m_activeEditor = nullptr;
|
m_activeEditor = nullptr;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
oxThrowError(m_editors.erase(it).moveTo(it));
|
OX_THROW_ERROR(m_editors.erase(it).moveTo(it));
|
||||||
} catch (ox::Exception const&ex) {
|
} catch (ox::Exception const&ex) {
|
||||||
oxErrf("Editor tab deletion failed: {} ({}:{})\n", ex.what(), ex.file, ex.line);
|
oxErrf("Editor tab deletion failed: {} ({}:{})\n", ex.what(), ex.file, ex.line);
|
||||||
} catch (std::exception const&ex) {
|
} catch (std::exception const&ex) {
|
||||||
@ -323,15 +323,15 @@ void StudioUI::handleKeyInput() noexcept {
|
|||||||
ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
|
ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
std::filesystem::create_directories(toStdStringView(path), ec);
|
std::filesystem::create_directories(toStdStringView(path), ec);
|
||||||
oxReturnError(ox::Error(ec.value() != 0, "Could not create project directory"));
|
OX_RETURN_ERROR(ox::Error(ec.value() != 0, "Could not create project directory"));
|
||||||
oxReturnError(openProjectPath(path));
|
OX_RETURN_ERROR(openProjectPath(path));
|
||||||
return m_project->writeTypeStore();
|
return m_project->writeTypeStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
|
ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
|
||||||
oxRequireM(fs, keel::loadRomFs(path.view()));
|
OX_REQUIRE_M(fs, keel::loadRomFs(path.view()));
|
||||||
oxReturnError(keel::setRomFs(keelCtx(m_ctx), std::move(fs)));
|
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_ctx), std::move(fs)));
|
||||||
oxReturnError(
|
OX_RETURN_ERROR(
|
||||||
ox::make_unique_catch<studio::Project>(keelCtx(m_ctx), std::move(path), m_projectDataDir)
|
ox::make_unique_catch<studio::Project>(keelCtx(m_ctx), std::move(path), m_projectDataDir)
|
||||||
.moveTo(m_project));
|
.moveTo(m_project));
|
||||||
auto const sctx = applicationData<studio::StudioContext>(m_ctx);
|
auto const sctx = applicationData<studio::StudioContext>(m_ctx);
|
||||||
@ -366,7 +366,7 @@ ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool makeActiveTab)
|
|||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
oxRequire(ext, studio::fileExt(path));
|
OX_REQUIRE(ext, studio::fileExt(path));
|
||||||
// create Editor
|
// create Editor
|
||||||
BaseEditor *editor = nullptr;
|
BaseEditor *editor = nullptr;
|
||||||
auto const err = m_editorMakers.contains(ext) ?
|
auto const err = m_editorMakers.contains(ext) ?
|
||||||
|
@ -60,7 +60,7 @@ ox::Error writeConfig(keel::Context &ctx, ox::StringViewCR name, T const&data) n
|
|||||||
//oxErrf("Could not create config directory: {} - {}\n", path, toStr(err));
|
//oxErrf("Could not create config directory: {} - {}\n", path, toStr(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
oxRequireM(buff, ox::writeOC(data));
|
OX_REQUIRE_M(buff, ox::writeOC(data));
|
||||||
*buff.back().value = '\n';
|
*buff.back().value = '\n';
|
||||||
if (auto const err = fs.write(path, buff.data(), buff.size())) {
|
if (auto const err = fs.write(path, buff.data(), buff.size())) {
|
||||||
//oxErrf("Could not read config file: {} - {}\n", path, toStr(err));
|
//oxErrf("Could not read config file: {} - {}\n", path, toStr(err));
|
||||||
|
@ -24,7 +24,7 @@ constexpr ImTextureID toImTextureID(ox::Unsigned_c auto id) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<T> getDragDropPayload(ox::CStringView name) noexcept {
|
ox::Result<T> getDragDropPayload(ox::CStringViewCR name) noexcept {
|
||||||
auto const payload = ImGui::AcceptDragDropPayload(name.c_str());
|
auto const payload = ImGui::AcceptDragDropPayload(name.c_str());
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
return ox::Error(1, "No drag/drop payload");
|
return ox::Error(1, "No drag/drop payload");
|
||||||
@ -34,8 +34,8 @@ ox::Result<T> getDragDropPayload(ox::CStringView name) noexcept {
|
|||||||
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::CStringViewCR name, auto const&obj) noexcept {
|
||||||
oxRequire(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
|
OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
|
||||||
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
|
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ class DragDropTarget {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline auto dragDropTarget(auto const&cb) noexcept {
|
auto dragDropTarget(auto const&cb) noexcept {
|
||||||
if constexpr(ox::is_same_v<decltype(cb()), ox::Error>) {
|
if constexpr(ox::is_same_v<decltype(cb()), ox::Error>) {
|
||||||
if (ig::DragDropTarget const tgt; tgt) [[unlikely]] {
|
if (ig::DragDropTarget const tgt; tgt) [[unlikely]] {
|
||||||
return cb();
|
return cb();
|
||||||
@ -104,7 +104,7 @@ inline auto dragDropTarget(auto const&cb) noexcept {
|
|||||||
|
|
||||||
class ChildStackItem {
|
class ChildStackItem {
|
||||||
public:
|
public:
|
||||||
explicit ChildStackItem(ox::CStringView id, ImVec2 const&sz = {}) noexcept;
|
explicit ChildStackItem(ox::CStringViewCR id, ImVec2 const&sz = {}) noexcept;
|
||||||
~ChildStackItem() noexcept;
|
~ChildStackItem() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ class IDStackItem {
|
|||||||
public:
|
public:
|
||||||
explicit IDStackItem(int id) noexcept;
|
explicit IDStackItem(int id) noexcept;
|
||||||
explicit IDStackItem(const char *id) noexcept;
|
explicit IDStackItem(const char *id) noexcept;
|
||||||
explicit IDStackItem(ox::CStringView id) noexcept;
|
explicit IDStackItem(ox::CStringViewCR id) noexcept;
|
||||||
~IDStackItem() noexcept;
|
~IDStackItem() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ class IndentStackItem {
|
|||||||
|
|
||||||
void centerNextWindow(turbine::Context &ctx) noexcept;
|
void centerNextWindow(turbine::Context &ctx) noexcept;
|
||||||
|
|
||||||
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept;
|
bool PushButton(ox::CStringViewCR lbl, ImVec2 const&btnSz = BtnSz) noexcept;
|
||||||
|
|
||||||
template<typename Str>
|
template<typename Str>
|
||||||
struct TextInput {
|
struct TextInput {
|
||||||
@ -180,7 +180,7 @@ PopupResponse PopupControlsOkCancel(float popupWidth, bool &popupOpen);
|
|||||||
PopupResponse PopupControlsOkCancel(bool &popupOpen);
|
PopupResponse PopupControlsOkCancel(bool &popupOpen);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz = {285, 0});
|
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -199,19 +199,19 @@ bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &sele
|
|||||||
* @return true if new value selected, false otherwise
|
* @return true if new value selected, false otherwise
|
||||||
*/
|
*/
|
||||||
bool ComboBox(
|
bool ComboBox(
|
||||||
ox::CStringView lbl,
|
ox::CStringViewCR lbl,
|
||||||
std::function<ox::CStringView(size_t)> const&f,
|
std::function<ox::CStringView(size_t)> const&f,
|
||||||
size_t strCnt,
|
size_t strCnt,
|
||||||
size_t &selectedIdx) noexcept;
|
size_t &selectedIdx) noexcept;
|
||||||
|
|
||||||
bool FileComboBox(
|
bool FileComboBox(
|
||||||
ox::CStringView lbl,
|
ox::CStringViewCR lbl,
|
||||||
studio::StudioContext &sctx,
|
StudioContext &sctx,
|
||||||
ox::StringView fileExt,
|
ox::StringViewCR fileExt,
|
||||||
size_t &selectedIdx) noexcept;
|
size_t &selectedIdx) noexcept;
|
||||||
|
|
||||||
bool ListBox(
|
bool ListBox(
|
||||||
ox::CStringView name,
|
ox::CStringViewCR name,
|
||||||
std::function<ox::CStringView(size_t)> const&f,
|
std::function<ox::CStringView(size_t)> const&f,
|
||||||
size_t strCnt,
|
size_t strCnt,
|
||||||
size_t &selIdx) noexcept;
|
size_t &selIdx) noexcept;
|
||||||
@ -223,7 +223,7 @@ bool ListBox(
|
|||||||
* @param selIdx
|
* @param selIdx
|
||||||
* @return true if new value selected, false otherwise
|
* @return true if new value selected, false otherwise
|
||||||
*/
|
*/
|
||||||
bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t &selIdx) noexcept;
|
bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept;
|
||||||
|
|
||||||
class FilePicker {
|
class FilePicker {
|
||||||
private:
|
private:
|
||||||
@ -237,8 +237,8 @@ class FilePicker {
|
|||||||
|
|
||||||
FilePicker(
|
FilePicker(
|
||||||
studio::StudioContext &sctx,
|
studio::StudioContext &sctx,
|
||||||
ox::String title,
|
ox::StringParam title,
|
||||||
ox::String fileExt,
|
ox::StringParam fileExt,
|
||||||
ImVec2 const&size = {}) noexcept;
|
ImVec2 const&size = {}) noexcept;
|
||||||
|
|
||||||
void draw() noexcept;
|
void draw() noexcept;
|
||||||
|
@ -79,7 +79,7 @@ class ItemMakerT: public ItemMaker {
|
|||||||
ox::Result<ox::String> write(studio::StudioContext &sctx, ox::StringView const pName) const noexcept override {
|
ox::Result<ox::String> write(studio::StudioContext &sctx, ox::StringView const pName) const noexcept override {
|
||||||
auto const path = itemPath(pName);
|
auto const path = itemPath(pName);
|
||||||
createUuidMapping(keelCtx(sctx.tctx), path, ox::UUID::generate().unwrap());
|
createUuidMapping(keelCtx(sctx.tctx), path, ox::UUID::generate().unwrap());
|
||||||
oxReturnError(sctx.project->writeObj(path, m_item, m_fmt));
|
OX_RETURN_ERROR(sctx.project->writeObj(path, m_item, m_fmt));
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -130,39 +130,39 @@ class Project {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Error Project::writeObj(ox::StringViewCR path, T const&obj, ox::ClawFormat fmt) noexcept {
|
ox::Error Project::writeObj(ox::StringViewCR path, T const&obj, ox::ClawFormat fmt) noexcept {
|
||||||
oxRequireM(buff, ox::writeClaw(obj, fmt));
|
OX_REQUIRE_M(buff, ox::writeClaw(obj, fmt));
|
||||||
if (fmt == ox::ClawFormat::Organic) {
|
if (fmt == ox::ClawFormat::Organic) {
|
||||||
buff.pop_back();
|
buff.pop_back();
|
||||||
}
|
}
|
||||||
// write to FS
|
// write to FS
|
||||||
oxReturnError(mkdir(parentDir(path)));
|
OX_RETURN_ERROR(mkdir(parentDir(path)));
|
||||||
oxReturnError(writeBuff(path, buff));
|
OX_RETURN_ERROR(writeBuff(path, buff));
|
||||||
// write type descriptor
|
// write type descriptor
|
||||||
if (m_typeStore.get<T>().error) {
|
if (m_typeStore.get<T>().error) {
|
||||||
oxReturnError(ox::buildTypeDef(m_typeStore, obj));
|
OX_RETURN_ERROR(ox::buildTypeDef(m_typeStore, obj));
|
||||||
}
|
}
|
||||||
oxRequire(desc, m_typeStore.get<T>());
|
OX_REQUIRE(desc, m_typeStore.get<T>());
|
||||||
auto const descPath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc));
|
auto const descPath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc));
|
||||||
auto const descExists = m_fs.exists(descPath);
|
auto const descExists = m_fs.exists(descPath);
|
||||||
if (!descExists) {
|
if (!descExists) {
|
||||||
oxReturnError(writeTypeStore());
|
OX_RETURN_ERROR(writeTypeStore());
|
||||||
}
|
}
|
||||||
oxReturnError(keel::reloadAsset(m_ctx, path));
|
OX_RETURN_ERROR(keel::reloadAsset(m_ctx, path));
|
||||||
oxRequire(uuid, pathToUuid(m_ctx, path));
|
OX_REQUIRE(uuid, pathToUuid(m_ctx, path));
|
||||||
fileUpdated.emit(path, uuid);
|
fileUpdated.emit(path, uuid);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Error Project::writeObj(ox::StringViewCR path, T const&obj) noexcept {
|
ox::Error Project::writeObj(ox::StringViewCR path, T const&obj) noexcept {
|
||||||
oxRequire(ext, fileExt(path));
|
OX_REQUIRE(ext, fileExt(path));
|
||||||
auto const fmt = m_typeFmt[ext].or_value(ox::ClawFormat::Metal);
|
auto const fmt = m_typeFmt[ext].or_value(ox::ClawFormat::Metal);
|
||||||
return writeObj(path, obj, fmt);
|
return writeObj(path, obj, fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Result<T> Project::loadObj(ox::StringViewCR path) const noexcept {
|
ox::Result<T> Project::loadObj(ox::StringViewCR path) const noexcept {
|
||||||
oxRequire(buff, loadBuff(path));
|
OX_REQUIRE(buff, loadBuff(path));
|
||||||
if constexpr(ox::is_same_v<T, ox::ModelObject>) {
|
if constexpr(ox::is_same_v<T, ox::ModelObject>) {
|
||||||
return keel::readAsset(m_typeStore, buff);
|
return keel::readAsset(m_typeStore, buff);
|
||||||
} else {
|
} else {
|
||||||
@ -180,7 +180,7 @@ ox::Error Project::subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&s
|
|||||||
break;
|
break;
|
||||||
case ProjectEvent::FileRecognized:
|
case ProjectEvent::FileRecognized:
|
||||||
{
|
{
|
||||||
oxRequire(files, listFiles());
|
OX_REQUIRE(files, listFiles());
|
||||||
for (auto const&f : files) {
|
for (auto const&f : files) {
|
||||||
slot(f);
|
slot(f);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ constexpr auto iterateSelection(studio::Selection const&sel, auto const&cb) {
|
|||||||
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
|
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
|
||||||
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
|
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
|
||||||
if constexpr(retErr) {
|
if constexpr(retErr) {
|
||||||
oxReturnError(cb(x, y));
|
OX_RETURN_ERROR(cb(x, y));
|
||||||
} else {
|
} else {
|
||||||
cb(x, y);
|
cb(x, y);
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ constexpr auto iterateSelectionRows(studio::Selection const&sel, auto const&cb)
|
|||||||
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
|
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
|
||||||
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
|
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
|
||||||
if constexpr(retErr) {
|
if constexpr(retErr) {
|
||||||
oxReturnError(cb(x, y));
|
OX_RETURN_ERROR(cb(x, y));
|
||||||
} else {
|
} else {
|
||||||
cb(x, y);
|
cb(x, y);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace studio::ig {
|
namespace studio::ig {
|
||||||
|
|
||||||
ChildStackItem::ChildStackItem(ox::CStringView id, ImVec2 const&sz) noexcept {
|
ChildStackItem::ChildStackItem(ox::CStringViewCR id, ImVec2 const&sz) noexcept {
|
||||||
ImGui::BeginChild(id.c_str(), sz);
|
ImGui::BeginChild(id.c_str(), sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ IDStackItem::IDStackItem(const char *id) noexcept {
|
|||||||
ImGui::PushID(id);
|
ImGui::PushID(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDStackItem::IDStackItem(ox::CStringView id) noexcept: IDStackItem(id.c_str()) {}
|
IDStackItem::IDStackItem(ox::CStringViewCR id) noexcept: IDStackItem(id.c_str()) {}
|
||||||
|
|
||||||
IDStackItem::~IDStackItem() noexcept {
|
IDStackItem::~IDStackItem() noexcept {
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
@ -50,7 +50,7 @@ void centerNextWindow(turbine::Context &ctx) noexcept {
|
|||||||
ImGui::SetNextWindowPos(ImVec2(screenW / mod, screenH / mod), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
ImGui::SetNextWindowPos(ImVec2(screenW / mod, screenH / mod), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz) noexcept {
|
bool PushButton(ox::CStringViewCR lbl, ImVec2 const&btnSz) noexcept {
|
||||||
return ImGui::Button(lbl.c_str(), btnSz);
|
return ImGui::Button(lbl.c_str(), btnSz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ PopupResponse PopupControlsOkCancel(bool &popupOpen) {
|
|||||||
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen);
|
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz) {
|
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz) {
|
||||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||||
centerNextWindow(ctx);
|
centerNextWindow(ctx);
|
||||||
ImGui::OpenPopup(popupName.c_str());
|
ImGui::OpenPopup(popupName.c_str());
|
||||||
@ -105,7 +105,7 @@ bool ComboBox(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ComboBox(
|
bool ComboBox(
|
||||||
ox::CStringView lbl,
|
ox::CStringViewCR lbl,
|
||||||
std::function<ox::CStringView(size_t)> const&f,
|
std::function<ox::CStringView(size_t)> const&f,
|
||||||
size_t strCnt,
|
size_t strCnt,
|
||||||
size_t &selectedIdx) noexcept {
|
size_t &selectedIdx) noexcept {
|
||||||
@ -125,16 +125,16 @@ bool ComboBox(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FileComboBox(
|
bool FileComboBox(
|
||||||
ox::CStringView lbl,
|
ox::CStringViewCR lbl,
|
||||||
StudioContext &sctx,
|
StudioContext &sctx,
|
||||||
ox::StringView fileExt,
|
ox::StringViewCR fileExt,
|
||||||
size_t &selectedIdx) noexcept {
|
size_t &selectedIdx) noexcept {
|
||||||
auto const&list = sctx.project->fileList(fileExt);
|
auto const&list = sctx.project->fileList(fileExt);
|
||||||
return ComboBox(lbl, list, selectedIdx);
|
return ComboBox(lbl, list, selectedIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ListBox(
|
bool ListBox(
|
||||||
ox::CStringView name,
|
ox::CStringViewCR name,
|
||||||
std::function<ox::CStringView(size_t)> const&f,
|
std::function<ox::CStringView(size_t)> const&f,
|
||||||
size_t strCnt,
|
size_t strCnt,
|
||||||
size_t &selIdx) noexcept {
|
size_t &selIdx) noexcept {
|
||||||
@ -155,7 +155,7 @@ bool ListBox(
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t &selIdx) noexcept {
|
bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept {
|
||||||
return ListBox(name, [list](size_t i) -> ox::CStringView {
|
return ListBox(name, [list](size_t i) -> ox::CStringView {
|
||||||
return list[i];
|
return list[i];
|
||||||
}, list.size(), selIdx);
|
}, list.size(), selIdx);
|
||||||
@ -164,8 +164,8 @@ bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t
|
|||||||
|
|
||||||
FilePicker::FilePicker(
|
FilePicker::FilePicker(
|
||||||
StudioContext &sctx,
|
StudioContext &sctx,
|
||||||
ox::String title,
|
ox::StringParam title,
|
||||||
ox::String fileExt,
|
ox::StringParam fileExt,
|
||||||
ImVec2 const&size) noexcept:
|
ImVec2 const&size) noexcept:
|
||||||
m_sctx(sctx),
|
m_sctx(sctx),
|
||||||
m_title(std::move(title)),
|
m_title(std::move(title)),
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user