Compare commits
242 Commits
15bc41dd35
...
release-d2
Author | SHA1 | Date | |
---|---|---|---|
7f56a77e7d | |||
055d64b125 | |||
de9f842640 | |||
200e586768 | |||
f1609519a7 | |||
e452d9db4f | |||
43a87b606e | |||
8acc6244d5 | |||
bd2aeee276 | |||
89fab5cc20 | |||
1c06ea677f | |||
6b948ee069 | |||
72dddcaee5 | |||
7c824e910c | |||
a0c8146396 | |||
d5b232f5d5 | |||
c79fe3be43 | |||
1df4e78084 | |||
ffbdb09c31 | |||
b35a956e4f | |||
d3847caab4 | |||
ae066a914c | |||
67543af806 | |||
6b774ec285 | |||
4b9758f478 | |||
bf12b15fe6 | |||
a7328eb5ef | |||
b52124a0c5 | |||
eae9972f85 | |||
d83e392964 | |||
e2d0a784f1 | |||
f08821422a | |||
6a2954f82b | |||
9c19655ce2 | |||
087c834b25 | |||
79bdbf2eaa | |||
2bdc3def74 | |||
e7a663901a | |||
ffdc0ddb97 | |||
e941781f21 | |||
b869f490c3 | |||
caf8d93c21 | |||
afbf2caf97 | |||
20914eaade | |||
c5f76ff558 | |||
050339ba09 | |||
45ec39f77b | |||
319fbb2600 | |||
f43d97a17e | |||
a0974637a3 | |||
c90a8449be | |||
95dcd6bee7 | |||
5b167fd53b | |||
a701a241eb | |||
9907bb8f1d | |||
9cb6bd4a32 | |||
2dba592a42 | |||
978f2f9c4f | |||
2bad4ee416 | |||
46d1313797 | |||
fcf6f00797 | |||
ef6e3af735 | |||
80d0df2f46 | |||
9db10ec4a1 | |||
c460e0f9e0 | |||
3fa9d132ae | |||
907ead2948 | |||
8526b3fa51 | |||
6de0e882e9 | |||
d29118d783 | |||
8395128efa | |||
77c86b9516 | |||
6d2a20e8bd | |||
056284c857 | |||
3787f6adb2 | |||
ce34d450b9 | |||
8fa47e961d | |||
4e4cec1b64 | |||
9840b6fdee | |||
d0c90c39e0 | |||
7ba6fb3ac5 | |||
8dd6adc554 | |||
0093778f64 | |||
59016ee894 | |||
2b8dbb88b2 | |||
7bc1d90be8 | |||
cfb7d4f861 | |||
7a6e94959c | |||
eb1846278b | |||
00c2a39dba | |||
56f59b29fe | |||
9b11fa4e91 | |||
72e54da017 | |||
58d13a3ad9 | |||
5ae6df7e05 | |||
f71d4d3efd | |||
4b824ddef4 | |||
8b3b8d50d6 | |||
1f2e9917f1 | |||
13ddbd981e | |||
3a781f6704 | |||
30909f85a3 | |||
9cc27f5be9 | |||
cdc7428eb6 | |||
d31938ba4f | |||
935099f8d4 | |||
63608229e1 | |||
e6803af22f | |||
db961739ad | |||
2167a46266 | |||
d1c6ab9f77 | |||
c426decd99 | |||
496afd66ea | |||
ad7f696a71 | |||
819e93bb1c | |||
960889749d | |||
1b93b2038f | |||
d056323679 | |||
b10d9b6118 | |||
bd44fcf6ad | |||
a1de7fbd8a | |||
debeb83119 | |||
e2545a956b | |||
a60765b338 | |||
dc233286b4 | |||
5b929b8796 | |||
aea1aabcd7 | |||
3b8a9af97b | |||
d54853a8b5 | |||
d06412a6fe | |||
937e88ce7a | |||
9a5bdebbd7 | |||
a2361c3fd9 | |||
d6f0fe0cc8 | |||
e3b2c66d70 | |||
6dec1bf5ed | |||
af1f674bc0 | |||
6a1e2f7566 | |||
393259a010 | |||
b6b59e77f5 | |||
4a94672fdc | |||
d22c968561 | |||
79c85c2a33 | |||
3ac3b7b5e6 | |||
8c9ebbedae | |||
dbd98fe18b | |||
7418a7126a | |||
d5a1e11ec5 | |||
f4a93d8419 | |||
e923c73c91 | |||
4a9f035014 | |||
b5ee68c90b | |||
e906237d76 | |||
6bcf29b8f2 | |||
406388c042 | |||
371044d63d | |||
62c671e823 | |||
0ac494998f | |||
500c012713 | |||
1c4fb80702 | |||
a4fac4c1d3 | |||
115941a787 | |||
65a179e314 | |||
eed240eacc | |||
cc7c7ac9d7 | |||
9a80196fa6 | |||
8804819e17 | |||
ade6af8698 | |||
cd0958c691 | |||
40a3c28fbf | |||
def994f406 | |||
e808859e29 | |||
9e9f30fb18 | |||
facde6bdce | |||
1298051a1a | |||
f169c96e78 | |||
1547e8e550 | |||
795b1add64 | |||
db91ea6a63 | |||
7e19f45c69 | |||
57ba1caf90 | |||
a5bdad448f | |||
54fcbb1a33 | |||
195fd7a113 | |||
0d606643f5 | |||
402f54b3e3 | |||
ed5fc079ee | |||
140005799f | |||
7d9a1676e8 | |||
b61f81abf0 | |||
775efbddc8 | |||
1505d7ea37 | |||
26a2d340d6 | |||
ce514d586c | |||
5cbf789374 | |||
3f83a254d2 | |||
348193ae9e | |||
6b7c002a10 | |||
34081a0414 | |||
d23b69ce17 | |||
5717d67462 | |||
7666bcc2db | |||
8f5173e52a | |||
9ab3543b32 | |||
d16bbef282 | |||
a8db357360 | |||
566b724d36 | |||
b13eb0ef70 | |||
9855a0bcf0 | |||
611e2fa7cb | |||
95d9aee0cf | |||
3de03bf1fd | |||
742427584a | |||
91fd0d0786 | |||
53262c53c4 | |||
b212385b17 | |||
453e08497d | |||
72c130d8a9 | |||
9904399724 | |||
1a1c8ae6cc | |||
e9822bf124 | |||
644abd7f22 | |||
1e8d8c8b9e | |||
eccb8c4fb3 | |||
6b3974eb93 | |||
f6058f4e07 | |||
ecb09930db | |||
fc5e63a4d7 | |||
232a166833 | |||
95ba8eb138 | |||
a37df08c19 | |||
0fc7e7005c | |||
68a0dd9660 | |||
d635a954fa | |||
d0f19fd51d | |||
dd16577b50 | |||
c0aa119155 | |||
3c9ce4436a | |||
2a692fc46e | |||
e543131f0d | |||
c085c50b30 | |||
bb8fb0469a |
@ -4,10 +4,9 @@ Checks: '-*,
|
||||
cppcoreguidelines-interfaces-global-init,
|
||||
cppcoreguidelines-narrowing-conversions,
|
||||
cppcoreguidelines-pro-type-member-init,
|
||||
cppcoreguidelines-pro-type-static-cast-downcast,
|
||||
-cppcoreguidelines-pro-type-static-cast-downcast,
|
||||
cppcoreguidelines-slicing,
|
||||
google-default-arguments,
|
||||
google-explicit-constructor,
|
||||
google-runtime-operator,
|
||||
hicpp-exception-baseclass,
|
||||
hicpp-multiway-paths-covered,
|
||||
@ -53,6 +52,7 @@ readability-uniqueptr-delete-release,
|
||||
readability-use-anyofallof,
|
||||
cert-*,
|
||||
misc-*,
|
||||
-misc-include-cleaner
|
||||
-misc-use-anonymous-namespace,
|
||||
readability-duplicate-include,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
|
19
.gitea/workflows/build.yaml
Normal file
19
.gitea/workflows/build.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
name: Build
|
||||
run-name: ${{ gitea.actor }} build and test
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: nostalgia
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
- run: make purge configure-debug
|
||||
- run: make build
|
||||
- run: make test
|
||||
- run: make purge configure-asan
|
||||
- run: make build
|
||||
- run: make test
|
||||
- run: make purge configure-release
|
||||
- run: make build
|
||||
- run: make test
|
7
.gitignore
vendored
7
.gitignore
vendored
@ -2,8 +2,10 @@
|
||||
.clangd
|
||||
.current_build
|
||||
.conanbuild
|
||||
.idea
|
||||
.mypy_cache
|
||||
.stfolder
|
||||
.stignore
|
||||
scripts/__pycache__
|
||||
CMakeLists.txt.user
|
||||
ROM.oxfs
|
||||
@ -13,8 +15,7 @@ compile_commands.json
|
||||
dist
|
||||
graph_info.json
|
||||
imgui.ini
|
||||
nostalgia.gba
|
||||
nostalgia.sav
|
||||
nostalgia_media.oxfs
|
||||
*.gba
|
||||
*.sav
|
||||
studio_state.json
|
||||
tags
|
||||
|
1
.lldbinit
Normal file
1
.lldbinit
Normal file
@ -0,0 +1 @@
|
||||
type summary add --summary-string "${var.m_buff.m_items}" ox::String
|
@ -11,16 +11,11 @@ endif()
|
||||
|
||||
include(deps/buildcore/base.cmake)
|
||||
|
||||
set(NOSTALGIA_BUILD_PLAYER ON CACHE BOOL "Build Player")
|
||||
set(NOSTALGIA_BUILD_STUDIO ON CACHE BOOL "Build Studio")
|
||||
set(OX_ENABLE_TRACEHOOK OFF CACHE BOOL "Generate OxTraceHook shared library for uprobes")
|
||||
|
||||
if(BUILDCORE_TARGET STREQUAL "gba")
|
||||
set(NOSTALGIA_BUILD_STUDIO OFF)
|
||||
set(TURBINE_BUILD_TYPE "GBA")
|
||||
include(deps/gbabuildcore/base.cmake)
|
||||
else()
|
||||
set(TURBINE_BUILD_TYPE "Native")
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
@ -30,22 +25,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
if(APPLE)
|
||||
set(CMAKE_MACOSX_RPATH OFF)
|
||||
set(CMAKE_INSTALL_NAME_DIR "@executable_path/../Library/nostalgia")
|
||||
set(NOSTALGIA_DIST_BIN nostalgia-studio.app/Contents/MacOS)
|
||||
set(NOSTALGIA_DIST_LIB nostalgia-studio.app/Contents/Library)
|
||||
set(NOSTALGIA_DIST_MODULE nostalgia-studio.app/Contents/Plugins)
|
||||
set(NOSTALGIA_DIST_RESOURCES nostalgia-studio.app/Contents/Resources)
|
||||
set(NOSTALGIA_DIST_MAC_APP_CONTENTS nostalgia-studio.app/Contents)
|
||||
else()
|
||||
if(UNIX)
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
endif()
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
set(NOSTALGIA_DIST_BIN bin)
|
||||
set(NOSTALGIA_DIST_LIB lib)
|
||||
set(NOSTALGIA_DIST_MODULE lib)
|
||||
set(NOSTALGIA_DIST_RESOURCES share)
|
||||
endif()
|
||||
|
||||
add_subdirectory(deps/ox)
|
||||
@ -57,7 +42,6 @@ add_subdirectory(deps/teagba)
|
||||
if(NOT BUILDCORE_TARGET STREQUAL "gba")
|
||||
include_directories(
|
||||
SYSTEM
|
||||
deps/glfw/deps
|
||||
deps/glfw/include
|
||||
deps/imgui
|
||||
deps/imgui/backends
|
||||
@ -65,7 +49,11 @@ if(NOT BUILDCORE_TARGET STREQUAL "gba")
|
||||
/usr/local/include
|
||||
)
|
||||
add_subdirectory(deps/glad)
|
||||
set(GLFW_BUILD_EXAMPLES OFF)
|
||||
set(GLFW_BUILD_TESTS OFF)
|
||||
set(GLFW_BUILD_DOCS OFF)
|
||||
add_subdirectory(deps/glfw)
|
||||
add_subdirectory(deps/glutils)
|
||||
add_subdirectory(deps/imgui)
|
||||
add_subdirectory(deps/lodepng)
|
||||
add_subdirectory(deps/nfde)
|
||||
|
@ -31,7 +31,6 @@ RUN dnf install -y clang \
|
||||
python3-pip \
|
||||
libglvnd-devel \
|
||||
gtk3-devel
|
||||
RUN pip install conan
|
||||
|
||||
###############################################################################
|
||||
# Install devkitARM
|
||||
|
13
Makefile
13
Makefile
@ -1,31 +1,32 @@
|
||||
BC_VAR_PROJECT_NAME=nostalgia
|
||||
BC_VAR_PROJECT_NAME_CAP=Nostalgia
|
||||
BUILDCORE_PATH=deps/buildcore
|
||||
include ${BUILDCORE_PATH}/base.mk
|
||||
|
||||
ifeq ($(BC_VAR_OS),darwin)
|
||||
NOSTALGIA_STUDIO=./build/${BC_VAR_CURRENT_BUILD}/bin/nostalgia-studio.app/Contents/MacOS/nostalgia-studio
|
||||
NOSTALGIA_STUDIO=./build/${BC_VAR_CURRENT_BUILD}/bin/${BC_VAR_PROJECT_NAME_CAP}Studio.app/Contents/MacOS/${BC_VAR_PROJECT_NAME_CAP}Studio
|
||||
MGBA=/Applications/mGBA.app/Contents/MacOS/mGBA
|
||||
else
|
||||
NOSTALGIA_STUDIO=./build/${BC_VAR_CURRENT_BUILD}/bin/nostalgia-studio
|
||||
NOSTALGIA_STUDIO=./build/${BC_VAR_CURRENT_BUILD}/bin/${BC_VAR_PROJECT_NAME_CAP}Studio
|
||||
MGBA=mgba-qt
|
||||
endif
|
||||
|
||||
.PHONY: pkg-gba
|
||||
pkg-gba: build
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./scripts/pkg-gba.py sample_project
|
||||
${BC_CMD_ENVRUN} ${BC_PY3} ./scripts/pkg-gba.py sample_project ${BC_VAR_PROJECT_NAME}
|
||||
|
||||
.PHONY: run
|
||||
run: build
|
||||
./build/${BC_VAR_CURRENT_BUILD}/bin/nostalgia sample_project
|
||||
./build/${BC_VAR_CURRENT_BUILD}/bin/${BC_VAR_PROJECT_NAME} sample_project
|
||||
.PHONY: run-studio
|
||||
run-studio: build
|
||||
${NOSTALGIA_STUDIO}
|
||||
.PHONY: gba-run
|
||||
gba-run: pkg-gba
|
||||
${MGBA} nostalgia.gba
|
||||
${MGBA} ${BC_VAR_PROJECT_NAME}.gba
|
||||
.PHONY: debug
|
||||
debug: build
|
||||
${BC_CMD_HOST_DEBUGGER} ./build/${BC_VAR_CURRENT_BUILD}/bin/nostalgia sample_project
|
||||
${BC_CMD_HOST_DEBUGGER} ./build/${BC_VAR_CURRENT_BUILD}/bin/${BC_VAR_PROJECT_NAME} sample_project
|
||||
.PHONY: debug-studio
|
||||
debug-studio: build
|
||||
${BC_CMD_HOST_DEBUGGER} ${NOSTALGIA_STUDIO}
|
||||
|
@ -14,6 +14,8 @@ For Debian (and probably other Linux distros, but the package names will
|
||||
probably differ), install the following additional packages:
|
||||
* pkg-config
|
||||
* xorg-dev
|
||||
* libgtk-3-dev
|
||||
* python3-mypy
|
||||
|
||||
## Build
|
||||
|
||||
|
2
deps/buildcore/base.mk
vendored
2
deps/buildcore/base.mk
vendored
@ -89,7 +89,7 @@ purge:
|
||||
${BC_CMD_RM_RF} compile_commands.json
|
||||
.PHONY: test
|
||||
test: build
|
||||
${BC_CMD_ENVRUN} mypy ${BC_VAR_SCRIPTS}
|
||||
${BC_CMD_ENVRUN} ${BC_CMD_PY3} -m mypy ${BC_VAR_SCRIPTS}
|
||||
${BC_CMD_CMAKE_BUILD} ${BC_VAR_BUILD_PATH} test
|
||||
.PHONY: test-verbose
|
||||
test-verbose: build
|
||||
|
4
deps/buildcore/scripts/setup-build.py
vendored
4
deps/buildcore/scripts/setup-build.py
vendored
@ -99,7 +99,9 @@ def main() -> int:
|
||||
if platform.system() == 'Windows':
|
||||
cmake_cmd.append('-A x64')
|
||||
|
||||
subprocess.run(cmake_cmd)
|
||||
cmake_err = subprocess.run(cmake_cmd).returncode
|
||||
if cmake_err != 0:
|
||||
return cmake_err
|
||||
|
||||
util.mkdir_p('dist')
|
||||
if int(args.current_build) != 0:
|
||||
|
10
deps/glutils/CMakeLists.txt
vendored
Normal file
10
deps/glutils/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
project(GlUtils CXX)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
install(
|
||||
DIRECTORY
|
||||
include/glutils
|
||||
DESTINATION
|
||||
include
|
||||
)
|
@ -9,14 +9,14 @@
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <ox/std/bounds.hpp>
|
||||
#include <ox/std/cstringview.hpp>
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/std/size.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
|
||||
namespace glutils {
|
||||
|
||||
constexpr ox::StringView GlslVersion = "#version 330";
|
||||
|
||||
struct Empty {
|
||||
virtual ~Empty() noexcept = default;
|
||||
};
|
||||
@ -111,7 +111,7 @@ extern template struct GLObject<deleteProgram>;
|
||||
extern template struct GLObject<deleteShader>;
|
||||
|
||||
using GLBuffer = GLObject<deleteBuffer>;
|
||||
using GLFrameBuffer = GLObject<deleteBuffer>;
|
||||
using GLFrameBuffer = GLObject<deleteFrameBuffer>;
|
||||
using GLRenderBuffer = GLObject<deleteRenderBuffer>;
|
||||
using GLShader = GLObject<deleteShader>;
|
||||
using GLProgram = GLObject<deleteProgram>;
|
||||
@ -151,9 +151,7 @@ class FrameBufferBind {
|
||||
void bind(const FrameBuffer &fb) noexcept;
|
||||
|
||||
|
||||
ox::Result<GLProgram> buildShaderProgram(const GLchar *vert, const GLchar *frag, const GLchar *geo = nullptr) noexcept;
|
||||
|
||||
ox::Result<GLProgram> buildShaderProgram(const ox::String &vert, const ox::String &frag, const ox::String &geo = "") noexcept;
|
||||
ox::Result<GLProgram> buildShaderProgram(ox::CStringView const&vert, ox::CStringView const&frag, ox::CStringView const&geo = "") noexcept;
|
||||
|
||||
glutils::GLVertexArray generateVertexArrayObject() noexcept;
|
||||
|
||||
@ -165,7 +163,9 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept;
|
||||
/**
|
||||
* Resizes a FrameBuffer, and creates if it does not already exist.
|
||||
*/
|
||||
void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept;
|
||||
void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept;
|
||||
|
||||
void resizeInitFrameBuffer(FrameBuffer &fb, ox::Size const&sz) noexcept;
|
||||
|
||||
struct BufferSet {
|
||||
glutils::GLVertexArray vao;
|
||||
@ -176,9 +176,9 @@ struct BufferSet {
|
||||
ox::Vector<GLuint> elements;
|
||||
};
|
||||
|
||||
void sendVbo(const BufferSet &bs) noexcept;
|
||||
|
||||
void sendEbo(const BufferSet &bs) noexcept;
|
||||
void sendVbo(BufferSet const&bs) noexcept;
|
||||
|
||||
void sendEbo(BufferSet const&bs) noexcept;
|
||||
|
||||
void clearScreen() noexcept;
|
||||
|
@ -3,23 +3,21 @@ add_library(
|
||||
glutils.cpp
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
GlUtils PUBLIC
|
||||
../include
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
GlUtils PUBLIC
|
||||
OxStd
|
||||
glad
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
glutils.hpp
|
||||
DESTINATION
|
||||
include/glutils
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
GlUtils
|
||||
DESTINATION
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
||||
)
|
@ -6,7 +6,7 @@
|
||||
#include <ox/std/bstring.hpp>
|
||||
#include <ox/std/trace.hpp>
|
||||
|
||||
#include "glutils.hpp"
|
||||
#include "glutils/glutils.hpp"
|
||||
|
||||
namespace glutils {
|
||||
|
||||
@ -88,27 +88,23 @@ static ox::Result<GLShader> buildShader(
|
||||
return shader;
|
||||
}
|
||||
|
||||
ox::Result<GLProgram> buildShaderProgram(const GLchar *vert, const GLchar *frag, const GLchar *geo) noexcept {
|
||||
ox::Result<GLProgram> buildShaderProgram(
|
||||
ox::CStringView const&vert,
|
||||
ox::CStringView const&frag,
|
||||
ox::CStringView const&geo) noexcept {
|
||||
GLProgram prgm(glCreateProgram());
|
||||
oxRequire(vs, buildShader(GL_VERTEX_SHADER, vert, "vshad"));
|
||||
oxRequire(vs, buildShader(GL_VERTEX_SHADER, vert.c_str(), "vshad"));
|
||||
glAttachShader(prgm, vs);
|
||||
if (geo && ox_strlen(geo) != 0) {
|
||||
oxRequire(gs, buildShader(GL_GEOMETRY_SHADER, geo, "gshad"));
|
||||
if (geo.c_str() && geo.bytes() != 0) {
|
||||
oxRequire(gs, buildShader(GL_GEOMETRY_SHADER, geo.c_str(), "gshad"));
|
||||
glAttachShader(prgm, gs);
|
||||
}
|
||||
oxRequire(fs, buildShader(GL_FRAGMENT_SHADER, frag, "fshad"));
|
||||
oxRequire(fs, buildShader(GL_FRAGMENT_SHADER, frag.c_str(), "fshad"));
|
||||
glAttachShader(prgm, fs);
|
||||
glLinkProgram(prgm);
|
||||
return prgm;
|
||||
}
|
||||
|
||||
ox::Result<GLProgram> buildShaderProgram(
|
||||
const ox::String &vert,
|
||||
const ox::String &frag,
|
||||
const ox::String &geo) noexcept {
|
||||
return buildShaderProgram(vert.c_str(), frag.c_str(), geo.c_str());
|
||||
}
|
||||
|
||||
GLVertexArray generateVertexArrayObject() noexcept {
|
||||
GLVertexArray vao;
|
||||
glGenVertexArrays(1, &vao.id);
|
||||
@ -133,8 +129,9 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept {
|
||||
glGenTextures(1, &fb.color.id);
|
||||
glBindTexture(GL_TEXTURE_2D, fb.color);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fb.color, 0);
|
||||
// depth texture
|
||||
glGenRenderbuffers(1, &fb.depth.id);
|
||||
@ -150,21 +147,23 @@ FrameBuffer generateFrameBuffer(int width, int height) noexcept {
|
||||
return fb;
|
||||
}
|
||||
|
||||
void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept {
|
||||
if (!*fb) {
|
||||
*fb = generateFrameBuffer(width, height);
|
||||
void resizeInitFrameBuffer(FrameBuffer &fb, int width, int height) noexcept {
|
||||
if (!fb) {
|
||||
fb = generateFrameBuffer(width, height);
|
||||
return;
|
||||
}
|
||||
width = ox::max(1, width);
|
||||
height = ox::max(1, height);
|
||||
fb->width = width;
|
||||
fb->height = height;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, *fb);
|
||||
fb.width = width;
|
||||
fb.height = height;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb);
|
||||
// color texture
|
||||
glBindTexture(GL_TEXTURE_2D, fb->color);
|
||||
glBindTexture(GL_TEXTURE_2D, fb.color);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// depth texture
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fb->depth);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, fb.depth);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
|
||||
// restore primary FB
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
@ -172,13 +171,17 @@ void resizeInitFrameBuffer(FrameBuffer *fb, int width, int height) noexcept {
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
}
|
||||
|
||||
void sendVbo(const BufferSet &bs) noexcept {
|
||||
void resizeInitFrameBuffer(FrameBuffer &fb, ox::Size const&sz) noexcept {
|
||||
resizeInitFrameBuffer(fb, sz.width, sz.height);
|
||||
}
|
||||
|
||||
void sendVbo(BufferSet const&bs) noexcept {
|
||||
const auto bufferSize = static_cast<GLsizeiptr>(sizeof(decltype(bs.vertices)::value_type) * bs.vertices.size());
|
||||
glBindBuffer(GL_ARRAY_BUFFER, bs.vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, bufferSize, bs.vertices.data(), GL_DYNAMIC_DRAW);
|
||||
}
|
||||
|
||||
void sendEbo(const BufferSet &bs) noexcept {
|
||||
void sendEbo(BufferSet const&bs) noexcept {
|
||||
const auto bufferSize = static_cast<GLsizeiptr>(sizeof(decltype(bs.elements)::value_type) * bs.elements.size());
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bs.ebo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bufferSize, bs.elements.data(), GL_STATIC_DRAW);
|
5
deps/imgui/CMakeLists.txt
vendored
5
deps/imgui/CMakeLists.txt
vendored
@ -15,3 +15,8 @@ add_library(
|
||||
backends/imgui_impl_glfw.cpp
|
||||
backends/imgui_impl_opengl3.cpp
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
imgui SYSTEM PUBLIC
|
||||
.
|
||||
)
|
2
deps/nfde/CMakeLists.txt
vendored
2
deps/nfde/CMakeLists.txt
vendored
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(nativefiledialog-extended)
|
||||
|
||||
if(NOT MSVC)
|
||||
|
18
deps/ox/src/ox/clargs/clargs.cpp
vendored
18
deps/ox/src/ox/clargs/clargs.cpp
vendored
@ -13,7 +13,7 @@ namespace ox {
|
||||
|
||||
ClArgs::ClArgs(int argc, const char **args) noexcept {
|
||||
for (auto i = 0u; i < static_cast<unsigned>(argc); ++i) {
|
||||
String arg = args[i];
|
||||
auto arg = String(args[i]);
|
||||
if (arg[0] == '-') {
|
||||
while (arg[0] == '-' && arg.len()) {
|
||||
arg = arg.substr(1);
|
||||
@ -21,7 +21,7 @@ ClArgs::ClArgs(int argc, const char **args) noexcept {
|
||||
m_bools[arg] = true;
|
||||
// parse additional arguments
|
||||
if (i < static_cast<unsigned>(argc) && args[i + 1]) {
|
||||
String val = args[i + 1];
|
||||
auto val = String(args[i + 1]);
|
||||
if (val.len() && val[i] != '-') {
|
||||
if (val == "false") {
|
||||
m_bools[arg] = false;
|
||||
@ -37,32 +37,32 @@ ClArgs::ClArgs(int argc, const char **args) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
bool ClArgs::getBool(ox::CRString arg, bool defaultValue) const noexcept {
|
||||
bool ClArgs::getBool(ox::CRStringView arg, bool defaultValue) const noexcept {
|
||||
auto [value, err] = m_ints.at(arg);
|
||||
return !err ? *value : defaultValue;
|
||||
}
|
||||
|
||||
String ClArgs::getString(ox::CRString arg, const char *defaultValue) const noexcept {
|
||||
String ClArgs::getString(ox::CRStringView arg, const char *defaultValue) const noexcept {
|
||||
auto [value, err] = m_strings.at(arg);
|
||||
return !err ? *value : defaultValue;
|
||||
return !err ? ox::String(std::move(*value)) : ox::String(defaultValue);
|
||||
}
|
||||
|
||||
int ClArgs::getInt(ox::CRString arg, int defaultValue) const noexcept {
|
||||
int ClArgs::getInt(ox::CRStringView arg, int defaultValue) const noexcept {
|
||||
auto [value, err] = m_ints.at(arg);
|
||||
return !err ? *value : defaultValue;
|
||||
}
|
||||
|
||||
Result<bool> ClArgs::getBool(ox::CRString arg) const noexcept {
|
||||
Result<bool> ClArgs::getBool(ox::CRStringView arg) const noexcept {
|
||||
oxRequire(out, m_bools.at(arg));
|
||||
return *out;
|
||||
}
|
||||
|
||||
Result<String> ClArgs::getString(ox::CRString argName) const noexcept {
|
||||
Result<String> ClArgs::getString(ox::CRStringView argName) const noexcept {
|
||||
oxRequire(out, m_strings.at(argName));
|
||||
return *out;
|
||||
}
|
||||
|
||||
Result<int> ClArgs::getInt(ox::CRString arg) const noexcept {
|
||||
Result<int> ClArgs::getInt(ox::CRStringView arg) const noexcept {
|
||||
oxRequire(out, m_ints.at(arg));
|
||||
return *out;
|
||||
}
|
||||
|
12
deps/ox/src/ox/clargs/clargs.hpp
vendored
12
deps/ox/src/ox/clargs/clargs.hpp
vendored
@ -23,21 +23,21 @@ class ClArgs {
|
||||
ClArgs(int argc, const char **args) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
bool getBool(ox::CRString arg, bool defaultValue) const noexcept;
|
||||
bool getBool(ox::CRStringView arg, bool defaultValue) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
String getString(ox::CRString argName, const char *defaultValue) const noexcept;
|
||||
String getString(ox::CRStringView argName, const char *defaultValue) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
int getInt(ox::CRString arg, int defaultValue) const noexcept;
|
||||
int getInt(ox::CRStringView arg, int defaultValue) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Result<bool> getBool(ox::CRString arg) const noexcept;
|
||||
Result<bool> getBool(ox::CRStringView arg) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
Result<String> getString(ox::CRString argName) const noexcept;
|
||||
Result<String> getString(ox::CRStringView argName) const noexcept;
|
||||
|
||||
Result<int> getInt(ox::CRString arg) const noexcept;
|
||||
Result<int> getInt(ox::CRStringView arg) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
20
deps/ox/src/ox/claw/CMakeLists.txt
vendored
20
deps/ox/src/ox/claw/CMakeLists.txt
vendored
@ -16,16 +16,16 @@ target_link_libraries(
|
||||
$<$<BOOL:${OX_USE_STDLIB}>:OxOrganicClaw>
|
||||
)
|
||||
|
||||
if(OX_USE_STDLIB)
|
||||
add_executable(
|
||||
readclaw
|
||||
readclaw.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
readclaw PUBLIC
|
||||
OxClaw
|
||||
)
|
||||
endif()
|
||||
#if(OX_USE_STDLIB)
|
||||
# add_executable(
|
||||
# readclaw
|
||||
# readclaw.cpp
|
||||
# )
|
||||
# target_link_libraries(
|
||||
# readclaw PUBLIC
|
||||
# OxClaw
|
||||
# )
|
||||
#endif()
|
||||
|
||||
install(TARGETS OxClaw
|
||||
LIBRARY DESTINATION lib
|
||||
|
9
deps/ox/src/ox/claw/read.cpp
vendored
9
deps/ox/src/ox/claw/read.cpp
vendored
@ -72,9 +72,12 @@ Result<Buffer> stripClawHeader(const ox::Buffer &buff) noexcept {
|
||||
return stripClawHeader(buff.data(), buff.size());
|
||||
}
|
||||
|
||||
Result<ModelObject> readClaw(TypeStore *ts, const char *buff, std::size_t buffSz) noexcept {
|
||||
Result<ModelObject> readClaw(TypeStore &ts, const char *buff, std::size_t buffSz) noexcept {
|
||||
oxRequire(header, readClawHeader(buff, buffSz));
|
||||
oxRequire(t, ts->getLoad(header.typeName, header.typeVersion, header.typeParams));
|
||||
auto const [t, tdErr] = ts.getLoad(header.typeName, header.typeVersion, header.typeParams);
|
||||
if (tdErr) {
|
||||
return OxError(3, "Could not load type descriptor");
|
||||
}
|
||||
ModelObject obj;
|
||||
oxReturnError(obj.setType(t));
|
||||
switch (header.fmt) {
|
||||
@ -103,7 +106,7 @@ Result<ModelObject> readClaw(TypeStore *ts, const char *buff, std::size_t buffSz
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
Result<ModelObject> readClaw(TypeStore *ts, const Buffer &buff) noexcept {
|
||||
Result<ModelObject> readClaw(TypeStore &ts, const Buffer &buff) noexcept {
|
||||
return readClaw(ts, buff.data(), buff.size());
|
||||
}
|
||||
|
||||
|
4
deps/ox/src/ox/claw/read.hpp
vendored
4
deps/ox/src/ox/claw/read.hpp
vendored
@ -88,8 +88,8 @@ Result<T> readClaw(const Buffer &buff) {
|
||||
return readClaw<T>(buff.data(), buff.size());
|
||||
}
|
||||
|
||||
Result<ModelObject> readClaw(TypeStore *ts, const char *buff, std::size_t buffSz) noexcept;
|
||||
Result<ModelObject> readClaw(TypeStore &ts, const char *buff, std::size_t buffSz) noexcept;
|
||||
|
||||
Result<ModelObject> readClaw(TypeStore *ts, const Buffer &buff) noexcept;
|
||||
Result<ModelObject> readClaw(TypeStore &ts, const Buffer &buff) noexcept;
|
||||
|
||||
}
|
||||
|
28
deps/ox/src/ox/claw/test/tests.cpp
vendored
28
deps/ox/src/ox/claw/test/tests.cpp
vendored
@ -8,11 +8,7 @@
|
||||
|
||||
#undef NDEBUG
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <ox/claw/format.hpp>
|
||||
#include <ox/claw/read.hpp>
|
||||
#include <ox/claw/write.hpp>
|
||||
@ -107,12 +103,12 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
static std::map<std::string_view, ox::Error(*)()> tests = {
|
||||
static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
{
|
||||
{
|
||||
"ClawHeaderReader",
|
||||
[] {
|
||||
ox::String hdr = "O1;com.drinkingtea.ox.claw.test.Header;2;";
|
||||
constexpr auto hdr = ox::StringLiteral("O1;com.drinkingtea.ox.claw.test.Header;2;");
|
||||
auto [ch, err] = ox::readClawHeader(hdr.c_str(), hdr.len() + 1);
|
||||
oxAssert(err, "Error parsing header");
|
||||
oxAssert(ch.fmt == ox::ClawFormat::Organic, "Format wrong");
|
||||
@ -124,7 +120,7 @@ static std::map<std::string_view, ox::Error(*)()> tests = {
|
||||
{
|
||||
"ClawHeaderReader2",
|
||||
[] {
|
||||
ox::String hdr = "M2;com.drinkingtea.ox.claw.test.Header2;3;";
|
||||
constexpr auto hdr = ox::StringLiteral("M2;com.drinkingtea.ox.claw.test.Header2;3;");
|
||||
auto [ch, err] = ox::readClawHeader(hdr.c_str(), hdr.len() + 1);
|
||||
oxAssert(err, "Error parsing header");
|
||||
oxAssert(ch.fmt == ox::ClawFormat::Metal, "Format wrong");
|
||||
@ -192,14 +188,14 @@ static std::map<std::string_view, ox::Error(*)()> tests = {
|
||||
};
|
||||
|
||||
int main(int argc, const char **args) {
|
||||
int retval = -1;
|
||||
if (argc > 0) {
|
||||
auto testName = args[1];
|
||||
if (tests.find(testName) != tests.end()) {
|
||||
retval = static_cast<int>(tests[testName]());
|
||||
} else {
|
||||
retval = 1;
|
||||
}
|
||||
if (argc < 2) {
|
||||
oxError("Must specify test to run");
|
||||
}
|
||||
return retval;
|
||||
auto const testName = args[1];
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
oxAssert(func->second(), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
16
deps/ox/src/ox/event/test/tests.cpp
vendored
16
deps/ox/src/ox/event/test/tests.cpp
vendored
@ -21,7 +21,7 @@ struct TestStruct: public ox::SignalHandler {
|
||||
}
|
||||
};
|
||||
|
||||
std::map<std::string, std::function<ox::Error()>> tests = {
|
||||
std::map<ox::StringView, std::function<ox::Error()>> tests = {
|
||||
{
|
||||
"test1",
|
||||
[] {
|
||||
@ -39,12 +39,14 @@ std::map<std::string, std::function<ox::Error()>> tests = {
|
||||
};
|
||||
|
||||
int main(int argc, const char **args) {
|
||||
if (argc > 1) {
|
||||
auto testName = args[1];
|
||||
if (tests.find(testName) != tests.end()) {
|
||||
oxAssert(tests[testName](), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
if (argc < 2) {
|
||||
oxError("Must specify test to run");
|
||||
}
|
||||
auto const testName = args[1];
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
oxAssert(func->second(), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
6
deps/ox/src/ox/fs/CMakeLists.txt
vendored
6
deps/ox/src/ox/fs/CMakeLists.txt
vendored
@ -16,12 +16,6 @@ if(NOT MSVC)
|
||||
endif()
|
||||
|
||||
if(NOT OX_BARE_METAL)
|
||||
if(NOT APPLE AND NOT MSVC AND NOT ${OX_OS_FREEBSD})
|
||||
target_link_libraries(
|
||||
OxFS PUBLIC
|
||||
stdc++fs
|
||||
)
|
||||
endif()
|
||||
set_property(
|
||||
TARGET
|
||||
OxFS
|
||||
|
18
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
18
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
@ -36,13 +36,6 @@ FileAddress::FileAddress(ox::CRStringView path) noexcept {
|
||||
m_type = FileAddressType::Path;
|
||||
}
|
||||
|
||||
FileAddress::FileAddress(char *path) noexcept {
|
||||
auto pathSize = ox_strlen(path) + 1;
|
||||
m_data.path = new char[pathSize];
|
||||
memcpy(m_data.path, path, pathSize);
|
||||
m_type = FileAddressType::Path;
|
||||
}
|
||||
|
||||
FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
@ -52,9 +45,14 @@ FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
switch (m_type) {
|
||||
case FileAddressType::Path:
|
||||
{
|
||||
auto strSize = ox_strlen(other.m_data.path) + 1;
|
||||
m_data.path = new char[strSize];
|
||||
ox_memcpy(m_data.path, other.m_data.path, strSize);
|
||||
if (other.m_data.path) {
|
||||
auto strSize = ox_strlen(other.m_data.path) + 1;
|
||||
m_data.path = new char[strSize];
|
||||
ox_memcpy(m_data.path, other.m_data.path, strSize);
|
||||
} else {
|
||||
m_data.constPath = "";
|
||||
m_type = FileAddressType::ConstPath;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FileAddressType::ConstPath:
|
||||
|
99
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
99
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
@ -25,7 +25,7 @@ enum class FileAddressType: int8_t {
|
||||
class FileAddress {
|
||||
|
||||
template<typename T>
|
||||
friend constexpr Error model(T*, CommonPtrWith<FileAddress> auto*) noexcept;
|
||||
friend constexpr Error model(T *h, CommonPtrWith<FileAddress> auto *fa) noexcept;
|
||||
|
||||
public:
|
||||
static constexpr auto TypeName = "net.drinkingtea.ox.FileAddress";
|
||||
@ -59,13 +59,7 @@ class FileAddress {
|
||||
|
||||
explicit FileAddress(CRStringView path) noexcept;
|
||||
|
||||
template<std::size_t SmallStrSz>
|
||||
explicit FileAddress(const ox::BasicString<SmallStrSz> &path) noexcept: FileAddress(StringView(path)) {
|
||||
}
|
||||
|
||||
explicit FileAddress(char *path) noexcept;
|
||||
|
||||
explicit constexpr FileAddress(const char *path) noexcept;
|
||||
constexpr FileAddress(ox::StringLiteral path) noexcept;
|
||||
|
||||
constexpr ~FileAddress() noexcept;
|
||||
|
||||
@ -86,7 +80,6 @@ class FileAddress {
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Result<uint64_t> getInode() const noexcept {
|
||||
switch (m_type) {
|
||||
case FileAddressType::Inode:
|
||||
@ -96,12 +89,12 @@ class FileAddress {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr Result<const char*> getPath() const noexcept {
|
||||
constexpr Result<ox::StringView> getPath() const noexcept {
|
||||
switch (m_type) {
|
||||
case FileAddressType::Path:
|
||||
return m_data.path;
|
||||
return ox::StringView(m_data.path);
|
||||
case FileAddressType::ConstPath:
|
||||
return m_data.constPath;
|
||||
return ox::StringView(m_data.constPath);
|
||||
default:
|
||||
return OxError(1);
|
||||
}
|
||||
@ -124,8 +117,8 @@ class FileAddress {
|
||||
|
||||
};
|
||||
|
||||
constexpr FileAddress::FileAddress(const char *path) noexcept {
|
||||
m_data.constPath = path;
|
||||
constexpr FileAddress::FileAddress(ox::StringLiteral path) noexcept {
|
||||
m_data.constPath = path.c_str();
|
||||
m_type = FileAddressType::ConstPath;
|
||||
}
|
||||
|
||||
@ -133,45 +126,6 @@ constexpr FileAddress::~FileAddress() noexcept {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
template<>
|
||||
constexpr const char *getModelTypeName<FileAddress::Data>() noexcept {
|
||||
return FileAddress::Data::TypeName;
|
||||
}
|
||||
|
||||
template<>
|
||||
constexpr const char *getModelTypeName<FileAddress>() noexcept {
|
||||
return FileAddress::TypeName;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, CommonPtrWith<FileAddress::Data> auto *obj) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<FileAddress::Data>());
|
||||
oxReturnError(io->fieldCString("path", &obj->path));
|
||||
oxReturnError(io->fieldCString("constPath", &obj->path));
|
||||
oxReturnError(io->field("inode", &obj->inode));
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *io, CommonPtrWith<FileAddress> auto *fa) noexcept {
|
||||
oxReturnError(io->template setTypeInfo<FileAddress>());
|
||||
if constexpr(T::opType() == OpType::Reflect) {
|
||||
int8_t type = 0;
|
||||
oxReturnError(io->field("type", &type));
|
||||
oxReturnError(io->field("data", UnionView(&fa->m_data, 0)));
|
||||
} else if constexpr(T::opType() == OpType::Read) {
|
||||
auto type = static_cast<int8_t>(fa->m_type);
|
||||
oxReturnError(io->field("type", &type));
|
||||
fa->m_type = static_cast<FileAddressType>(type);
|
||||
oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||
} else if constexpr(T::opType() == OpType::Write) {
|
||||
auto type = static_cast<int8_t>(fa->m_type);
|
||||
oxReturnError(io->field("type", &type));
|
||||
oxReturnError(io->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||
}
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
constexpr void FileAddress::cleanup() noexcept {
|
||||
if (m_type == FileAddressType::Path) {
|
||||
safeDeleteArray(m_data.path);
|
||||
@ -184,4 +138,43 @@ constexpr void FileAddress::clear() noexcept {
|
||||
m_type = FileAddressType::None;
|
||||
}
|
||||
|
||||
template<>
|
||||
constexpr const char *getModelTypeName<FileAddress::Data>() noexcept {
|
||||
return FileAddress::Data::TypeName;
|
||||
}
|
||||
|
||||
template<>
|
||||
constexpr const char *getModelTypeName<FileAddress>() noexcept {
|
||||
return FileAddress::TypeName;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *h, CommonPtrWith<FileAddress::Data> auto *obj) noexcept {
|
||||
oxReturnError(h->template setTypeInfo<FileAddress::Data>());
|
||||
oxReturnError(h->fieldCString("path", &obj->path));
|
||||
oxReturnError(h->fieldCString("constPath", &obj->path));
|
||||
oxReturnError(h->field("inode", &obj->inode));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Error model(T *h, CommonPtrWith<FileAddress> auto *fa) noexcept {
|
||||
oxReturnError(h->template setTypeInfo<FileAddress>());
|
||||
if constexpr(T::opType() == OpType::Reflect) {
|
||||
int8_t type = -1;
|
||||
oxReturnError(h->field("type", &type));
|
||||
oxReturnError(h->field("data", UnionView(&fa->m_data, type)));
|
||||
} else if constexpr(T::opType() == OpType::Read) {
|
||||
auto type = static_cast<int8_t>(fa->m_type);
|
||||
oxReturnError(h->field("type", &type));
|
||||
fa->m_type = static_cast<FileAddressType>(type);
|
||||
oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||
} else if constexpr(T::opType() == OpType::Write) {
|
||||
auto const type = static_cast<int8_t>(fa->m_type);
|
||||
oxReturnError(h->field("type", &type));
|
||||
oxReturnError(h->field("data", UnionView(&fa->m_data, static_cast<int>(fa->m_type))));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
9
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
9
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/buffer.hpp>
|
||||
#include <ox/std/span.hpp>
|
||||
|
||||
#include <ox/fs/filestore/filestoretemplate.hpp>
|
||||
#include <ox/fs/filesystem/filelocation.hpp>
|
||||
@ -66,10 +67,18 @@ class FileSystem {
|
||||
return writeFilePath(path, buffer, size, FileType::NormalFile);
|
||||
}
|
||||
|
||||
Error write(CRStringView path, ox::Span<char> const&buff) noexcept {
|
||||
return write(path, buff.data(), buff.size(), FileType::NormalFile);
|
||||
}
|
||||
|
||||
Error write(uint64_t inode, const void *buffer, uint64_t size) noexcept {
|
||||
return write(inode, buffer, size, FileType::NormalFile);
|
||||
}
|
||||
|
||||
Error write(uint64_t inode, ox::Span<char> const&buff) noexcept {
|
||||
return write(inode, buff.data(), buff.size(), FileType::NormalFile);
|
||||
}
|
||||
|
||||
Error write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept;
|
||||
|
||||
inline Error write(CRStringView path, const void *buffer, uint64_t size, FileType fileType) noexcept {
|
||||
|
@ -24,7 +24,7 @@ PassThroughFS::PassThroughFS(CRStringView dirPath) {
|
||||
PassThroughFS::~PassThroughFS() noexcept = default;
|
||||
|
||||
String PassThroughFS::basePath() const noexcept {
|
||||
return m_path.string().c_str();
|
||||
return ox::String(m_path.string().c_str());
|
||||
}
|
||||
|
||||
Error PassThroughFS::mkdir(CRStringView path, bool recursive) noexcept {
|
||||
@ -101,7 +101,7 @@ Result<FileStat> PassThroughFS::statPath(CRStringView path) const noexcept {
|
||||
oxTracef("ox.fs.PassThroughFS.statInode", "{} {}", ec.message(), path);
|
||||
const uint64_t size = type == FileType::Directory ? 0 : std::filesystem::file_size(p, ec);
|
||||
oxTracef("ox.fs.PassThroughFS.statInode", "{} {}", ec.message(), path);
|
||||
oxTracef("ox.fs.PassThroughFS.statInode::size", "{} {}", path, size);
|
||||
oxTracef("ox.fs.PassThroughFS.statInode.size", "{} {}", path, size);
|
||||
oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: stat failed"));
|
||||
return FileStat{0, 0, size, type};
|
||||
}
|
||||
@ -188,7 +188,7 @@ Error PassThroughFS::writeFileInode(uint64_t, const void*, uint64_t, FileType) n
|
||||
std::string_view PassThroughFS::stripSlash(StringView path) noexcept {
|
||||
const auto pathLen = ox_strlen(path);
|
||||
for (auto i = 0u; i < pathLen && path[0] == '/'; i++) {
|
||||
path = path.substr(1);
|
||||
path = substr(path, 1);
|
||||
}
|
||||
return {path.data(), path.bytes()};
|
||||
}
|
||||
|
65
deps/ox/src/ox/fs/test/tests.cpp
vendored
65
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -26,11 +26,11 @@ struct OX_PACKED NodeType: public ox::ptrarith::Item<T> {
|
||||
}
|
||||
};
|
||||
|
||||
const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tests = {
|
||||
const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests = {
|
||||
{
|
||||
{
|
||||
"PtrArith::setSize",
|
||||
[](std::string_view) {
|
||||
[](ox::StringView) {
|
||||
using BuffPtr_t = uint32_t;
|
||||
ox::Vector<char> buff(5 * ox::units::MB);
|
||||
auto buffer = new (buff.data()) ox::ptrarith::NodeBuffer<BuffPtr_t, NodeType<BuffPtr_t>>(buff.size());
|
||||
@ -57,8 +57,8 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"PathIterator::next1",
|
||||
[](std::string_view) {
|
||||
ox::String path = "/usr/share/charset.gbag";
|
||||
[](ox::StringView) {
|
||||
auto const path = ox::String("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||
@ -69,8 +69,8 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"PathIterator::next2",
|
||||
[](std::string_view) {
|
||||
ox::String path = "/usr/share/";
|
||||
[](ox::StringView) {
|
||||
auto const path = ox::String("/usr/share/");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||
@ -80,8 +80,8 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"PathIterator::next3",
|
||||
[](std::string_view) {
|
||||
ox::String path = "/";
|
||||
[](ox::StringView) {
|
||||
auto const path = ox::String("/");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "\0") == 0, "PathIterator shows wrong next");
|
||||
@ -90,8 +90,8 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"PathIterator::next4",
|
||||
[](std::string_view) {
|
||||
ox::String path = "usr/share/charset.gbag";
|
||||
[](ox::StringView) {
|
||||
auto const path = ox::String("usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||
@ -102,8 +102,8 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"PathIterator::next5",
|
||||
[](std::string_view) {
|
||||
ox::String path = "usr/share/";
|
||||
[](ox::StringView) {
|
||||
auto const path = ox::String("usr/share/");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||
@ -113,8 +113,8 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"PathIterator::dirPath",
|
||||
[] (std::string_view) {
|
||||
ox::String path = "/usr/share/charset.gbag";
|
||||
[] (ox::StringView) {
|
||||
auto const path = ox::String("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.dirPath(buff, path.len()) == 0 && ox_strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
|
||||
@ -123,8 +123,8 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"PathIterator::fileName",
|
||||
[](std::string_view) {
|
||||
ox::String path = "/usr/share/charset.gbag";
|
||||
[](ox::StringView) {
|
||||
auto const path = ox::String("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.fileName(buff, path.len()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows incorrect file name");
|
||||
@ -133,7 +133,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"PathIterator::hasNext",
|
||||
[](std::string_view) {
|
||||
[](ox::StringView) {
|
||||
const auto path = "/file1";
|
||||
ox::PathIterator it(path, ox_strlen(path));
|
||||
oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext");
|
||||
@ -143,7 +143,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"Ptr::subPtr",
|
||||
[](std::string_view) {
|
||||
[](ox::StringView) {
|
||||
constexpr auto buffLen = 5000;
|
||||
ox::ptrarith::Ptr<uint8_t, uint32_t> p(ox_alloca(buffLen), buffLen, 500, 500);
|
||||
oxAssert(p.valid(), "Ptr::subPtr: Ptr p is invalid.");
|
||||
@ -155,7 +155,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"NodeBuffer::insert",
|
||||
[](std::string_view) {
|
||||
[](ox::StringView) {
|
||||
constexpr auto buffLen = 5000;
|
||||
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||
oxAssert(list->malloc(50).value.valid(), "NodeBuffer::insert: malloc 1 failed");
|
||||
@ -168,7 +168,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"FileStore::readWrite",
|
||||
[](std::string_view) {
|
||||
[](ox::StringView) {
|
||||
constexpr auto buffLen = 5000;
|
||||
constexpr auto str1 = "Hello, World!";
|
||||
constexpr auto str1Len = ox_strlen(str1) + 1;
|
||||
@ -189,7 +189,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"Directory",
|
||||
[](std::string_view) {
|
||||
[](ox::StringView) {
|
||||
ox::Vector<uint8_t> fsBuff(5000);
|
||||
oxAssert(ox::FileStore32::format(fsBuff.data(), fsBuff.size()), "FS format failed");
|
||||
ox::FileStore32 fileStore(fsBuff.data(), fsBuff.size());
|
||||
@ -216,7 +216,7 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
},
|
||||
{
|
||||
"FileSystem",
|
||||
[](std::string_view) {
|
||||
[](ox::StringView) {
|
||||
ox::Vector<uint8_t> fsBuff(5000);
|
||||
oxTrace("ox.fs.test.FileSystem") << "format";
|
||||
oxAssert(ox::FileSystem32::format(fsBuff.data(), fsBuff.size()), "FileSystem format failed");
|
||||
@ -237,16 +237,15 @@ const std::map<std::string_view, std::function<ox::Error(std::string_view)>> tes
|
||||
};
|
||||
|
||||
int main(int argc, const char **args) {
|
||||
int retval = -1;
|
||||
if (argc > 1) {
|
||||
std::string_view testName = args[1];
|
||||
std::string_view testArg;
|
||||
if (args[2]) {
|
||||
testArg = args[2];
|
||||
}
|
||||
if (tests.find(testName) != tests.end()) {
|
||||
retval = static_cast<int>(tests.at(testName)(testArg));
|
||||
}
|
||||
if (argc < 3) {
|
||||
oxError("Must specify test to run and test argument");
|
||||
}
|
||||
return retval;
|
||||
ox::StringView const testName = args[1];
|
||||
ox::StringView const testArg = args[2] ? args[2] : nullptr;
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
oxAssert(func->second(testArg), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
2
deps/ox/src/ox/fs/tool.cpp
vendored
2
deps/ox/src/ox/fs/tool.cpp
vendored
@ -67,7 +67,7 @@ static ox::Error run(int argc, const char **argv) noexcept {
|
||||
return OxError(1);
|
||||
}
|
||||
const auto fsPath = argv[1];
|
||||
ox::String subCmd = argv[2];
|
||||
ox::String subCmd(argv[2]);
|
||||
oxRequire(fs, loadFs(fsPath));
|
||||
if (subCmd == "ls") {
|
||||
return runLs(fs.get(), argc - 2, argv + 2);
|
||||
|
7
deps/ox/src/ox/mc/intops.hpp
vendored
7
deps/ox/src/ox/mc/intops.hpp
vendored
@ -64,13 +64,14 @@ struct McInt {
|
||||
|
||||
template<typename I>
|
||||
[[nodiscard]]
|
||||
constexpr McInt encodeInteger(I input) noexcept {
|
||||
constexpr McInt encodeInteger(I pInput) noexcept {
|
||||
auto const input = ox::ResizedInt_t<I, 64>{pInput};
|
||||
McInt out;
|
||||
const auto inputNegative = is_signed_v<I> && input < 0;
|
||||
// move input to uint64_t to allow consistent bit manipulation, and to avoid
|
||||
// overflow concerns
|
||||
uint64_t val = 0;
|
||||
ox_memcpy(&val, &input, sizeof(I));
|
||||
ox_memcpy(&val, &input, sizeof(input));
|
||||
if (val) {
|
||||
// bits needed to represent number factoring in space possibly
|
||||
// needed for signed bit
|
||||
@ -93,7 +94,7 @@ constexpr McInt encodeInteger(I input) noexcept {
|
||||
}
|
||||
if (bytes == 9) {
|
||||
out.data[0] = bytesIndicator;
|
||||
ox_memcpy(&out.data[1], &leVal, sizeof(I));
|
||||
ox_memcpy(&out.data[1], &leVal, 8);
|
||||
if (inputNegative) {
|
||||
out.data[1] |= 0b1000'0000;
|
||||
}
|
||||
|
64
deps/ox/src/ox/mc/read.hpp
vendored
64
deps/ox/src/ox/mc/read.hpp
vendored
@ -15,6 +15,7 @@
|
||||
#include <ox/model/types.hpp>
|
||||
#include <ox/std/buffer.hpp>
|
||||
#include <ox/std/byteswap.hpp>
|
||||
#include <ox/std/optional.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/trace.hpp>
|
||||
#include <ox/std/vector.hpp>
|
||||
@ -27,21 +28,19 @@
|
||||
namespace ox {
|
||||
|
||||
template<Reader_c Reader>
|
||||
class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<Reader>> {
|
||||
class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<Reader>, ox::OpType::Read> {
|
||||
|
||||
private:
|
||||
FieldBitmapReader<Reader> m_fieldPresence;
|
||||
std::size_t m_fields = 0;
|
||||
std::size_t m_field = 0;
|
||||
int m_unionIdx = -1;
|
||||
ox::Optional<int> m_unionIdx;
|
||||
Reader &m_reader;
|
||||
MetalClawReaderTemplate<Reader> *m_parent = nullptr;
|
||||
|
||||
public:
|
||||
explicit constexpr MetalClawReaderTemplate(
|
||||
Reader &reader,
|
||||
int unionIdx = -1,
|
||||
MetalClawReaderTemplate<Reader> *parent = nullptr) noexcept;
|
||||
ox::Optional<int> const&unionIdx = {}) noexcept;
|
||||
|
||||
constexpr ~MetalClawReaderTemplate() noexcept;
|
||||
|
||||
@ -108,7 +107,7 @@ class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<R
|
||||
* Returns a MetalClawReader to parse a child object.
|
||||
*/
|
||||
[[nodiscard]]
|
||||
constexpr MetalClawReaderTemplate<Reader> child(const char *name, int unionIdx = -1) noexcept;
|
||||
constexpr MetalClawReaderTemplate<Reader> child(const char *name, ox::Optional<int> unionIdx = {}) noexcept;
|
||||
|
||||
/**
|
||||
* Indicates whether or not the next field to be read is present.
|
||||
@ -127,11 +126,6 @@ class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<R
|
||||
|
||||
constexpr void nextField() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return OpType::Read;
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename I>
|
||||
constexpr Error readInteger(I *val) noexcept;
|
||||
@ -141,12 +135,10 @@ class MetalClawReaderTemplate: public ModelHandlerBase<MetalClawReaderTemplate<R
|
||||
template<Reader_c Reader>
|
||||
constexpr MetalClawReaderTemplate<Reader>::MetalClawReaderTemplate(
|
||||
Reader &reader,
|
||||
int unionIdx,
|
||||
MetalClawReaderTemplate *parent) noexcept:
|
||||
ox::Optional<int> const&unionIdx) noexcept:
|
||||
m_fieldPresence(reader),
|
||||
m_unionIdx(unionIdx),
|
||||
m_reader(reader),
|
||||
m_parent(parent) {
|
||||
m_reader(reader) {
|
||||
}
|
||||
|
||||
template<Reader_c Reader>
|
||||
@ -199,7 +191,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, uint64_t *va
|
||||
|
||||
template<Reader_c Reader>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, bool *val) noexcept {
|
||||
if (m_unionIdx == -1 || 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));
|
||||
*val = result.value;
|
||||
oxReturnError(result);
|
||||
@ -211,7 +203,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, bool *val) n
|
||||
// array handler
|
||||
template<Reader_c Reader>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, auto *val, std::size_t valLen) noexcept {
|
||||
if (m_unionIdx == -1 || 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))) {
|
||||
// read the length
|
||||
std::size_t bytesRead = 0;
|
||||
@ -237,7 +229,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, auto *v
|
||||
template<Reader_c Reader>
|
||||
template<typename T>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, HashMap<String, T> *val) noexcept {
|
||||
if (m_unionIdx == -1 || 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))) {
|
||||
// read the length
|
||||
oxRequire(g, m_reader.tellg());
|
||||
@ -269,19 +261,19 @@ template<Reader_c Reader>
|
||||
template<typename T>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, T *val) noexcept {
|
||||
if constexpr(isVector_v<T>) {
|
||||
if (m_unionIdx == -1 || 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
|
||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||
oxRequire(len, arrayLength(name, false));
|
||||
val->resize(len);
|
||||
oxReturnError(ox::resizeVector(*val, len));
|
||||
return field(name, val->data(), val->size());
|
||||
}
|
||||
oxReturnError(ox::resizeVector(*val, 0));
|
||||
}
|
||||
val->resize(0);
|
||||
++m_field;
|
||||
return {};
|
||||
} else if constexpr(isArray_v<T>) {
|
||||
if (m_unionIdx == -1 || 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
|
||||
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
|
||||
oxRequire(len, arrayLength(name, false));
|
||||
@ -294,7 +286,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, T *val)
|
||||
++m_field;
|
||||
return {};
|
||||
} else {
|
||||
if ((m_unionIdx == -1 || 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))) {
|
||||
auto reader = child("");
|
||||
oxReturnError(model(reader.interface(), val));
|
||||
@ -308,20 +300,20 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, T *val)
|
||||
template<Reader_c Reader>
|
||||
template<typename U, bool force>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, UnionView<U, force> val) noexcept {
|
||||
if ((m_unionIdx == -1 || 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))) {
|
||||
auto reader = child("", val.idx());
|
||||
auto reader = child("", ox::Optional<int>(ox::in_place, val.idx()));
|
||||
oxReturnError(model(reader.interface(), val.get()));
|
||||
}
|
||||
}
|
||||
++m_field;
|
||||
return OxError(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<Reader_c Reader>
|
||||
template<std::size_t SmallStringSize>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, BasicString<SmallStringSize> *val) noexcept {
|
||||
if (m_unionIdx == -1 || 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))) {
|
||||
// read the length
|
||||
std::size_t bytesRead = 0;
|
||||
@ -387,7 +379,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
|
||||
|
||||
template<Reader_c Reader>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char **val, std::size_t buffLen) noexcept {
|
||||
if (m_unionIdx == -1 || 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))) {
|
||||
// read the length
|
||||
std::size_t bytesRead = 0;
|
||||
@ -415,7 +407,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
|
||||
|
||||
template<Reader_c Reader>
|
||||
constexpr Result<ArrayLength> MetalClawReaderTemplate<Reader>::arrayLength(const char*, bool pass) noexcept {
|
||||
if (m_unionIdx == -1 || 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))) {
|
||||
// read the length
|
||||
std::size_t bytesRead = 0;
|
||||
@ -432,7 +424,7 @@ constexpr Result<ArrayLength> MetalClawReaderTemplate<Reader>::arrayLength(const
|
||||
|
||||
template<Reader_c Reader>
|
||||
constexpr Result<StringLength> MetalClawReaderTemplate<Reader>::stringLength(const char*) noexcept {
|
||||
if (m_unionIdx == -1 || 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))) {
|
||||
// read the length
|
||||
std::size_t bytesRead = 0;
|
||||
@ -447,7 +439,7 @@ constexpr Result<StringLength> MetalClawReaderTemplate<Reader>::stringLength(con
|
||||
template<Reader_c Reader>
|
||||
template<typename I>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::readInteger(I *val) noexcept {
|
||||
if (m_unionIdx == -1 || 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))) {
|
||||
std::size_t bytesRead = 0;
|
||||
auto const result = mc::decodeInteger<I>(m_reader, &bytesRead);
|
||||
@ -464,7 +456,7 @@ constexpr Error MetalClawReaderTemplate<Reader>::readInteger(I *val) noexcept {
|
||||
template<Reader_c Reader>
|
||||
template<typename T, typename CB>
|
||||
constexpr Error MetalClawReaderTemplate<Reader>::field(const char*, CB cb) noexcept {
|
||||
if (m_unionIdx == -1 || 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))) {
|
||||
// read the length
|
||||
std::size_t bytesRead = 0;
|
||||
@ -496,8 +488,10 @@ constexpr ox::Error MetalClawReaderTemplate<Reader>::setTypeInfo(
|
||||
}
|
||||
|
||||
template<Reader_c Reader>
|
||||
constexpr MetalClawReaderTemplate<Reader> MetalClawReaderTemplate<Reader>::child(const char*, int unionIdx) noexcept {
|
||||
return MetalClawReaderTemplate<Reader>(m_reader, unionIdx, this);
|
||||
constexpr MetalClawReaderTemplate<Reader> MetalClawReaderTemplate<Reader>::child(
|
||||
const char*,
|
||||
ox::Optional<int> unionIdx) noexcept {
|
||||
return MetalClawReaderTemplate<Reader>(m_reader, unionIdx);
|
||||
}
|
||||
|
||||
template<Reader_c Reader>
|
||||
@ -533,7 +527,7 @@ template<typename T>
|
||||
Error readMC(const char *buff, std::size_t buffLen, T *val) noexcept {
|
||||
BufferReader br(buff, buffLen);
|
||||
MetalClawReader reader(br);
|
||||
ModelHandlerInterface handler(&reader);
|
||||
ModelHandlerInterface<MetalClawReader, ox::OpType::Read> handler(&reader);
|
||||
return model(&handler, val);
|
||||
}
|
||||
|
||||
|
22
deps/ox/src/ox/mc/test/tests.cpp
vendored
22
deps/ox/src/ox/mc/test/tests.cpp
vendored
@ -45,7 +45,7 @@ struct TestStruct {
|
||||
int32_t Int8 = 0;
|
||||
int unionIdx = 1;
|
||||
TestUnion Union;
|
||||
ox::String String = "";
|
||||
ox::String String;
|
||||
ox::BString<32> BString = "";
|
||||
uint32_t List[4] = {0, 0, 0, 0};
|
||||
ox::Vector<uint32_t> Vector = {1, 2, 3, 4, 5};
|
||||
@ -105,7 +105,7 @@ constexpr ox::Error model(T *io, ox::CommonPtrWith<TestStruct> auto *obj) noexce
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
std::map<ox::String, ox::Error(*)()> tests = {
|
||||
std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
{
|
||||
{
|
||||
"MetalClawWriter",
|
||||
@ -267,6 +267,9 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
||||
return OxError(0);
|
||||
};
|
||||
oxAssert(check(uint32_t(14)), "Decode of 14 failed.");
|
||||
oxAssert(check(int8_t(-1)), "Decode of -1 failed.");
|
||||
oxAssert(check(int16_t(-1)), "Decode of -1 failed.");
|
||||
oxAssert(check(int32_t(-1)), "Decode of -1 failed.");
|
||||
oxAssert(check(int64_t(-1)), "Decode of -1 failed.");
|
||||
oxAssert(check(int64_t(-2)), "Decode of -2 failed.");
|
||||
oxAssert(check(int64_t(-127)), "Decode of -127 failed.");
|
||||
@ -460,11 +463,14 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
||||
};
|
||||
|
||||
int main(int argc, const char **args) {
|
||||
if (argc > 0) {
|
||||
auto testName = args[1];
|
||||
if (tests.find(testName) != tests.end()) {
|
||||
oxAssert(tests[testName](), "Test failed...");
|
||||
}
|
||||
if (argc < 2) {
|
||||
oxError("Must specify test to run");
|
||||
}
|
||||
return 0;
|
||||
auto const testName = args[1];
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
oxAssert(func->second(), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
133
deps/ox/src/ox/mc/write.hpp
vendored
133
deps/ox/src/ox/mc/write.hpp
vendored
@ -16,6 +16,7 @@
|
||||
#include <ox/std/buffer.hpp>
|
||||
#include <ox/std/byteswap.hpp>
|
||||
#include <ox/std/hashmap.hpp>
|
||||
#include <ox/std/optional.hpp>
|
||||
#include <ox/std/string.hpp>
|
||||
#include <ox/std/types.hpp>
|
||||
#include <ox/std/units.hpp>
|
||||
@ -34,48 +35,39 @@ class MetalClawWriter {
|
||||
ox::Vector<uint8_t, 16> m_presenceMapBuff{};
|
||||
FieldBitmap m_fieldPresence;
|
||||
int m_field = 0;
|
||||
int m_unionIdx = -1;
|
||||
ox::Optional<int> m_unionIdx;
|
||||
std::size_t m_writerBeginP{};
|
||||
Writer &m_writer;
|
||||
|
||||
public:
|
||||
constexpr explicit MetalClawWriter(Writer &writer, int unionIdx = -1) noexcept;
|
||||
constexpr explicit MetalClawWriter(Writer &writer, ox::Optional<int> const&unionIdx = {}) noexcept;
|
||||
|
||||
constexpr ~MetalClawWriter() noexcept = default;
|
||||
|
||||
constexpr Error field(const char*, CommonPtrWith<int8_t> auto *val) noexcept;
|
||||
constexpr Error field(const char*, CommonPtrWith<int16_t> auto *val) noexcept;
|
||||
constexpr Error field(const char*, CommonPtrWith<int32_t> auto *val) noexcept;
|
||||
constexpr Error field(const char*, CommonPtrWith<int64_t> auto *val) noexcept;
|
||||
constexpr Error field(const char*, const int8_t *val) noexcept;
|
||||
constexpr Error field(const char*, const int16_t *val) noexcept;
|
||||
constexpr Error field(const char*, const int32_t *val) noexcept;
|
||||
constexpr Error field(const char*, const int64_t *val) noexcept;
|
||||
|
||||
constexpr Error field(const char*, CommonPtrWith<uint8_t> auto *val) noexcept;
|
||||
constexpr Error field(const char*, CommonPtrWith<uint16_t> auto *val) noexcept;
|
||||
constexpr Error field(const char*, CommonPtrWith<uint32_t> auto *val) noexcept;
|
||||
constexpr Error field(const char*, CommonPtrWith<uint64_t> auto *val) noexcept;
|
||||
constexpr Error field(const char*, const uint8_t *val) noexcept;
|
||||
constexpr Error field(const char*, const uint16_t *val) noexcept;
|
||||
constexpr Error field(const char*, const uint32_t *val) noexcept;
|
||||
constexpr Error field(const char*, const uint64_t *val) noexcept;
|
||||
|
||||
constexpr Error field(const char*, CommonPtrWith<bool> auto *val) noexcept;
|
||||
constexpr Error field(const char*, const bool *val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
constexpr Error field(const char*, T *val, std::size_t len) noexcept;
|
||||
constexpr Error field(const char*, const T *val, std::size_t len) noexcept;
|
||||
|
||||
template<typename T>
|
||||
constexpr Error field(const char *name, const HashMap<String, T> *val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
constexpr Error field(const char*, HashMap<String, T> *val) noexcept;
|
||||
|
||||
template<std::size_t SmallStringSize>
|
||||
constexpr Error field(const char*, const BasicString<SmallStringSize> *val) noexcept;
|
||||
|
||||
template<std::size_t L>
|
||||
constexpr Error field(const char*, const BString<L> *val) noexcept;
|
||||
|
||||
template<std::size_t SmallStringSize>
|
||||
constexpr Error field(const char*, BasicString<SmallStringSize> *val) noexcept;
|
||||
|
||||
template<std::size_t L>
|
||||
constexpr Error field(const char*, BString<L> *val) noexcept;
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char *const*val, std::size_t buffLen) noexcept;
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char **val) noexcept;
|
||||
@ -84,20 +76,8 @@ class MetalClawWriter {
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char *val, std::size_t len) noexcept;
|
||||
|
||||
constexpr Error fieldCString(const char *name, char **val, std::size_t buffLen) noexcept {
|
||||
return fieldCString(name, const_cast<const char**>(val), buffLen);
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, char **val) noexcept {
|
||||
return fieldCString(name, const_cast<const char**>(val));
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, char *val, std::size_t buffLen) noexcept {
|
||||
return fieldCString(name, const_cast<const char*>(val), buffLen);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Error field(const char*, T *val) noexcept;
|
||||
constexpr Error field(const char*, const T *val) noexcept;
|
||||
|
||||
template<typename U, bool force = false>
|
||||
constexpr Error field(const char*, UnionView<U, force> val) noexcept;
|
||||
@ -135,7 +115,7 @@ class MetalClawWriter {
|
||||
private:
|
||||
constexpr Error appendInteger(Integer_c auto val) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (val && (m_unionIdx == -1 || m_unionIdx == m_field)) {
|
||||
if (val && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||
auto mi = mc::encodeInteger(val);
|
||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(mi.data), mi.length));
|
||||
fieldSet = true;
|
||||
@ -151,7 +131,7 @@ extern template class ModelHandlerInterface<MetalClawWriter<BufferWriter>>;
|
||||
extern template class ModelHandlerInterface<MetalClawWriter<CharBuffWriter>>;
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr MetalClawWriter<Writer>::MetalClawWriter(Writer &writer, int unionIdx) noexcept:
|
||||
constexpr MetalClawWriter<Writer>::MetalClawWriter(Writer &writer, ox::Optional<int> const&unionIdx) noexcept:
|
||||
m_fieldPresence(m_presenceMapBuff.data(), m_presenceMapBuff.size()),
|
||||
m_unionIdx(unionIdx),
|
||||
m_writerBeginP(writer.tellp()),
|
||||
@ -159,48 +139,48 @@ constexpr MetalClawWriter<Writer>::MetalClawWriter(Writer &writer, int unionIdx)
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<int8_t> auto *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const int8_t *val) noexcept {
|
||||
return appendInteger(*val);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<int16_t> auto *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const int16_t *val) noexcept {
|
||||
return appendInteger(*val);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<int32_t> auto *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const int32_t *val) noexcept {
|
||||
return appendInteger(*val);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<int64_t> auto *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const int64_t *val) noexcept {
|
||||
return appendInteger(*val);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<uint8_t> auto *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const uint8_t *val) noexcept {
|
||||
return appendInteger(*val);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<uint16_t> auto *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const uint16_t *val) noexcept {
|
||||
return appendInteger(*val);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<uint32_t> auto *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const uint32_t *val) noexcept {
|
||||
return appendInteger(*val);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<uint64_t> auto *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const uint64_t *val) noexcept {
|
||||
return appendInteger(*val);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, CommonPtrWith<bool> auto *val) noexcept {
|
||||
if (m_unionIdx == -1 || m_unionIdx == m_field) {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const bool *val) noexcept {
|
||||
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), *val));
|
||||
}
|
||||
++m_field;
|
||||
@ -211,7 +191,7 @@ template<Writer_c Writer>
|
||||
template<std::size_t SmallStringSize>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const BasicString<SmallStringSize> *val) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (val->len() && (m_unionIdx == -1 || m_unionIdx == m_field)) {
|
||||
if (val->len() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||
// write the length
|
||||
const auto strLen = mc::encodeInteger(val->len());
|
||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLen.data), strLen.length));
|
||||
@ -230,22 +210,10 @@ constexpr Error MetalClawWriter<Writer>::field(const char *name, const BString<L
|
||||
return fieldCString(name, val->data(), val->cap());
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
template<std::size_t SmallStringSize>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char *name, BasicString<SmallStringSize> *val) noexcept {
|
||||
return field(name, const_cast<const BasicString<SmallStringSize>*>(val));
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
template<std::size_t L>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char *name, BString<L> *val) noexcept {
|
||||
return fieldCString(name, val->data(), val->cap());
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (m_unionIdx == -1 || m_unionIdx == m_field) {
|
||||
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
|
||||
const auto strLen = *val ? ox_strlen(*val) : 0;
|
||||
// write the length
|
||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||
@ -272,7 +240,7 @@ constexpr Error MetalClawWriter<Writer>::fieldCString(const char *name, const ch
|
||||
template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *val, std::size_t strLen) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (strLen && (m_unionIdx == -1 || m_unionIdx == m_field)) {
|
||||
if (strLen && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||
// write the length
|
||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data), strLenBuff.length));
|
||||
@ -287,21 +255,22 @@ constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *v
|
||||
|
||||
template<Writer_c Writer>
|
||||
template<typename T>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, T *val) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const T *val) noexcept {
|
||||
if constexpr(isVector_v<T> || isArray_v<T>) {
|
||||
return field(nullptr, val->data(), val->size());
|
||||
} else {
|
||||
bool fieldSet = false;
|
||||
if (val && (m_unionIdx == -1 || m_unionIdx == m_field)) {
|
||||
if (val && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||
auto const writeIdx = m_writer.tellp();
|
||||
MetalClawWriter<Writer> writer(m_writer);
|
||||
ModelHandlerInterface<MetalClawWriter<Writer>> handler{&writer};
|
||||
oxReturnError(model(&handler, val));
|
||||
oxReturnError(writer.finalize());
|
||||
fieldSet = true;
|
||||
fieldSet = writeIdx != m_writer.tellp();
|
||||
}
|
||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||
++m_field;
|
||||
return OxError(0);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,35 +278,37 @@ template<Writer_c Writer>
|
||||
template<typename U, bool force>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, UnionView<U, force> val) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (val.get() && (m_unionIdx == -1 || m_unionIdx == m_field)) {
|
||||
MetalClawWriter<Writer> writer(m_writer, val.idx());
|
||||
if (val.get() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||
auto const writeIdx = m_writer.tellp();
|
||||
MetalClawWriter<Writer> writer(m_writer, ox::Optional<int>(ox::in_place, val.idx()));
|
||||
ModelHandlerInterface handler{&writer};
|
||||
oxReturnError(model(&handler, val.get()));
|
||||
oxReturnError(writer.finalize());
|
||||
fieldSet = true;
|
||||
fieldSet = writeIdx != m_writer.tellp();
|
||||
}
|
||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||
++m_field;
|
||||
return OxError(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
template<typename T>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, T *val, std::size_t len) noexcept {
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char*, const T *val, std::size_t len) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (len && (m_unionIdx == -1 || m_unionIdx == m_field)) {
|
||||
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||
// write the length
|
||||
const auto arrLen = mc::encodeInteger(len);
|
||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(arrLen.data), arrLen.length));
|
||||
auto const writeIdx = m_writer.tellp();
|
||||
MetalClawWriter<Writer> writer(m_writer);
|
||||
ModelHandlerInterface handler{&writer};
|
||||
oxReturnError(handler.template setTypeInfo<T>("List", 0, {}, static_cast<std::size_t>(len)));
|
||||
// write the array
|
||||
for (std::size_t i = 0; i < len; i++) {
|
||||
for (std::size_t i = 0; i < len; ++i) {
|
||||
oxReturnError(handler.field("", &val[i]));
|
||||
}
|
||||
oxReturnError(writer.finalize());
|
||||
fieldSet = true;
|
||||
fieldSet = writeIdx != m_writer.tellp();
|
||||
}
|
||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||
++m_field;
|
||||
@ -350,7 +321,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const HashMap<String
|
||||
const auto &keys = val->keys();
|
||||
const auto len = keys.size();
|
||||
bool fieldSet = false;
|
||||
if (len && (m_unionIdx == -1 || m_unionIdx == m_field)) {
|
||||
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||
// write the length
|
||||
const auto arrLen = mc::encodeInteger(len);
|
||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(arrLen.data), arrLen.length));
|
||||
@ -361,7 +332,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const HashMap<String
|
||||
oxReturnError(handler.setTypeInfo("Map", 0, {}, len * 2));
|
||||
// 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 {
|
||||
const auto keyLen = ox_strlen(key);
|
||||
const auto keyLen = key.len();
|
||||
auto wkey = ox_malloca(keyLen + 1, char, 0);
|
||||
memcpy(wkey.get(), key.c_str(), keyLen + 1);
|
||||
oxReturnError(handler.fieldCString("", wkey.get(), keyLen));
|
||||
@ -369,7 +340,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const HashMap<String
|
||||
return handler.field("", value);
|
||||
};
|
||||
// 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];
|
||||
oxReturnError(loopBody(handler, key, *val));
|
||||
}
|
||||
@ -381,12 +352,6 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const HashMap<String
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
template<typename T>
|
||||
constexpr Error MetalClawWriter<Writer>::field(const char *name, HashMap<String, T> *val) noexcept {
|
||||
return field(name, const_cast<const HashMap<String, T>*>(val));
|
||||
}
|
||||
|
||||
template<Writer_c Writer>
|
||||
template<typename T>
|
||||
constexpr ox::Error MetalClawWriter<Writer>::setTypeInfo(
|
||||
@ -421,7 +386,7 @@ Result<Buffer> writeMC(Writer_c auto &writer, const auto &val) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<Buffer> writeMC(const auto &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);
|
||||
BufferWriter bw(&buff, 0);
|
||||
oxReturnError(writeMC(bw, val));
|
||||
@ -429,7 +394,7 @@ Result<Buffer> writeMC(const auto &val, std::size_t buffReserveSz = 2 * units::K
|
||||
return buff;
|
||||
}
|
||||
|
||||
Error writeMC(char *buff, std::size_t buffLen, const auto &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);
|
||||
oxReturnError(writeMC(bw, val));
|
||||
if (sizeOut) {
|
||||
|
14
deps/ox/src/ox/model/descwrite.hpp
vendored
14
deps/ox/src/ox/model/descwrite.hpp
vendored
@ -209,7 +209,7 @@ constexpr Error TypeDescWriter::field(CRStringView name, UnionView<T, force> val
|
||||
if (m_type) {
|
||||
const auto t = type(val);
|
||||
oxAssert(t != nullptr, "field(const char *name, T val): Type not found or generated");
|
||||
m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, t->typeName);
|
||||
m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, ox::String(t->typeName));
|
||||
return OxError(0);
|
||||
}
|
||||
return OxError(1);
|
||||
@ -219,9 +219,11 @@ template<typename T>
|
||||
constexpr Error TypeDescWriter::field(CRStringView name, const T *val) noexcept {
|
||||
if (m_type) {
|
||||
if constexpr(isVector_v<T> || isArray_v<T>) {
|
||||
return field(name, val->data(), 0, detail::buildSubscriptStack(val));
|
||||
typename T::value_type *data = nullptr;
|
||||
return field(name, data, 0, detail::buildSubscriptStack(val));
|
||||
} else if constexpr(isSmartPtr_v<T>) {
|
||||
return field(name, val->get(), 0, detail::buildSubscriptStack(val));
|
||||
typename T::value_type *data = nullptr;
|
||||
return field(name, data, 0, detail::buildSubscriptStack(val));
|
||||
} else if constexpr(is_pointer_v<T>) {
|
||||
return field(name, val, 0, detail::buildSubscriptStack(val));
|
||||
} else {
|
||||
@ -238,7 +240,7 @@ template<typename ...Args>
|
||||
constexpr Error TypeDescWriter::fieldCString(CRStringView name, Args&&...) noexcept {
|
||||
constexpr auto s = "";
|
||||
const auto t = type(s);
|
||||
m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, t->typeName);
|
||||
m_type->fieldList.emplace_back(t, String(name), 0, SubscriptStack{}, ox::String(t->typeName));
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -357,7 +359,7 @@ constexpr const DescriptorType *TypeDescWriter::getType(CRStringView tn, int typ
|
||||
template<typename T>
|
||||
constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore) noexcept {
|
||||
TypeDescWriter writer(typeStore);
|
||||
ModelHandlerInterface handler(&writer);
|
||||
ModelHandlerInterface<TypeDescWriter, ox::OpType::Reflect> handler(&writer);
|
||||
if (std::is_constant_evaluated()) {
|
||||
std::allocator<T> a;
|
||||
T *t = a.allocate(1);
|
||||
@ -373,7 +375,7 @@ constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore) noexcept {
|
||||
template<typename T>
|
||||
constexpr Result<DescriptorType*> buildTypeDef(TypeStore *typeStore, T *val) noexcept {
|
||||
TypeDescWriter writer(typeStore);
|
||||
ModelHandlerInterface handler(&writer);
|
||||
ModelHandlerInterface<TypeDescWriter, ox::OpType::Reflect> handler(&writer);
|
||||
oxReturnError(model(&handler, val));
|
||||
return writer.definition();
|
||||
}
|
||||
|
58
deps/ox/src/ox/model/modelhandleradaptor.hpp
vendored
58
deps/ox/src/ox/model/modelhandleradaptor.hpp
vendored
@ -14,7 +14,7 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
template<typename Handler>
|
||||
template<typename Handler, OpType opType_v = Handler::opType()>
|
||||
class ModelHandlerInterface {
|
||||
private:
|
||||
Handler *m_handler = nullptr;
|
||||
@ -46,28 +46,47 @@ class ModelHandlerInterface {
|
||||
}
|
||||
|
||||
template<std::size_t len>
|
||||
constexpr Error fieldCString(const char *name, const char val[len]) noexcept requires(Handler::opType() != OpType::Read) {
|
||||
return m_handler->fieldCString(name, &val[0], len);
|
||||
constexpr Error fieldCString(const char *name, const char val[len]) noexcept requires(opType_v != OpType::Read) {
|
||||
if constexpr(opType_v != OpType::Read) {
|
||||
return m_handler->fieldCString(name, &val[0], len);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, char **val) noexcept {
|
||||
return m_handler->fieldCString(name, val);
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char *const*val) noexcept requires(Handler::opType() != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val);
|
||||
constexpr Error fieldCString(const char *name, const char *const*val) noexcept requires(opType_v != OpType::Read) {
|
||||
// this check looks pointless, but it's to address a Clang bug
|
||||
if constexpr(opType_v != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char **val) noexcept requires(Handler::opType() != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val);
|
||||
constexpr Error fieldCString(const char *name, const char **val) noexcept requires(opType_v != OpType::Read) {
|
||||
// this check looks pointless, but it's to address a Clang bug
|
||||
if constexpr(opType_v != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, char **val, std::size_t buffLen) noexcept {
|
||||
return m_handler->fieldCString(name, val, buffLen);
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, const char **val, std::size_t buffLen) noexcept requires(Handler::opType() != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val, buffLen);
|
||||
constexpr Error fieldCString(const char *name, const char **val, std::size_t buffLen) noexcept requires(opType_v != OpType::Read) {
|
||||
// this check looks pointless, but it's to address a Clang bug
|
||||
if constexpr(opType_v != OpType::Read) {
|
||||
return m_handler->fieldCString(name, val, buffLen);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
constexpr Error fieldCString(const char *name, char *val, std::size_t buffLen) noexcept {
|
||||
@ -103,7 +122,7 @@ class ModelHandlerInterface {
|
||||
case ModelValue::Type::Union:
|
||||
{
|
||||
auto &u = v->template get<ModelUnion>();
|
||||
if constexpr(Handler::opType() == OpType::Read) {
|
||||
if constexpr(opType_v == OpType::Read) {
|
||||
u.setActiveField(m_handler->whichFieldPresent(name, u));
|
||||
return m_handler->field(name, UnionView<ModelUnion, true>(&u, u.unionIdx()));
|
||||
} else {
|
||||
@ -177,13 +196,12 @@ class ModelHandlerInterface {
|
||||
constexpr auto handler() noexcept {
|
||||
return m_handler;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename Handler>
|
||||
template<typename Handler, ox::OpType opType_v = Handler::opType()>
|
||||
class ModelHandlerBase {
|
||||
private:
|
||||
ModelHandlerInterface<Handler> m_interface;
|
||||
ModelHandlerInterface<Handler, opType_v> m_interface;
|
||||
public:
|
||||
constexpr ModelHandlerBase() noexcept: m_interface(static_cast<Handler*>(this)) {}
|
||||
constexpr ModelHandlerBase(const ModelHandlerBase&) noexcept: m_interface(static_cast<Handler*>(this)) {}
|
||||
@ -192,6 +210,20 @@ class ModelHandlerBase {
|
||||
constexpr auto interface() noexcept {
|
||||
return &m_interface;
|
||||
}
|
||||
[[nodiscard]]
|
||||
static constexpr ox::OpType opType() noexcept {
|
||||
return opType_v;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
constexpr ox::Error resizeVector(auto &vec, size_t sz) {
|
||||
if constexpr(ox::is_same_v<decltype(vec.resize(0)), ox::Error>) {
|
||||
return vec.resize(sz);
|
||||
} else {
|
||||
vec.resize(sz);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
35
deps/ox/src/ox/model/modelvalue.hpp
vendored
35
deps/ox/src/ox/model/modelvalue.hpp
vendored
@ -144,8 +144,6 @@ class ModelValue {
|
||||
|
||||
constexpr ModelValue(const ModelValue &other) noexcept;
|
||||
|
||||
constexpr ModelValue(ModelValue &other) noexcept;
|
||||
|
||||
constexpr ModelValue(ModelValue &&other) noexcept;
|
||||
|
||||
template<typename T>
|
||||
@ -204,7 +202,8 @@ class ModelValue {
|
||||
class ModelValueVector {
|
||||
private:
|
||||
Vector<ModelValue> m_vec;
|
||||
ModelValue m_templateValue;
|
||||
const DescriptorType *m_type = nullptr;
|
||||
int m_typeSubscriptLevels = 0;
|
||||
String m_typeName;
|
||||
int m_typeVersion = 0;
|
||||
|
||||
@ -229,14 +228,15 @@ class ModelValueVector {
|
||||
return m_vec.data();
|
||||
}
|
||||
|
||||
constexpr void resize(std::size_t sz) noexcept {
|
||||
constexpr ox::Error resize(std::size_t sz) noexcept {
|
||||
const auto oldSz = m_vec.size();
|
||||
m_vec.resize(sz);
|
||||
if (sz > oldSz) {
|
||||
for (auto i = oldSz; i < sz; ++i) {
|
||||
m_vec[i] = m_templateValue;
|
||||
oxReturnError(m_vec[i].setType(m_type, m_typeSubscriptLevels));
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@ -250,7 +250,9 @@ class ModelValueVector {
|
||||
}
|
||||
|
||||
constexpr Error setType(const DescriptorType *type, int subscriptLevels) noexcept {
|
||||
return m_templateValue.setType(type, subscriptLevels);
|
||||
m_type = type;
|
||||
m_typeSubscriptLevels = subscriptLevels;
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@ -350,7 +352,7 @@ class ModelObject {
|
||||
|
||||
constexpr ModelObject(const ModelObject &other) noexcept {
|
||||
for (const auto &f : other.m_fieldsOrder) {
|
||||
auto &field = m_fieldsOrder.emplace_back(new Field{f->name, f->value});
|
||||
auto &field = m_fieldsOrder.emplace_back(new Field{ox::String(f->name), f->value});
|
||||
m_fields[field->name] = &field->value;
|
||||
}
|
||||
m_type = other.m_type;
|
||||
@ -427,7 +429,7 @@ class ModelObject {
|
||||
return *this;
|
||||
}
|
||||
for (const auto &f : other.m_fieldsOrder) {
|
||||
auto &field = m_fieldsOrder.emplace_back(new Field{f->name, f->value});
|
||||
auto &field = m_fieldsOrder.emplace_back(new Field{ox::String(f->name), f->value});
|
||||
m_fields[field->name] = &field->value;
|
||||
}
|
||||
m_type = other.m_type;
|
||||
@ -450,7 +452,7 @@ class ModelObject {
|
||||
f = val;
|
||||
}
|
||||
|
||||
constexpr Result<const ModelValue*> get(const String &k) const noexcept {
|
||||
constexpr Result<const ModelValue*> get(StringView const&k) const noexcept {
|
||||
if (m_fields.contains(k)) {
|
||||
return *m_fields.at(k).value;
|
||||
}
|
||||
@ -464,7 +466,7 @@ class ModelObject {
|
||||
return {};
|
||||
}
|
||||
|
||||
constexpr auto &operator[](const String &k) noexcept {
|
||||
constexpr auto &operator[](StringView const&k) noexcept {
|
||||
auto [v, err] = m_fields.at(k);
|
||||
if (err) [[unlikely]] {
|
||||
oxPanic(err, ox::sfmt("field {} does not exist in type {}", k, buildTypeId(*m_type)).c_str());
|
||||
@ -528,7 +530,7 @@ class ModelUnion {
|
||||
public:
|
||||
constexpr ModelUnion(const ModelUnion &other) noexcept {
|
||||
for (auto i = 0; const auto &f : other.m_fieldsOrder) {
|
||||
auto &field = m_fieldsOrder.emplace_back(new Field{i, f->name, f->value});
|
||||
auto &field = m_fieldsOrder.emplace_back(new Field{i, ox::String(f->name), f->value});
|
||||
m_fields[field->name] = field.get();
|
||||
++i;
|
||||
}
|
||||
@ -553,7 +555,7 @@ class ModelUnion {
|
||||
return UniquePtr<ModelUnion>(new ModelUnion(other));
|
||||
}
|
||||
|
||||
constexpr auto &operator[](const String &k) noexcept {
|
||||
constexpr auto &operator[](StringView const&k) noexcept {
|
||||
const auto [v, err] = m_fields.at(k);
|
||||
if (err) [[unlikely]] {
|
||||
oxPanic(err, ox::sfmt("field {} does not exist in type {}", k, buildTypeId(*m_type)).c_str());
|
||||
@ -588,7 +590,7 @@ class ModelUnion {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Result<const ModelValue*> get(const String &k) const noexcept {
|
||||
constexpr Result<const ModelValue*> get(StringView const&k) const noexcept {
|
||||
oxRequire(t, m_fields.at(k));
|
||||
return &(*t)->value;
|
||||
}
|
||||
@ -814,9 +816,6 @@ constexpr ModelValue::ModelValue(const ModelValue &other) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr ModelValue::ModelValue(ModelValue &other) noexcept: ModelValue(const_cast<const ModelValue&>(other)) {
|
||||
}
|
||||
|
||||
constexpr ModelValue::ModelValue(ModelValue &&other) noexcept {
|
||||
m_type = other.m_type;
|
||||
switch (m_type) {
|
||||
@ -1094,14 +1093,12 @@ constexpr ModelValueVector::ModelValueVector(const ModelValueVector &other) noex
|
||||
for (auto &v : other.m_vec) {
|
||||
m_vec.emplace_back(v);
|
||||
}
|
||||
m_templateValue = other.m_templateValue;
|
||||
m_typeName = other.m_typeName;
|
||||
m_typeVersion = other.m_typeVersion;
|
||||
}
|
||||
|
||||
constexpr ModelValueVector::ModelValueVector(ModelValueVector &&other) noexcept {
|
||||
m_vec = std::move(other.m_vec);
|
||||
m_templateValue = std::move(other.m_templateValue);
|
||||
m_typeName = std::move(other.m_typeName);
|
||||
m_typeVersion = other.m_typeVersion;
|
||||
}
|
||||
@ -1113,7 +1110,6 @@ constexpr ModelValueVector &ModelValueVector::operator=(const ModelValueVector &
|
||||
for (auto &v : other.m_vec) {
|
||||
m_vec.emplace_back(v);
|
||||
}
|
||||
m_templateValue = other.m_templateValue;
|
||||
m_typeName = other.m_typeName;
|
||||
m_typeVersion = other.m_typeVersion;
|
||||
return *this;
|
||||
@ -1124,7 +1120,6 @@ constexpr ModelValueVector &ModelValueVector::operator=(ModelValueVector &&other
|
||||
return *this;
|
||||
}
|
||||
m_vec = std::move(other.m_vec);
|
||||
m_templateValue = std::move(other.m_templateValue);
|
||||
m_typeName = std::move(other.m_typeName);
|
||||
m_typeVersion = other.m_typeVersion;
|
||||
return *this;
|
||||
|
19
deps/ox/src/ox/model/test/tests.cpp
vendored
19
deps/ox/src/ox/model/test/tests.cpp
vendored
@ -32,7 +32,7 @@ constexpr auto getModelTypeVersion(TestType2*) noexcept {
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::map<ox::String, ox::Error(*)()> tests = {
|
||||
std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
{
|
||||
{
|
||||
"ModelValue",
|
||||
@ -47,6 +47,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
||||
return ox::Error{};
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"getModelTypeName",
|
||||
[] {
|
||||
@ -55,6 +56,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
||||
return ox::Error{};
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"getModelTypeVersion",
|
||||
[] {
|
||||
@ -67,11 +69,14 @@ std::map<ox::String, ox::Error(*)()> tests = {
|
||||
};
|
||||
|
||||
int main(int argc, const char **args) {
|
||||
if (argc > 0) {
|
||||
auto testName = args[1];
|
||||
if (tests.find(testName) != tests.end()) {
|
||||
oxAssert(tests[testName](), "Test failed...");
|
||||
}
|
||||
if (argc < 2) {
|
||||
oxError("Must specify test to run");
|
||||
}
|
||||
return 0;
|
||||
auto const testName = args[1];
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
oxAssert(func->second(), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
2
deps/ox/src/ox/model/typestore.hpp
vendored
2
deps/ox/src/ox/model/typestore.hpp
vendored
@ -58,7 +58,7 @@ class TypeStore {
|
||||
if (!std::is_constant_evaluated()) {
|
||||
oxRequireM(dt, loadDescriptor(typeId));
|
||||
for (auto &f : dt->fieldList) {
|
||||
oxReturnError(this->getLoad(f.typeId).moveTo(&f.type));
|
||||
oxReturnError(this->getLoad(f.typeId).moveTo(f.type));
|
||||
}
|
||||
auto &out = m_cache[typeId];
|
||||
out = std::move(dt);
|
||||
|
2
deps/ox/src/ox/oc/read.cpp
vendored
2
deps/ox/src/ox/oc/read.cpp
vendored
@ -265,7 +265,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t b
|
||||
Error OrganicClawReader::field(const char *key, UUID *val) noexcept {
|
||||
UUIDStr str;
|
||||
oxReturnError(field(key, &str));
|
||||
return UUID::fromString(str).moveTo(val);
|
||||
return UUID::fromString(str).moveTo(*val);
|
||||
}
|
||||
|
||||
Result<std::size_t> OrganicClawReader::arrayLength(const char *key, bool) noexcept {
|
||||
|
4
deps/ox/src/ox/oc/read.hpp
vendored
4
deps/ox/src/ox/oc/read.hpp
vendored
@ -147,7 +147,7 @@ Error OrganicClawReader::field(const char *key, T *val) noexcept {
|
||||
if constexpr(isVector_v<T>) {
|
||||
const auto &srcVal = value(key);
|
||||
const auto srcSize = srcVal.size();
|
||||
val->resize(srcSize);
|
||||
oxReturnError(ox::resizeVector(*val, srcSize));
|
||||
err = field(key, val->data(), val->size());
|
||||
} else if constexpr(isArray_v<T>) {
|
||||
const auto &srcVal = value(key);
|
||||
@ -194,7 +194,7 @@ Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
|
||||
if (targetValid()) {
|
||||
const auto &jv = value(key);
|
||||
if (jv.empty()) {
|
||||
*val = 0;
|
||||
*val = BasicString<L>{};
|
||||
} else if (jv.isString()) {
|
||||
*val = jv.asString().c_str();
|
||||
} else {
|
||||
|
112
deps/ox/src/ox/oc/test/tests.cpp
vendored
112
deps/ox/src/ox/oc/test/tests.cpp
vendored
@ -53,7 +53,7 @@ struct TestStruct {
|
||||
int32_t Int8 = 0;
|
||||
int unionIdx = 1;
|
||||
TestUnion Union;
|
||||
ox::String String = "";
|
||||
ox::String String{""};
|
||||
uint32_t List[4] = {0, 0, 0, 0};
|
||||
ox::HashMap<ox::String, int> Map;
|
||||
TestStructNest EmptyStruct;
|
||||
@ -124,7 +124,7 @@ constexpr TestStruct &TestStruct::operator=(TestStruct &&other) noexcept {
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::map<std::string_view, ox::Error(*)()> tests = {
|
||||
const std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
{
|
||||
{
|
||||
"OrganicClawWriter",
|
||||
@ -189,53 +189,53 @@ const std::map<std::string_view, ox::Error(*)()> tests = {
|
||||
},
|
||||
|
||||
{
|
||||
"OrganicClawModelValue",
|
||||
[] {
|
||||
ox::Buffer dataBuff;
|
||||
TestStruct testIn;
|
||||
testIn.Bool = true;
|
||||
testIn.Int = 42;
|
||||
testIn.String = "Test String 1";
|
||||
testIn.List[0] = 1;
|
||||
testIn.List[1] = 2;
|
||||
testIn.List[2] = 3;
|
||||
testIn.List[3] = 4;
|
||||
testIn.Struct.Bool = false;
|
||||
testIn.Struct.Int = 300;
|
||||
testIn.Struct.String = "Test String 2";
|
||||
testIn.unionIdx = 1;
|
||||
testIn.Union.Int = 93;
|
||||
oxAssert(ox::writeOC(testIn).moveTo(&dataBuff), "Data generation failed");
|
||||
ox::TypeStore typeStore;
|
||||
auto type = ox::buildTypeDef(&typeStore, &testIn);
|
||||
oxAssert(type.error, "Descriptor write failed");
|
||||
ox::ModelObject testOut;
|
||||
oxReturnError(testOut.setType(type.value));
|
||||
oxAssert(ox::readOC(dataBuff.data(), dataBuff.size(), &testOut), "Data read 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("String").unwrap()->get<ox::String>() == testIn.String, "testOut.String failed");
|
||||
auto &testOutStruct = testOut.get("Struct").unwrap()->get<ox::ModelObject>();
|
||||
auto &testOutUnion = testOut.get("Union").unwrap()->get<ox::ModelUnion>();
|
||||
auto &testOutList = testOut.get("List").unwrap()->get<ox::ModelValueVector>();
|
||||
auto testOutStructCopy = testOut.get("Struct").unwrap()->get<ox::ModelObject>();
|
||||
auto testOutUnionCopy = testOut.get("Union").unwrap()->get<ox::ModelUnion>();
|
||||
auto testOutListCopy = testOut.get("List").unwrap()->get<ox::ModelValueVector>();
|
||||
oxAssert(testOutStruct.typeName() == TestStructNest::TypeName, "ModelObject TypeName failed");
|
||||
oxAssert(testOutStruct.typeVersion() == TestStructNest::TypeVersion, "ModelObject TypeVersion failed");
|
||||
oxAssert(testOutStruct.get("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool failed");
|
||||
oxAssert(testOutStruct.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String failed");
|
||||
oxAssert(testOut.get("unionIdx").unwrap()->get<int>() == testIn.unionIdx, "testOut.unionIdx failed");
|
||||
oxAssert(testOutUnion.unionIdx() == testIn.unionIdx, "testOut.Union idx wrong");
|
||||
oxAssert(testOutUnion.get("Int").unwrap()->get<uint32_t>() == testIn.Union.Int, "testOut.Union.Int failed");
|
||||
oxAssert(testOutList[0].get<uint32_t>() == testIn.List[0], "testOut.List[0] failed");
|
||||
oxAssert(testOutList[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] failed");
|
||||
oxAssert(testOutStructCopy.get("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool (copy) failed");
|
||||
oxAssert(testOutStructCopy.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String (copy) failed");
|
||||
oxAssert(testOutListCopy[0].get<uint32_t>() == testIn.List[0], "testOut.Struct.List[0] (copy) failed");
|
||||
oxAssert(testOutListCopy[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] (copy) failed");
|
||||
return OxError(0);
|
||||
}
|
||||
"OrganicClawModelValue",
|
||||
[] {
|
||||
ox::Buffer dataBuff;
|
||||
TestStruct testIn;
|
||||
testIn.Bool = true;
|
||||
testIn.Int = 42;
|
||||
testIn.String = "Test String 1";
|
||||
testIn.List[0] = 1;
|
||||
testIn.List[1] = 2;
|
||||
testIn.List[2] = 3;
|
||||
testIn.List[3] = 4;
|
||||
testIn.Struct.Bool = false;
|
||||
testIn.Struct.Int = 300;
|
||||
testIn.Struct.String = "Test String 2";
|
||||
testIn.unionIdx = 1;
|
||||
testIn.Union.Int = 93;
|
||||
oxAssert(ox::writeOC(testIn).moveTo(dataBuff), "Data generation failed");
|
||||
ox::TypeStore typeStore;
|
||||
auto type = ox::buildTypeDef(&typeStore, &testIn);
|
||||
oxAssert(type.error, "Descriptor write failed");
|
||||
ox::ModelObject testOut;
|
||||
oxReturnError(testOut.setType(type.value));
|
||||
oxAssert(ox::readOC(dataBuff.data(), dataBuff.size(), &testOut), "Data read 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("String").unwrap()->get<ox::String>() == testIn.String, "testOut.String failed");
|
||||
auto &testOutStruct = testOut.get("Struct").unwrap()->get<ox::ModelObject>();
|
||||
auto &testOutUnion = testOut.get("Union").unwrap()->get<ox::ModelUnion>();
|
||||
auto &testOutList = testOut.get("List").unwrap()->get<ox::ModelValueVector>();
|
||||
auto testOutStructCopy = testOut.get("Struct").unwrap()->get<ox::ModelObject>();
|
||||
auto testOutUnionCopy = testOut.get("Union").unwrap()->get<ox::ModelUnion>();
|
||||
auto testOutListCopy = testOut.get("List").unwrap()->get<ox::ModelValueVector>();
|
||||
oxAssert(testOutStruct.typeName() == TestStructNest::TypeName, "ModelObject TypeName failed");
|
||||
oxAssert(testOutStruct.typeVersion() == TestStructNest::TypeVersion, "ModelObject TypeVersion failed");
|
||||
oxAssert(testOutStruct.get("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool failed");
|
||||
oxAssert(testOutStruct.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String failed");
|
||||
oxAssert(testOut.get("unionIdx").unwrap()->get<int>() == testIn.unionIdx, "testOut.unionIdx failed");
|
||||
oxAssert(testOutUnion.unionIdx() == testIn.unionIdx, "testOut.Union idx wrong");
|
||||
oxAssert(testOutUnion.get("Int").unwrap()->get<uint32_t>() == testIn.Union.Int, "testOut.Union.Int failed");
|
||||
oxAssert(testOutList[0].get<uint32_t>() == testIn.List[0], "testOut.List[0] failed");
|
||||
oxAssert(testOutList[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] failed");
|
||||
oxAssert(testOutStructCopy.get("Bool").unwrap()->get<bool>() == testIn.Struct.Bool, "testOut.Struct.Bool (copy) failed");
|
||||
oxAssert(testOutStructCopy.get("String").unwrap()->get<ox::String>() == testIn.Struct.String.c_str(), "testOut.Struct.String (copy) failed");
|
||||
oxAssert(testOutListCopy[0].get<uint32_t>() == testIn.List[0], "testOut.Struct.List[0] (copy) failed");
|
||||
oxAssert(testOutListCopy[1].get<uint32_t>() == testIn.List[1], "testOut.Struct.List[1] (copy) failed");
|
||||
return OxError(0);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
@ -354,13 +354,11 @@ int main(int argc, const char **args) {
|
||||
if (argc < 2) {
|
||||
oxError("Must specify test to run");
|
||||
}
|
||||
const auto testName = args[1];
|
||||
ox::Error(*test)();
|
||||
try {
|
||||
test = tests.at(testName);
|
||||
} catch (const std::out_of_range&) {
|
||||
oxErrorf("Test {} not found", testName);
|
||||
return 1;
|
||||
auto const testName = args[1];
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
oxAssert(func->second(), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
return static_cast<int>(test());
|
||||
return -1;
|
||||
}
|
||||
|
10
deps/ox/src/ox/oc/write.cpp
vendored
10
deps/ox/src/ox/oc/write.cpp
vendored
@ -26,16 +26,8 @@ Error OrganicClawWriter::fieldCString(const char *key, const char *const*val, in
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error OrganicClawWriter::fieldCString(const char *key, char **val, int len) noexcept {
|
||||
return fieldCString(key, const_cast<const char**>(val), len);
|
||||
}
|
||||
|
||||
Error OrganicClawWriter::fieldCString(const char *key, const char *const*val) noexcept {
|
||||
return fieldCString(key, const_cast<const char**>(val), {});
|
||||
}
|
||||
|
||||
Error OrganicClawWriter::fieldCString(const char *key, char **val) noexcept {
|
||||
return fieldCString(key, const_cast<const char**>(val), {});
|
||||
return fieldCString(key, const_cast<const char**>(val), static_cast<int>(ox_strlen(val)));
|
||||
}
|
||||
|
||||
Error OrganicClawWriter::field(const char *key, const UUID *uuid) noexcept {
|
||||
|
92
deps/ox/src/ox/oc/write.hpp
vendored
92
deps/ox/src/ox/oc/write.hpp
vendored
@ -36,32 +36,32 @@ class OrganicClawWriter {
|
||||
|
||||
explicit OrganicClawWriter(Json::Value json, int unionIdx = -1) noexcept;
|
||||
|
||||
Error field(const char *key, CommonPtrWith<int8_t> auto *val) noexcept {
|
||||
if (*val) {
|
||||
Error field(const char *key, const int8_t *val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error field(const char *key, CommonPtrWith<int16_t> auto *val) noexcept {
|
||||
if (*val) {
|
||||
Error field(const char *key, const int16_t *val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error field(const char *key, CommonPtrWith<int32_t> auto *val) noexcept {
|
||||
if (*val) {
|
||||
Error field(const char *key, const int32_t *val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error field(const char *key, CommonPtrWith<int64_t> auto *val) noexcept {
|
||||
if (*val) {
|
||||
Error field(const char *key, const int64_t *val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
@ -69,58 +69,55 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
|
||||
Error field(const char *key, CommonPtrWith<uint8_t> auto *val) noexcept {
|
||||
if (*val) {
|
||||
Error field(const char *key, const uint8_t *val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error field(const char *key, CommonPtrWith<uint16_t> auto *val) noexcept {
|
||||
if (targetValid() && *val) {
|
||||
Error field(const char *key, const uint16_t *val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error field(const char *key, CommonPtrWith<uint32_t> auto *val) noexcept {
|
||||
if (targetValid() && *val) {
|
||||
Error field(const char *key, const uint32_t *val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error field(const char *key, CommonPtrWith<uint64_t> auto *val) noexcept {
|
||||
if (targetValid() && *val) {
|
||||
Error field(const char *key, const uint64_t *val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
Error field(const char *key, CommonPtrWith<bool> auto *val) noexcept {
|
||||
if (targetValid() && *val) {
|
||||
Error field(char const*key, bool const*val) noexcept {
|
||||
if (targetValid() && (*val || m_json.isArray())) {
|
||||
value(key) = *val;
|
||||
}
|
||||
++m_fieldIt;
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, T *val, std::size_t len) noexcept;
|
||||
|
||||
template<typename U, bool force = true>
|
||||
Error field(const char*, UnionView<U, force> val) noexcept;
|
||||
Error field(char const*, UnionView<U, force> val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char *key, const HashMap<String, T> *val) noexcept {
|
||||
Error field(char const*key, HashMap<String, T> const*val) noexcept {
|
||||
if (targetValid()) {
|
||||
const auto &keys = val->keys();
|
||||
OrganicClawWriter w;
|
||||
ModelHandlerInterface handler{&w};
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
for (std::size_t i = 0; i < keys.size(); ++i) {
|
||||
const auto k = keys[i].c_str();
|
||||
if (k) [[likely]] {
|
||||
@ -134,13 +131,8 @@ class OrganicClawWriter {
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Error field(const char *key, HashMap<String, T> *val) noexcept {
|
||||
return field(key, const_cast<const HashMap<String, T>*>(val));
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, const BString<L> *val) noexcept {
|
||||
Error field(char const*key, BString<L> const*val) noexcept {
|
||||
if (targetValid() && val->len()) {
|
||||
value(key) = val->c_str();
|
||||
}
|
||||
@ -149,16 +141,7 @@ class OrganicClawWriter {
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, BString<L> *val) noexcept {
|
||||
if (targetValid() && val->len()) {
|
||||
value(key) = val->c_str();
|
||||
}
|
||||
++m_fieldIt;
|
||||
return {};
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, const BasicString<L> *val) noexcept {
|
||||
Error field(char const*key, BasicString<L> const*val) noexcept {
|
||||
if (targetValid() && val->len()) {
|
||||
value(key) = val->c_str();
|
||||
}
|
||||
@ -166,23 +149,17 @@ class OrganicClawWriter {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
template<std::size_t L>
|
||||
Error field(const char *key, BasicString<L> *val) noexcept {
|
||||
return field(key, const_cast<const BasicString<L>*>(val));
|
||||
}
|
||||
|
||||
Error fieldCString(const char*, const char *const*val, int len) noexcept;
|
||||
|
||||
Error fieldCString(const char *name, char **val, int len) noexcept;
|
||||
|
||||
Error fieldCString(const char *name, const char *const*val) noexcept;
|
||||
|
||||
Error fieldCString(const char *name, char **val) noexcept;
|
||||
|
||||
Error field(const char *key, const UUID *uuid) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, T *val) noexcept;
|
||||
Error field(const char*, const T *val, std::size_t len) noexcept;
|
||||
|
||||
template<typename T>
|
||||
Error field(const char*, const T *val) noexcept;
|
||||
|
||||
template<typename T>
|
||||
constexpr ox::Error setTypeInfo(
|
||||
@ -200,6 +177,7 @@ class OrganicClawWriter {
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return OpType::Write;
|
||||
}
|
||||
@ -216,12 +194,12 @@ class OrganicClawWriter {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) noexcept {
|
||||
Error OrganicClawWriter::field(const char *key, const T *val, std::size_t len) noexcept {
|
||||
if (targetValid() && len) {
|
||||
OrganicClawWriter w((Json::Value(Json::arrayValue)));
|
||||
ModelHandlerInterface handler{&w};
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
for (std::size_t i = 0; i < len; ++i) {
|
||||
oxReturnError(handler.field("", &val[i]));
|
||||
oxReturnError(handler.field({}, &val[i]));
|
||||
}
|
||||
value(key) = w.m_json;
|
||||
}
|
||||
@ -230,12 +208,12 @@ Error OrganicClawWriter::field(const char *key, T *val, std::size_t len) noexcep
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Error OrganicClawWriter::field(const char *key, T *val) noexcept {
|
||||
Error OrganicClawWriter::field(const char *key, const T *val) noexcept {
|
||||
if constexpr(isVector_v<T> || isArray_v<T>) {
|
||||
return field(key, val->data(), val->size());
|
||||
} else if (val && targetValid()) {
|
||||
OrganicClawWriter w;
|
||||
ModelHandlerInterface handler{&w};
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
oxReturnError(model(&handler, val));
|
||||
if (!w.m_json.isNull()) {
|
||||
value(key) = w.m_json;
|
||||
@ -249,7 +227,7 @@ template<typename U, bool force>
|
||||
Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcept {
|
||||
if (targetValid()) {
|
||||
OrganicClawWriter w(val.idx());
|
||||
ModelHandlerInterface handler{&w};
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||
oxReturnError(model(&handler, val.get()));
|
||||
if (!w.m_json.isNull()) {
|
||||
value(key) = w.m_json;
|
||||
@ -261,7 +239,7 @@ Error OrganicClawWriter::field(const char *key, UnionView<U, force> val) noexcep
|
||||
|
||||
Result<Buffer> writeOC(const auto &val) noexcept {
|
||||
OrganicClawWriter writer;
|
||||
ModelHandlerInterface handler(&writer);
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(&writer);
|
||||
oxReturnError(model(&handler, &val));
|
||||
Json::StreamWriterBuilder jsonBuilder;
|
||||
const auto str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
|
@ -22,7 +22,7 @@ template<typename PlatSpec, typename T>
|
||||
constexpr std::size_t sizeOf(const T *t) noexcept;
|
||||
|
||||
template<typename PlatSpec>
|
||||
struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>> {
|
||||
struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>, OpType::Reflect> {
|
||||
std::size_t biggestAlignment = 1;
|
||||
|
||||
template<typename T>
|
||||
@ -64,11 +64,6 @@ struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>> {
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return ox::OpType::Reflect;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
1
deps/ox/src/ox/preloader/platspecs.hpp
vendored
1
deps/ox/src/ox/preloader/platspecs.hpp
vendored
@ -13,6 +13,7 @@
|
||||
namespace ox {
|
||||
|
||||
struct NativePlatSpec {
|
||||
static constexpr std::size_t RomStart = 1024;
|
||||
using PtrType = uintptr_t;
|
||||
using size_t = std::size_t;
|
||||
|
||||
|
2
deps/ox/src/ox/preloader/preloader.cpp
vendored
2
deps/ox/src/ox/preloader/preloader.cpp
vendored
@ -6,4 +6,6 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
template class Preloader<NativePlatSpec>;
|
||||
|
||||
}
|
||||
|
16
deps/ox/src/ox/preloader/preloader.hpp
vendored
16
deps/ox/src/ox/preloader/preloader.hpp
vendored
@ -15,7 +15,6 @@
|
||||
#include <ox/std/units.hpp>
|
||||
#include <ox/model/modelhandleradaptor.hpp>
|
||||
|
||||
#include "preloader.hpp"
|
||||
#include "platspecs.hpp"
|
||||
|
||||
namespace ox {
|
||||
@ -24,7 +23,7 @@ template<typename PlatSpec>
|
||||
class Preloader;
|
||||
|
||||
template<typename PlatSpec>
|
||||
class Preloader: public ModelHandlerBase<Preloader<PlatSpec>> {
|
||||
class Preloader: public ModelHandlerBase<Preloader<PlatSpec>, OpType::Reflect> {
|
||||
private:
|
||||
using PtrType = typename PlatSpec::PtrType;
|
||||
static constexpr auto PtrSize = sizeof(PtrType);
|
||||
@ -115,11 +114,6 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>> {
|
||||
return m_buff;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return ox::OpType::Write;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr ox::Error pad(const T*) noexcept;
|
||||
|
||||
@ -205,7 +199,7 @@ constexpr ox::Error Preloader<PlatSpec>::field(CRStringView, const ox::BasicStri
|
||||
const auto restore = m_writer.tellp();
|
||||
std::size_t a = 0;
|
||||
if (sz && sz >= SmallStringSize) {
|
||||
oxReturnError(ox::allocate(&m_writer, sz).moveTo(&a));
|
||||
oxReturnError(ox::allocate(&m_writer, sz).moveTo(a));
|
||||
} else {
|
||||
a = restore;
|
||||
}
|
||||
@ -253,7 +247,7 @@ constexpr ox::Error Preloader<PlatSpec>::field(CRStringView, const T **val, std:
|
||||
template<typename PlatSpec>
|
||||
constexpr ox::Result<std::size_t> Preloader<PlatSpec>::startAlloc(std::size_t sz) noexcept {
|
||||
oxRequire(a, ox::allocate(&m_writer, sz));
|
||||
m_allocStack.emplace_back(static_cast<PlatSpec::PtrType>(m_writer.tellp()));
|
||||
m_allocStack.emplace_back(static_cast<typename PlatSpec::PtrType>(m_writer.tellp()));
|
||||
oxReturnError(m_writer.seekp(a));
|
||||
return a;
|
||||
}
|
||||
@ -272,7 +266,7 @@ constexpr ox::Error Preloader<PlatSpec>::endAlloc() noexcept {
|
||||
return m_writer.seekp(0, ox::ios_base::end);
|
||||
}
|
||||
const auto &si = *m_allocStack.back().unwrap();
|
||||
oxReturnError(m_writer.seekp(si.restore, si.seekdir));
|
||||
oxReturnError(m_writer.seekp(static_cast<ox::ssize_t>(si.restore), si.seekdir));
|
||||
m_allocStack.pop_back();
|
||||
return {};
|
||||
}
|
||||
@ -364,4 +358,6 @@ constexpr ox::Error preload(Preloader<PlatSpec> *pl, ox::CommonPtrWith<T> auto *
|
||||
return pl->pad(obj);
|
||||
}
|
||||
|
||||
extern template class Preloader<NativePlatSpec>;
|
||||
|
||||
}
|
||||
|
9
deps/ox/src/ox/preloader/sizecatcher.hpp
vendored
9
deps/ox/src/ox/preloader/sizecatcher.hpp
vendored
@ -24,7 +24,7 @@ template<typename PlatSpec, typename T>
|
||||
constexpr std::size_t sizeOf(const T *t) noexcept;
|
||||
|
||||
template<typename PlatSpec>
|
||||
class SizeCatcher: public ModelHandlerBase<SizeCatcher<PlatSpec>> {
|
||||
class SizeCatcher: public ModelHandlerBase<SizeCatcher<PlatSpec>, OpType::Reflect> {
|
||||
private:
|
||||
std::size_t m_size = 0;
|
||||
|
||||
@ -61,11 +61,6 @@ class SizeCatcher: public ModelHandlerBase<SizeCatcher<PlatSpec>> {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return ox::OpType::Reflect;
|
||||
}
|
||||
|
||||
private:
|
||||
constexpr void pad(const auto *val) noexcept;
|
||||
};
|
||||
@ -112,7 +107,7 @@ constexpr std::size_t sizeOf(const T *t) noexcept {
|
||||
if constexpr(ox::is_integral_v<T>) {
|
||||
return sizeof(T);
|
||||
} else if constexpr(ox::is_pointer_v<T>) {
|
||||
return sizeof(PlatSpec::PtrType);
|
||||
return sizeof(typename PlatSpec::PtrType);
|
||||
} else {
|
||||
SizeCatcher<PlatSpec> sc;
|
||||
const auto err = model(sc.interface(), t);
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace ox {
|
||||
|
||||
template<typename PlatSpec>
|
||||
class UnionSizeCatcher: public ModelHandlerBase<UnionSizeCatcher<PlatSpec>> {
|
||||
class UnionSizeCatcher: public ModelHandlerBase<UnionSizeCatcher<PlatSpec>, OpType::Reflect> {
|
||||
private:
|
||||
std::size_t m_size = 0;
|
||||
|
||||
@ -55,11 +55,6 @@ class UnionSizeCatcher: public ModelHandlerBase<UnionSizeCatcher<PlatSpec>> {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr auto opType() noexcept {
|
||||
return ox::OpType::Reflect;
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename T, std::size_t SmallVecSize>
|
||||
constexpr ox::Error fieldStr(CRStringView, const ox::BasicString<SmallVecSize> *val) noexcept;
|
||||
|
217
deps/ox/src/ox/std/basestringview.hpp
vendored
Normal file
217
deps/ox/src/ox/std/basestringview.hpp
vendored
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright 2015 - 2023 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bit.hpp"
|
||||
#include "cstrops.hpp"
|
||||
#include "iterator.hpp"
|
||||
|
||||
namespace ox::detail {
|
||||
|
||||
class BaseStringView {
|
||||
public:
|
||||
template<typename RefType = char&, typename PtrType = char*, bool reverse = false>
|
||||
struct iterator: public Iterator<std::bidirectional_iterator_tag, char> {
|
||||
private:
|
||||
PtrType m_t = nullptr;
|
||||
std::size_t m_offset = 0;
|
||||
std::size_t m_max = 0;
|
||||
|
||||
public:
|
||||
constexpr iterator() noexcept = default;
|
||||
|
||||
constexpr iterator(PtrType t, std::size_t offset, std::size_t max) noexcept {
|
||||
m_t = t;
|
||||
m_offset = offset;
|
||||
m_max = max;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto offset() const noexcept {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
constexpr iterator operator+(std::size_t s) const noexcept {
|
||||
if constexpr(reverse) {
|
||||
return iterator(m_t, max<std::size_t>(m_offset - s, 0), m_max);
|
||||
} else {
|
||||
return iterator(m_t, min<std::size_t>(m_offset + s, m_max), m_max);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr auto operator-(const iterator &other) const noexcept {
|
||||
if constexpr(reverse) {
|
||||
return m_offset + other.m_offset;
|
||||
} else {
|
||||
return m_offset - other.m_offset;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr iterator operator-(std::size_t s) const noexcept {
|
||||
if constexpr(reverse) {
|
||||
return iterator(m_t, min<std::size_t>(m_offset + s, m_max), m_max);
|
||||
} else {
|
||||
return iterator(m_t, max<std::size_t>(m_offset - s, 0), m_max);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr iterator &operator+=(std::size_t s) noexcept {
|
||||
if constexpr(reverse) {
|
||||
m_offset = max<std::size_t>(m_offset - s, 0);
|
||||
} else {
|
||||
m_offset = min(m_offset + s, m_max);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr iterator &operator-=(std::size_t s) noexcept {
|
||||
if constexpr(reverse) {
|
||||
m_offset = min(m_offset + s, m_max);
|
||||
} else {
|
||||
m_offset = max<std::size_t>(m_offset - s, 0);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr iterator &operator++() noexcept {
|
||||
return operator+=(1);
|
||||
}
|
||||
|
||||
constexpr iterator &operator--() noexcept {
|
||||
return operator-=(1);
|
||||
}
|
||||
|
||||
constexpr RefType operator*() const noexcept {
|
||||
return m_t[m_offset];
|
||||
}
|
||||
|
||||
constexpr RefType operator[](std::size_t s) const noexcept {
|
||||
return m_t[s];
|
||||
}
|
||||
|
||||
constexpr bool operator<(const iterator &other) const noexcept {
|
||||
return m_offset < other.m_offset;
|
||||
}
|
||||
|
||||
constexpr bool operator>(const iterator &other) const noexcept {
|
||||
return m_offset > other.m_offset;
|
||||
}
|
||||
|
||||
constexpr bool operator<=(const iterator &other) const noexcept {
|
||||
return m_offset <= other.m_offset;
|
||||
}
|
||||
|
||||
constexpr bool operator>=(const iterator &other) const noexcept {
|
||||
return m_offset >= other.m_offset;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const iterator &other) const noexcept {
|
||||
return m_t == other.m_t && m_offset == other.m_offset && m_max == other.m_max;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const iterator &other) const noexcept {
|
||||
return m_t != other.m_t || m_offset != other.m_offset || m_max != other.m_max;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private:
|
||||
const char *m_str = nullptr;
|
||||
std::size_t m_len = 0;
|
||||
protected:
|
||||
constexpr BaseStringView() noexcept = default;
|
||||
|
||||
constexpr BaseStringView(BaseStringView const&sv) noexcept = default;
|
||||
|
||||
constexpr explicit BaseStringView(std::nullptr_t) noexcept {}
|
||||
|
||||
constexpr explicit BaseStringView(const char *str) noexcept: m_str(str), m_len(str ? ox_strlen(str) : 0) {}
|
||||
|
||||
constexpr explicit BaseStringView(const char *str, std::size_t len) noexcept: m_str(str), m_len(len) {}
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const char&, const char*> begin() const noexcept {
|
||||
return {m_str, 0, m_len};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const char&, const char*> end() const noexcept {
|
||||
return {m_str, m_len, m_len};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const char&, const char*> cbegin() const noexcept {
|
||||
return {m_str, 0, m_len};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const char&, const char*> cend() const noexcept {
|
||||
return {m_str, m_len, m_len};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const char&, const char*, true> crbegin() const noexcept {
|
||||
return {m_str, m_len - 1, m_len};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const char&, const char*, true> crend() const noexcept {
|
||||
return {m_str, MaxValue<std::size_t>, m_len};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const char&, const char*, true> rbegin() const noexcept {
|
||||
return {m_str, m_len - 1, m_len};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const char&, const char*, true> rend() const noexcept {
|
||||
return {m_str, MaxValue<std::size_t>, m_len};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto bytes() const noexcept {
|
||||
return m_len;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto len() const noexcept {
|
||||
return m_len;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto *data() const noexcept {
|
||||
return &m_str[0];
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto &front() const noexcept {
|
||||
return m_str[0];
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto &back() const noexcept {
|
||||
return m_str[m_len - 1];
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto operator[](std::size_t i) const noexcept {
|
||||
return m_str[i];
|
||||
}
|
||||
|
||||
protected:
|
||||
constexpr void set(const char *str, std::size_t len) noexcept {
|
||||
m_str = str;
|
||||
m_len = len;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
53
deps/ox/src/ox/std/cstringview.hpp
vendored
Normal file
53
deps/ox/src/ox/std/cstringview.hpp
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2015 - 2023 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "basestringview.hpp"
|
||||
#include "bstring.hpp"
|
||||
#include "string.hpp"
|
||||
#include "stringliteral.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
class CStringView: public detail::BaseStringView {
|
||||
public:
|
||||
constexpr CStringView() noexcept = default;
|
||||
|
||||
constexpr CStringView(CStringView const&sv) noexcept = default;
|
||||
|
||||
constexpr CStringView(StringLiteral const&str) noexcept: BaseStringView(str.data(), str.len()) {}
|
||||
|
||||
template<std::size_t SmallStrSz>
|
||||
constexpr CStringView(BasicString<SmallStrSz> const&str) noexcept: BaseStringView(str.data(), str.len()) {}
|
||||
|
||||
template<std::size_t SmallStrSz>
|
||||
constexpr CStringView(BString<SmallStrSz> const&str) noexcept: BaseStringView(str.data(), str.len()) {}
|
||||
|
||||
constexpr CStringView(std::nullptr_t) noexcept {}
|
||||
|
||||
constexpr CStringView(const char *str) noexcept: BaseStringView(str) {}
|
||||
|
||||
constexpr CStringView(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {}
|
||||
|
||||
constexpr auto &operator=(CStringView const&other) noexcept {
|
||||
if (&other != this) {
|
||||
set(other.data(), other.len());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const char *c_str() const noexcept {
|
||||
return data();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
145
deps/ox/src/ox/std/cstrops.hpp
vendored
Normal file
145
deps/ox/src/ox/std/cstrops.hpp
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright 2015 - 2023 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.hpp"
|
||||
#include "typetraits.hpp"
|
||||
|
||||
template<typename T1, typename T2>
|
||||
constexpr T1 ox_strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
using T1Type = typename ox::remove_reference<decltype(dest[0])>::type;
|
||||
std::size_t i = 0;
|
||||
while (i < maxLen && src[i]) {
|
||||
dest[i] = static_cast<T1Type>(src[i]);
|
||||
++i;
|
||||
}
|
||||
// set null terminator
|
||||
dest[i] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto ox_strnlen(const char *str1, std::size_t maxLen) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; len < maxLen && str1[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]]
|
||||
constexpr auto ox_strlen(T const&str1) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; str1[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
[[nodiscard]]
|
||||
constexpr int ox_strcmp(const T1 &str1, const T2 &str2) noexcept {
|
||||
auto retval = 0;
|
||||
auto i = 0u;
|
||||
while (str1[i] || str2[i]) {
|
||||
if (str1[i] < str2[i]) {
|
||||
retval = -1;
|
||||
break;
|
||||
} else if (str1[i] > str2[i]) {
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
[[nodiscard]]
|
||||
constexpr int ox_strncmp(T1 const&str1, T2 const&str2, const std::size_t maxLen) noexcept {
|
||||
auto retval = 0;
|
||||
std::size_t i = 0;
|
||||
while (i < maxLen && (str1[i] || str2[i])) {
|
||||
if (str1[i] < str2[i]) {
|
||||
retval = -1;
|
||||
break;
|
||||
} else if (str1[i] > str2[i]) {
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const char *ox_strchr(const char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
for (std::size_t i = 0; i <= maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
} else if (str[i] == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
for (std::size_t i = 0; i < maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
} else if (str[i] == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int ox_lastIndexOf(const auto &str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
int retval = -1;
|
||||
for (std::size_t i = 0; i < maxLen && str[i]; i++) {
|
||||
if (str[i] == character) {
|
||||
retval = static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
template<typename Integer, typename T>
|
||||
constexpr T ox_itoa(Integer v, T str) noexcept {
|
||||
if (v) {
|
||||
ox::ResizedInt_t<Integer, 64> mod = 1000000000000000000;
|
||||
ox::ResizedInt_t<Integer, 64> val = v;
|
||||
constexpr auto base = 10;
|
||||
auto it = 0;
|
||||
if (val < 0) {
|
||||
str[static_cast<std::size_t>(it)] = '-';
|
||||
it++;
|
||||
}
|
||||
while (mod) {
|
||||
auto digit = val / mod;
|
||||
val %= mod;
|
||||
mod /= base;
|
||||
if (it || digit) {
|
||||
ox::ResizedInt_t<Integer, 64> start = '0';
|
||||
if (digit >= 10) {
|
||||
start = 'a';
|
||||
digit -= 10;
|
||||
}
|
||||
str[static_cast<std::size_t>(it)] = static_cast<typename ox::remove_reference<decltype(str[0])>::type>(start + digit);
|
||||
it++;
|
||||
}
|
||||
}
|
||||
str[static_cast<std::size_t>(it)] = 0;
|
||||
} else {
|
||||
// 0 is a special case
|
||||
str[0] = '0';
|
||||
str[1] = 0;
|
||||
}
|
||||
return str;
|
||||
}
|
20
deps/ox/src/ox/std/def.hpp
vendored
20
deps/ox/src/ox/std/def.hpp
vendored
@ -17,16 +17,9 @@
|
||||
#define oxOut(...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", __VA_ARGS__)
|
||||
#define oxErr(...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", __VA_ARGS__)
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
// Non-GCC compilers don't like ##__VA_ARGS__, so use initializer list, which relies on std lib
|
||||
#define oxTracef(ch, fmt, ...) ox::trace::TraceStream(__FILE__, __LINE__, ch, ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), {__VA_ARGS__})
|
||||
#define oxOutf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), {__VA_ARGS__})
|
||||
#define oxErrf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), {__VA_ARGS__})
|
||||
#else
|
||||
#define oxTracef(ch, fmt, ...) ox::trace::TraceStream(__FILE__, __LINE__, ch, ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), ##__VA_ARGS__)
|
||||
#define oxOutf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), ##__VA_ARGS__)
|
||||
#define oxErrf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), ##__VA_ARGS__)
|
||||
#endif
|
||||
#define oxTracef(ch, fmt, ...) ox::trace::TraceStream(__FILE__, __LINE__, ch, ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), __VA_ARGS__)
|
||||
#define oxOutf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), __VA_ARGS__)
|
||||
#define oxErrf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), __VA_ARGS__)
|
||||
|
||||
#define oxInfo(...) oxTrace("info", __VA_ARGS__)
|
||||
#define oxInfof(...) oxTracef("info", __VA_ARGS__)
|
||||
@ -35,12 +28,7 @@
|
||||
|
||||
#ifndef OX_NODEBUG
|
||||
#define oxDebug(...) ox::trace::OutStream(__FILE__, __LINE__, "debug", __VA_ARGS__)
|
||||
#ifdef OX_USE_STDLIB
|
||||
// Non-GCC compilers don't like ##__VA_ARGS__, so use initializer list, which relies on std lib
|
||||
#define oxDebugf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "debug", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), {__VA_ARGS__})
|
||||
#else
|
||||
#define oxDebugf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "debug", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), ##__VA_ARGS__)
|
||||
#endif
|
||||
#define oxDebugf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "debug", ox::detail::fmtSegments<ox::detail::argCount(fmt)+1>(fmt), __VA_ARGS__)
|
||||
#else
|
||||
#define oxDebug(...) static_assert(false, "Debug prints were checked in.");
|
||||
#define oxDebugf(...) static_assert(false, "Debug prints were checked in.");
|
||||
|
131
deps/ox/src/ox/std/error.hpp
vendored
131
deps/ox/src/ox/std/error.hpp
vendored
@ -138,16 +138,16 @@ struct [[nodiscard]] Result {
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
constexpr Result(const Result<U> &&other) noexcept: value(std::move(other.value)), error(std::move(other.error)) {
|
||||
constexpr Result(Result<U> &&other) noexcept: value(std::move(other.value)), error(std::move(other.error)) {
|
||||
}
|
||||
|
||||
constexpr Result(const Error &error) noexcept: value(), error(error) {
|
||||
}
|
||||
|
||||
constexpr Result(const type &value, const Error &error = OxError(0)) noexcept: value(const_cast<type&>(value)), error(error) {
|
||||
constexpr Result(const type &value, const Error &error = OxError(0)) noexcept: value(value), error(error) {
|
||||
}
|
||||
|
||||
constexpr Result(type &&value, const Error &error = OxError(0)) noexcept: value(ox::forward<type>(value)), error(error) {
|
||||
constexpr Result(type &&value, const Error &error = OxError(0)) noexcept: value(std::move(value)), error(error) {
|
||||
}
|
||||
|
||||
constexpr ~Result() noexcept = default;
|
||||
@ -165,52 +165,139 @@ struct [[nodiscard]] Result {
|
||||
return error == 0;
|
||||
}
|
||||
|
||||
constexpr Error get(type *val) const noexcept {
|
||||
*val = value;
|
||||
return error;
|
||||
}
|
||||
|
||||
constexpr Error get(type *val) noexcept {
|
||||
*val = value;
|
||||
return error;
|
||||
}
|
||||
|
||||
constexpr Error moveTo(type *val) noexcept {
|
||||
constexpr Error copyTo(type &val) const& noexcept {
|
||||
if (!error) [[likely]] {
|
||||
*val = std::move(value);
|
||||
val = value;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
constexpr auto &unwrap() noexcept {
|
||||
constexpr Error copyTo(type &val) && noexcept {
|
||||
if (!error) [[likely]] {
|
||||
val = std::move(value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
constexpr Error moveTo(type &val) noexcept {
|
||||
if (!error) [[likely]] {
|
||||
val = std::move(value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &unwrap() & noexcept {
|
||||
if (error) {
|
||||
oxPanic(error, "Failed unwrap");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
constexpr auto &unwrapThrow() {
|
||||
[[nodiscard]]
|
||||
constexpr T &&unwrap() && noexcept {
|
||||
if (error) {
|
||||
oxPanic(error, "Failed unwrap");
|
||||
}
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T const&unwrap() const & noexcept {
|
||||
if (error) [[unlikely]] {
|
||||
oxPanic(error, "Failed unwrap");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &unwrapThrow() & {
|
||||
if (error) {
|
||||
throw ox::Exception(error);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
constexpr const auto &unwrap() const noexcept {
|
||||
if (error) [[unlikely]] {
|
||||
oxPanic(error, "Failed unwrap");
|
||||
[[nodiscard]]
|
||||
constexpr T &&unwrapThrow() && {
|
||||
if (error) {
|
||||
throw ox::Exception(error);
|
||||
}
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T const&unwrapThrow() const & {
|
||||
if (error) {
|
||||
throw ox::Exception(error);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename U = T>
|
||||
constexpr ox::Result<U> to(const auto &f) noexcept {
|
||||
constexpr ox::Result<U> to(auto const&f) & noexcept {
|
||||
if (error) [[unlikely]] {
|
||||
return OxError(1);
|
||||
return error;
|
||||
}
|
||||
return f(value);
|
||||
}
|
||||
|
||||
template<typename U = T>
|
||||
constexpr ox::Result<U> to(auto const&f) && noexcept {
|
||||
if (error) [[unlikely]] {
|
||||
return error;
|
||||
}
|
||||
return f(std::move(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter alt if Result contains an error.
|
||||
* @param alt
|
||||
* @return value of Result or alt
|
||||
*/
|
||||
constexpr T or_value(T &&alt) const& noexcept {
|
||||
if (error) {
|
||||
return std::move(alt);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter alt if Result contains an error.
|
||||
* @param alt
|
||||
* @return value of Result or alt
|
||||
*/
|
||||
constexpr T or_value(T &&alt) && noexcept {
|
||||
if (error) {
|
||||
return std::move(alt);
|
||||
}
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter alt if Result contains an error.
|
||||
* @param alt
|
||||
* @return value of Result or alt
|
||||
*/
|
||||
constexpr T or_value(T const&alt) const& noexcept {
|
||||
if (error) {
|
||||
return alt;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter alt if Result contains an error.
|
||||
* @param alt
|
||||
* @return value of Result or alt
|
||||
*/
|
||||
constexpr T or_value(T const&alt) && noexcept {
|
||||
if (error) {
|
||||
return alt;
|
||||
}
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
2
deps/ox/src/ox/std/fmt.hpp
vendored
2
deps/ox/src/ox/std/fmt.hpp
vendored
@ -186,7 +186,7 @@ constexpr Fmt<segementCnt> fmtSegments(StringView fmt) noexcept {
|
||||
|
||||
template<typename StringType = String, typename ...Args>
|
||||
[[nodiscard]]
|
||||
constexpr StringType sfmt(StringView fmt, Args... args) noexcept {
|
||||
constexpr StringType sfmt(StringView fmt, Args&&... args) noexcept {
|
||||
assert(ox::detail::argCount(fmt) == sizeof...(args));
|
||||
StringType out;
|
||||
const auto fmtSegments = ox::detail::fmtSegments<sizeof...(args)+1>(fmt);
|
||||
|
43
deps/ox/src/ox/std/hashmap.hpp
vendored
43
deps/ox/src/ox/std/hashmap.hpp
vendored
@ -18,25 +18,11 @@ namespace ox {
|
||||
template<typename K, typename T>
|
||||
class HashMap {
|
||||
|
||||
using key_t = K;
|
||||
using value_t = T;
|
||||
public:
|
||||
using key_t = K;
|
||||
using value_t = T;
|
||||
|
||||
private:
|
||||
// Maybe StringView. If K (or KK for MaybeSV) is a string type,
|
||||
// MaybeSV::type/MaybeSV_t is a StringView.
|
||||
// This avoids creating unnecessary Strings when taking a StringView or C
|
||||
// string in lookups.
|
||||
template<typename KK, bool isStr = isOxString_v<KK>>
|
||||
struct MaybeSV {
|
||||
using type = KK;
|
||||
};
|
||||
template<typename KK>
|
||||
struct MaybeSV<KK, true> {
|
||||
using type = ox::StringView;
|
||||
};
|
||||
template<typename KK>
|
||||
using MaybeSV_t = MaybeSV<KK>::type;
|
||||
|
||||
struct Pair {
|
||||
K key = {};
|
||||
T value{};
|
||||
@ -85,15 +71,9 @@ class HashMap {
|
||||
|
||||
constexpr static uint64_t hash(StringView const&) noexcept;
|
||||
|
||||
/**
|
||||
* K is assumed to be a null terminated string.
|
||||
*/
|
||||
template<typename KK>
|
||||
constexpr Pair *const&access(Vector<Pair*> const&pairs, KK const&key) const;
|
||||
|
||||
/**
|
||||
* K is assumed to be a null terminated string.
|
||||
*/
|
||||
template<typename KK>
|
||||
constexpr Pair *&access(Vector<Pair*> &pairs, KK const&key);
|
||||
|
||||
@ -124,7 +104,7 @@ constexpr bool HashMap<K, T>::operator==(HashMap const&other) const {
|
||||
if (m_keys != other.m_keys) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < m_keys.size(); i++) {
|
||||
for (int i = 0; i < m_keys.size(); ++i) {
|
||||
auto &k = m_keys[i];
|
||||
if (at(k) != other.at(k)) {
|
||||
return false;
|
||||
@ -194,7 +174,7 @@ constexpr void HashMap<K, T>::erase(MaybeSV_t<K> const&k) {
|
||||
auto h = hash(k) % m_pairs.size();
|
||||
while (true) {
|
||||
const auto &p = m_pairs[h];
|
||||
if (p == nullptr || ox_strcmp(p->key, k) == 0) {
|
||||
if (p == nullptr || p->key == k) {
|
||||
oxIgnoreError(m_pairs.erase(h));
|
||||
break;
|
||||
} else {
|
||||
@ -232,7 +212,7 @@ template<typename K, typename T>
|
||||
constexpr void HashMap<K, T>::expand() {
|
||||
Vector<Pair*> r;
|
||||
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
||||
auto k = m_keys[i];
|
||||
K k{m_keys[i]};
|
||||
access(r, k) = std::move(access(m_pairs, k));
|
||||
}
|
||||
m_pairs = std::move(r);
|
||||
@ -264,7 +244,7 @@ constexpr typename HashMap<K, T>::Pair *const&HashMap<K, T>::access(Vector<Pair*
|
||||
auto h = static_cast<std::size_t>(hash(k) % pairs.size());
|
||||
while (true) {
|
||||
const auto &p = pairs[h];
|
||||
if (p == nullptr || ox_strcmp(p->key, k) == 0) {
|
||||
if (p == nullptr || p->key == k) {
|
||||
return p;
|
||||
} else {
|
||||
h = (h + 1) % pairs.size();
|
||||
@ -278,14 +258,7 @@ constexpr typename HashMap<K, T>::Pair *&HashMap<K, T>::access(Vector<Pair*> &pa
|
||||
auto h = static_cast<std::size_t>(hash(k) % pairs.size());
|
||||
while (true) {
|
||||
auto &p = pairs[h];
|
||||
bool matches = [&] {
|
||||
if constexpr (is_integral_v<KK>) {
|
||||
return p == nullptr || k == p->key;
|
||||
} else {
|
||||
return p == nullptr || ox_strcmp(p->key, k) == 0;
|
||||
}
|
||||
}();
|
||||
if (matches) {
|
||||
if (p == nullptr || p->key == k) {
|
||||
return p;
|
||||
} else {
|
||||
h = (h + 1) % pairs.size();
|
||||
|
37
deps/ox/src/ox/std/memory.hpp
vendored
37
deps/ox/src/ox/std/memory.hpp
vendored
@ -39,6 +39,7 @@ constexpr T *construct_at(T *p, Args &&...args ) {
|
||||
|
||||
#endif
|
||||
|
||||
#include "error.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
|
||||
@ -74,6 +75,7 @@ class SharedPtr {
|
||||
int *m_refCnt = nullptr;
|
||||
|
||||
public:
|
||||
using value_type = T;
|
||||
explicit constexpr SharedPtr(T *t = nullptr) noexcept: m_t(t), m_refCnt(new int) {
|
||||
}
|
||||
|
||||
@ -180,9 +182,10 @@ template<typename T, typename Deleter = DefaultDelete>
|
||||
class UniquePtr {
|
||||
|
||||
private:
|
||||
T *m_t;
|
||||
T *m_t = nullptr;
|
||||
|
||||
public:
|
||||
using value_type = T;
|
||||
explicit constexpr UniquePtr(T *t = nullptr) noexcept: m_t(t) {
|
||||
}
|
||||
|
||||
@ -190,8 +193,8 @@ class UniquePtr {
|
||||
|
||||
constexpr UniquePtr(const UniquePtr&) = delete;
|
||||
|
||||
template<typename U>
|
||||
constexpr UniquePtr(UniquePtr<U> &&other) noexcept {
|
||||
template<typename U, typename UDeleter>
|
||||
constexpr UniquePtr(UniquePtr<U, UDeleter> &&other) noexcept {
|
||||
m_t = other.release();
|
||||
}
|
||||
|
||||
@ -210,25 +213,25 @@ class UniquePtr {
|
||||
return m_t;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
constexpr void reset(UniquePtr<U> &&other = UniquePtr()) {
|
||||
template<typename U, typename UDeleter>
|
||||
constexpr void reset(UniquePtr<U, UDeleter> &&other = UniquePtr()) {
|
||||
auto t = m_t;
|
||||
m_t = other.release();
|
||||
Deleter()(t);
|
||||
}
|
||||
|
||||
constexpr UniquePtr &operator=(const UniquePtr<T> &other) = delete;
|
||||
constexpr UniquePtr &operator=(UniquePtr const&other) = delete;
|
||||
|
||||
template<typename U>
|
||||
constexpr UniquePtr &operator=(const UniquePtr<U> &other) = delete;
|
||||
template<typename U, typename UDeleter>
|
||||
constexpr UniquePtr &operator=(UniquePtr<U, UDeleter> const&other) = delete;
|
||||
|
||||
constexpr UniquePtr &operator=(UniquePtr<T> &&other) noexcept {
|
||||
reset(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
constexpr UniquePtr &operator=(UniquePtr<U> &&other) noexcept {
|
||||
template<typename U, typename UDeleter>
|
||||
constexpr UniquePtr &operator=(UniquePtr<U, UDeleter> &&other) noexcept {
|
||||
reset(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
@ -247,8 +250,8 @@ class UniquePtr {
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using UPtr = UniquePtr<T>;
|
||||
template<typename T, typename Deleter = DefaultDelete>
|
||||
using UPtr = UniquePtr<T, Deleter>;
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator==(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexcept {
|
||||
@ -288,4 +291,14 @@ constexpr auto make_unique(Args&&... args) {
|
||||
return UniquePtr<U>(new T(ox::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename T, typename U = T, typename ...Args>
|
||||
[[nodiscard]]
|
||||
constexpr Result<UniquePtr<U>> make_unique_catch(Args&&... args) noexcept {
|
||||
try {
|
||||
return UniquePtr<U>(new T(ox::forward<Args>(args)...));
|
||||
} catch (ox::Exception const&ex) {
|
||||
return ex.toError();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
60
deps/ox/src/ox/std/optional.hpp
vendored
60
deps/ox/src/ox/std/optional.hpp
vendored
@ -28,7 +28,7 @@ class Optional {
|
||||
constexpr Optional() noexcept = default;
|
||||
|
||||
template<typename ...Args>
|
||||
explicit constexpr Optional(Args &&... args);
|
||||
explicit constexpr Optional(ox::in_place_t, Args &&... args);
|
||||
|
||||
constexpr Optional(const Optional &other) {
|
||||
if (other.m_ptr) {
|
||||
@ -64,20 +64,68 @@ class Optional {
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter alt if Result contains an error.
|
||||
* @param alt
|
||||
* @return value of Result or alt
|
||||
*/
|
||||
constexpr T or_value(T &&alt) const& noexcept {
|
||||
if (!m_ptr) {
|
||||
return std::move(alt);
|
||||
}
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter alt if Result contains an error.
|
||||
* @param alt
|
||||
* @return value of Result or alt
|
||||
*/
|
||||
constexpr T or_value(T &&alt) && noexcept {
|
||||
if (!m_ptr) {
|
||||
return std::move(alt);
|
||||
}
|
||||
return std::move(*m_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter alt if Result contains an error.
|
||||
* @param alt
|
||||
* @return value of Result or alt
|
||||
*/
|
||||
constexpr T or_value(T const&alt) const& noexcept {
|
||||
if (!m_ptr) {
|
||||
return alt;
|
||||
}
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parameter alt if Result contains an error.
|
||||
* @param alt
|
||||
* @return value of Result or alt
|
||||
*/
|
||||
constexpr T or_value(T const&alt) && noexcept {
|
||||
if (!m_ptr) {
|
||||
return alt;
|
||||
}
|
||||
return std::move(*m_ptr);
|
||||
}
|
||||
|
||||
constexpr T &operator*() & noexcept {
|
||||
return m_ptr;
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr const T &operator*() const & noexcept {
|
||||
return m_ptr;
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr T &&operator*() && noexcept {
|
||||
return m_ptr;
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr const T &&operator*() const && noexcept {
|
||||
return m_ptr;
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
constexpr T *operator->() noexcept {
|
||||
@ -163,7 +211,7 @@ class Optional {
|
||||
|
||||
template<typename T, std::size_t buffSize>
|
||||
template<typename... Args>
|
||||
constexpr Optional<T, buffSize>::Optional(Args &&... args) {
|
||||
constexpr Optional<T, buffSize>::Optional(ox::in_place_t, Args &&... args) {
|
||||
emplace(ox::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
30
deps/ox/src/ox/std/span.hpp
vendored
30
deps/ox/src/ox/std/span.hpp
vendored
@ -25,30 +25,32 @@ class SpanView {
|
||||
using value_type = T;
|
||||
using size_type = std::size_t;
|
||||
|
||||
template<typename RefType = T&, typename PtrType = T*, bool reverse = false>
|
||||
template<typename RefType = T const&, typename PtrType = T const*, bool reverse = false>
|
||||
using iterator = SpanIterator<T, RefType, PtrType, reverse>;
|
||||
|
||||
constexpr SpanView() noexcept {}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr SpanView(ox::Array<T, sz> const&a) noexcept:
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
m_items(a.data()),
|
||||
m_size(a.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz, typename Allocator>
|
||||
constexpr SpanView(ox::Vector<T, sz, Allocator> const&v) noexcept:
|
||||
m_items(v.data()),
|
||||
m_size(v.size()) {
|
||||
m_items(v.data()),
|
||||
m_size(v.size()) {
|
||||
}
|
||||
|
||||
template<std::size_t sz>
|
||||
constexpr SpanView(const T a[sz]) noexcept:
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
}
|
||||
|
||||
constexpr SpanView(const T *a, std::size_t sz) noexcept:
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
m_items(a),
|
||||
m_size(sz) {
|
||||
}
|
||||
|
||||
constexpr iterator<> begin() noexcept {
|
||||
@ -103,6 +105,11 @@ class SpanView {
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T const*data() const noexcept {
|
||||
return m_items;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t size() const noexcept {
|
||||
return m_size;
|
||||
@ -214,6 +221,11 @@ class Span {
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto data() const noexcept {
|
||||
return m_items;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t size() const noexcept {
|
||||
return m_size;
|
||||
|
3
deps/ox/src/ox/std/std.hpp
vendored
3
deps/ox/src/ox/std/std.hpp
vendored
@ -15,6 +15,8 @@
|
||||
#include "bstring.hpp"
|
||||
#include "byteswap.hpp"
|
||||
#include "concepts.hpp"
|
||||
#include "cstringview.hpp"
|
||||
#include "cstrops.hpp"
|
||||
#include "def.hpp"
|
||||
#include "defer.hpp"
|
||||
#include "defines.hpp"
|
||||
@ -37,6 +39,7 @@
|
||||
#include "stacktrace.hpp"
|
||||
#include "stddef.hpp"
|
||||
#include "string.hpp"
|
||||
#include "stringliteral.hpp"
|
||||
#include "stringview.hpp"
|
||||
#include "strongint.hpp"
|
||||
#include "strops.hpp"
|
||||
|
83
deps/ox/src/ox/std/string.hpp
vendored
83
deps/ox/src/ox/std/string.hpp
vendored
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 - 2022 gary@drinkingtea.net
|
||||
* Copyright 2015 - 2023 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(OX_USE_STDLIB)
|
||||
#if __has_include(<string>)
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
@ -32,15 +32,15 @@ class BasicString {
|
||||
|
||||
constexpr explicit BasicString(std::size_t cap) noexcept;
|
||||
|
||||
constexpr BasicString(const char *str) noexcept;
|
||||
constexpr explicit BasicString(const char *str) noexcept;
|
||||
|
||||
constexpr BasicString(const char8_t *str) noexcept;
|
||||
constexpr explicit BasicString(const char8_t *str) noexcept;
|
||||
|
||||
constexpr BasicString(const char *str, std::size_t size) noexcept;
|
||||
|
||||
constexpr explicit BasicString(CRStringView str) noexcept;
|
||||
|
||||
constexpr BasicString(const BasicString&) noexcept;
|
||||
constexpr explicit BasicString(BasicString const&) noexcept;
|
||||
|
||||
constexpr BasicString(BasicString&&) noexcept;
|
||||
|
||||
@ -130,7 +130,7 @@ class BasicString {
|
||||
|
||||
constexpr BasicString &operator+=(StringView src) noexcept;
|
||||
|
||||
constexpr BasicString &operator+=(const BasicString &src) noexcept;
|
||||
constexpr BasicString &operator+=(BasicString const&src) noexcept;
|
||||
|
||||
constexpr BasicString operator+(const char *str) const noexcept;
|
||||
|
||||
@ -142,23 +142,23 @@ class BasicString {
|
||||
|
||||
constexpr BasicString operator+(CRStringView src) const noexcept;
|
||||
|
||||
constexpr BasicString operator+(const BasicString &src) const noexcept;
|
||||
constexpr BasicString operator+(BasicString const&src) const noexcept;
|
||||
|
||||
constexpr bool operator==(const char *other) const noexcept;
|
||||
|
||||
constexpr bool operator==(const OxString_c auto &other) const noexcept;
|
||||
constexpr bool operator==(OxString_c auto const&other) const noexcept;
|
||||
|
||||
constexpr bool operator!=(const char *other) const noexcept;
|
||||
|
||||
constexpr bool operator!=(const OxString_c auto &other) const noexcept;
|
||||
constexpr bool operator!=(OxString_c auto const&other) const noexcept;
|
||||
|
||||
constexpr bool operator<(const BasicString &other) const noexcept;
|
||||
constexpr bool operator<(BasicString const&other) const noexcept;
|
||||
|
||||
constexpr bool operator>(const BasicString &other) const noexcept;
|
||||
constexpr bool operator>(BasicString const&other) const noexcept;
|
||||
|
||||
constexpr bool operator<=(const BasicString &other) const noexcept;
|
||||
constexpr bool operator<=(BasicString const&other) const noexcept;
|
||||
|
||||
constexpr bool operator>=(const BasicString &other) const noexcept;
|
||||
constexpr bool operator>=(BasicString const&other) const noexcept;
|
||||
|
||||
constexpr char operator[](std::size_t i) const noexcept;
|
||||
|
||||
@ -200,7 +200,7 @@ class BasicString {
|
||||
return c_str();
|
||||
}
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
#if __has_include(<string>)
|
||||
[[nodiscard]]
|
||||
inline std::string toStdString() const {
|
||||
return c_str();
|
||||
@ -225,19 +225,14 @@ class BasicString {
|
||||
constexpr std::size_t bytes() const noexcept;
|
||||
|
||||
private:
|
||||
template<std::size_t OtherSize>
|
||||
constexpr void set(const BasicString<OtherSize> &src) noexcept;
|
||||
|
||||
constexpr void set(CRStringView str) noexcept;
|
||||
|
||||
constexpr void set(const char *str) noexcept;
|
||||
|
||||
constexpr void set(const char8_t *str) noexcept;
|
||||
};
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString() noexcept {
|
||||
if (m_buff.size()) {
|
||||
if (!m_buff.empty()) {
|
||||
m_buff[0] = 0;
|
||||
} else {
|
||||
m_buff.push_back(0);
|
||||
@ -247,14 +242,14 @@ constexpr BasicString<SmallStringSize_v>::BasicString() noexcept {
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(std::size_t cap) noexcept: m_buff(cap + 1) {
|
||||
// GCC complains if you don't do this pretty unnecessary size check
|
||||
if (m_buff.size()) {
|
||||
if (!m_buff.empty()) {
|
||||
m_buff[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(const char *str) noexcept {
|
||||
if (m_buff.size()) {
|
||||
if (!m_buff.empty()) {
|
||||
m_buff[0] = 0;
|
||||
} else {
|
||||
m_buff.push_back(0);
|
||||
@ -264,7 +259,7 @@ constexpr BasicString<SmallStringSize_v>::BasicString(const char *str) noexcept
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(const char8_t *str) noexcept {
|
||||
if (m_buff.size()) {
|
||||
if (!m_buff.empty()) {
|
||||
m_buff[0] = 0;
|
||||
} else {
|
||||
m_buff.push_back(0);
|
||||
@ -388,7 +383,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(const BasicString &src) noexcept {
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(BasicString const&src) noexcept {
|
||||
oxIgnoreError(append(src.c_str(), src.len()));
|
||||
return *this;
|
||||
}
|
||||
@ -436,7 +431,7 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(const BasicString &src) const noexcept {
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(BasicString const&src) const noexcept {
|
||||
const std::size_t strLen = src.len();
|
||||
const auto currentLen = len();
|
||||
BasicString<SmallStringSize_v> cpy(currentLen + strLen);
|
||||
@ -459,7 +454,7 @@ constexpr bool BasicString<SmallStringSize_v>::operator==(const char *other) con
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator==(const OxString_c auto &other) const noexcept {
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator==(OxString_c auto const&other) const noexcept {
|
||||
return ox::StringView(*this) == ox::StringView(other);
|
||||
}
|
||||
|
||||
@ -469,27 +464,27 @@ constexpr bool BasicString<SmallStringSize_v>::operator!=(const char *other) con
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator!=(const OxString_c auto &other) const noexcept {
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator!=(OxString_c auto const&other) const noexcept {
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator<(const BasicString &other) const noexcept {
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator<(BasicString const&other) const noexcept {
|
||||
return ox_strcmp(c_str(), other.c_str()) < 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator>(const BasicString &other) const noexcept {
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator>(BasicString const&other) const noexcept {
|
||||
return ox_strcmp(c_str(), other.c_str()) > 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator<=(const BasicString &other) const noexcept {
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator<=(BasicString const&other) const noexcept {
|
||||
return ox_strcmp(c_str(), other.c_str()) < 1;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator>=(const BasicString &other) const noexcept {
|
||||
constexpr bool BasicString<SmallStringSize_v>::operator>=(BasicString const&other) const noexcept {
|
||||
return ox_strcmp(c_str(), other.c_str()) > -1;
|
||||
}
|
||||
|
||||
@ -543,31 +538,14 @@ constexpr std::size_t BasicString<SmallStringSize_v>::len() const noexcept {
|
||||
return length;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
template<std::size_t OtherSize>
|
||||
constexpr void BasicString<SmallStringSize_v>::set(const BasicString<OtherSize> &src) noexcept {
|
||||
std::size_t strBytes = src.bytes();
|
||||
m_buff.resize(strBytes);
|
||||
copy_n(src.begin(), strBytes, m_buff.data());
|
||||
*m_buff.back().value = 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr void BasicString<SmallStringSize_v>::set(CRStringView str) noexcept {
|
||||
std::size_t strBytes = str.bytes();
|
||||
std::size_t const strBytes = str.bytes();
|
||||
m_buff.resize(strBytes + 1);
|
||||
copy_n(str.data(), strBytes, m_buff.data());
|
||||
*m_buff.back().value = 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr void BasicString<SmallStringSize_v>::set(const char *str) noexcept {
|
||||
std::size_t strBytes = ox_strlen(str) + 1;
|
||||
m_buff.resize(strBytes);
|
||||
copy_n(str, strBytes, m_buff.data());
|
||||
*m_buff.back().value = 0;
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr void BasicString<SmallStringSize_v>::set(const char8_t *str) noexcept {
|
||||
std::size_t strBytes = ox_strlen(str) + 1;
|
||||
@ -581,6 +559,13 @@ extern template class BasicString<8>;
|
||||
using String = BasicString<8>;
|
||||
using CRString = String const&;
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::String toString(ox::CRStringView sv) noexcept {
|
||||
return ox::String(sv);
|
||||
}
|
||||
|
||||
|
||||
template<typename PlatSpec, std::size_t SmallStringSize_v>
|
||||
[[nodiscard]]
|
||||
constexpr auto sizeOf(const ox::BasicString<SmallStringSize_v>*) noexcept {
|
||||
|
4
deps/ox/src/ox/std/stringliteral.hpp
vendored
4
deps/ox/src/ox/std/stringliteral.hpp
vendored
@ -41,6 +41,10 @@ class StringLiteral: public detail::BaseStringView {
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const char *c_str() const noexcept {
|
||||
return data();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
89
deps/ox/src/ox/std/stringview.hpp
vendored
89
deps/ox/src/ox/std/stringview.hpp
vendored
@ -12,12 +12,9 @@
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
#include "bit.hpp"
|
||||
#include "concepts.hpp"
|
||||
#include "iterator.hpp"
|
||||
#include "stringliteral.hpp"
|
||||
#include "strops.hpp"
|
||||
#include "vector.hpp"
|
||||
#include "basestringview.hpp"
|
||||
#include "cstrops.hpp"
|
||||
#include "writer.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
@ -89,70 +86,6 @@ constexpr auto operator<=>(CRStringView s1, CRStringView s2) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool beginsWith(CRStringView base, CRStringView beginning) noexcept {
|
||||
const auto beginningLen = ox::min(beginning.len(), base.len());
|
||||
return base.len() >= beginning.len() && ox_strncmp(base.data(), beginning, beginningLen) == 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept {
|
||||
const auto endingLen = ending.len();
|
||||
return base.len() >= endingLen && ox_strcmp(base.data() + (base.len() - endingLen), ending) == 0;
|
||||
}
|
||||
|
||||
constexpr std::size_t find(CRStringView str, char search) noexcept {
|
||||
std::size_t i = 0;
|
||||
for (; i < str.len(); ++i) {
|
||||
if (str[i] == search) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
constexpr std::size_t find(CRStringView str, CRStringView search) noexcept {
|
||||
std::size_t i = 0;
|
||||
for (; i < str.len(); ++i) {
|
||||
if (beginsWith(substr(str, i), search)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
template<std::size_t smallSz = 0>
|
||||
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, char del) noexcept {
|
||||
ox::Vector<ox::StringView, smallSz> out;
|
||||
constexpr auto nextSeg = [](CRStringView current, char del) {
|
||||
return substr(current, find(current, del) + 1);
|
||||
};
|
||||
for (auto current = str; current.len(); current = nextSeg(current, del)) {
|
||||
const auto next = find(current, del);
|
||||
if (const auto s = substr(current, 0, next); s.len()) {
|
||||
out.emplace_back(s);
|
||||
}
|
||||
current = substr(current, next);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template<std::size_t smallSz = 0>
|
||||
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, CRStringView del) noexcept {
|
||||
ox::Vector<ox::StringView, smallSz> out;
|
||||
constexpr auto nextSeg = [](CRStringView current, CRStringView del) {
|
||||
return substr(current, find(current, del) + del.len());
|
||||
};
|
||||
for (auto current = str; current.len(); current = nextSeg(current, del)) {
|
||||
const auto next = find(current, del);
|
||||
if (const auto s = substr(current, 0, next); s.len()) {
|
||||
out.emplace_back(s);
|
||||
}
|
||||
current = substr(current, next);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
constexpr auto write(Writer_c auto &writer, ox::CRStringView sv) noexcept {
|
||||
return writer.write(sv.data(), sv.bytes());
|
||||
}
|
||||
@ -163,6 +96,22 @@ constexpr auto toStdStringView(CRStringView sv) noexcept {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Maybe StringView. If T is a string type, MaybeType::type/MaybeSV_t is a
|
||||
// StringView. This avoids creating unnecessary Strings when taking a
|
||||
// StringView or C string as a function argument.
|
||||
template<typename T, bool isStr = isOxString_v<T>>
|
||||
struct MaybeSV {
|
||||
using type = T;
|
||||
};
|
||||
template<typename T>
|
||||
struct MaybeSV<T, true> {
|
||||
using type = ox::StringView;
|
||||
};
|
||||
template<typename T>
|
||||
using MaybeSV_t = typename MaybeSV<T>::type;
|
||||
|
||||
|
||||
}
|
||||
|
||||
constexpr ox::Result<int> ox_atoi(ox::CRStringView str) noexcept {
|
||||
|
226
deps/ox/src/ox/std/strops.hpp
vendored
226
deps/ox/src/ox/std/strops.hpp
vendored
@ -8,130 +8,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "concepts.hpp"
|
||||
#include "cstrops.hpp"
|
||||
#include "error.hpp"
|
||||
#include "math.hpp"
|
||||
#include "stringview.hpp"
|
||||
#include "types.hpp"
|
||||
#include "typetraits.hpp"
|
||||
#include "vector.hpp"
|
||||
#include "writer.hpp"
|
||||
|
||||
template<typename T1, typename T2>
|
||||
constexpr T1 ox_strcpy(T1 dest, T2 src) noexcept {
|
||||
using T1Type = typename ox::remove_reference<decltype(dest[0])>::type;
|
||||
std::size_t i = 0;
|
||||
while (src[i]) {
|
||||
dest[i] = static_cast<T1Type>(src[i]);
|
||||
++i;
|
||||
}
|
||||
// set null terminator
|
||||
dest[i] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
constexpr T1 ox_strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
|
||||
using T1Type = typename ox::remove_reference<decltype(dest[0])>::type;
|
||||
std::size_t i = 0;
|
||||
while (i < maxLen && src[i]) {
|
||||
dest[i] = static_cast<T1Type>(src[i]);
|
||||
++i;
|
||||
}
|
||||
// set null terminator
|
||||
dest[i] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto ox_strnlen(const char *str1, std::size_t maxLen) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; len < maxLen && str1[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]]
|
||||
constexpr auto ox_strlen(T str1) noexcept {
|
||||
std::size_t len = 0;
|
||||
for (; str1[len]; len++);
|
||||
return len;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
[[nodiscard]]
|
||||
constexpr int ox_strcmp(const T1 &str1, const T2 &str2) noexcept {
|
||||
auto retval = 0;
|
||||
auto i = 0u;
|
||||
while (str1[i] || str2[i]) {
|
||||
if (str1[i] < str2[i]) {
|
||||
retval = -1;
|
||||
break;
|
||||
} else if (str1[i] > str2[i]) {
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
[[nodiscard]]
|
||||
constexpr int ox_strncmp(T1 str1, T2 str2, const std::size_t maxLen) noexcept {
|
||||
auto retval = 0;
|
||||
std::size_t i = 0;
|
||||
while (i < maxLen && (str1[i] || str2[i])) {
|
||||
if (str1[i] < str2[i]) {
|
||||
retval = -1;
|
||||
break;
|
||||
} else if (str1[i] > str2[i]) {
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const char *ox_strchr(const char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
for (std::size_t i = 0; i <= maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
} else if (str[i] == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
for (std::size_t i = 0; i < maxLen; i++) {
|
||||
if (str[i] == character) {
|
||||
return &str[i];
|
||||
} else if (str[i] == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int ox_lastIndexOf(const auto &str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept {
|
||||
int retval = -1;
|
||||
for (std::size_t i = 0; i < maxLen && str[i]; i++) {
|
||||
if (str[i] == character) {
|
||||
retval = static_cast<int>(i);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
namespace ox {
|
||||
|
||||
template<OxString_c Str>
|
||||
[[nodiscard]]
|
||||
constexpr Str substr(Str const&str, std::size_t pos) noexcept {
|
||||
constexpr ox::StringView substr(Str const&str, std::size_t pos) noexcept {
|
||||
if (str.len() >= pos) {
|
||||
return Str(str.data() + pos, str.len() - pos);
|
||||
}
|
||||
@ -140,7 +29,7 @@ constexpr Str substr(Str const&str, std::size_t pos) noexcept {
|
||||
|
||||
template<OxString_c Str>
|
||||
[[nodiscard]]
|
||||
constexpr Str substr(Str const&str, std::size_t start, std::size_t end) noexcept {
|
||||
constexpr ox::StringView substr(Str const&str, std::size_t start, std::size_t end) noexcept {
|
||||
if (str.len() >= start && end >= start) {
|
||||
return Str(str.data() + start, end - start);
|
||||
}
|
||||
@ -179,38 +68,79 @@ constexpr ox::Error itoa(Integer v, ox::Writer_c auto &writer) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool beginsWith(CRStringView base, CRStringView beginning) noexcept {
|
||||
const auto beginningLen = ox::min(beginning.len(), base.len());
|
||||
return base.len() >= beginning.len() && ox_strncmp(base.data(), beginning, beginningLen) == 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept {
|
||||
const auto endingLen = ending.len();
|
||||
return base.len() >= endingLen && ox_strcmp(base.data() + (base.len() - endingLen), ending) == 0;
|
||||
}
|
||||
|
||||
constexpr std::size_t find(CRStringView str, char search) noexcept {
|
||||
std::size_t i = 0;
|
||||
for (; i < str.len(); ++i) {
|
||||
if (str[i] == search) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
constexpr std::size_t find(CRStringView str, CRStringView search) noexcept {
|
||||
std::size_t i = 0;
|
||||
for (; i < str.len(); ++i) {
|
||||
if (beginsWith(substr(str, i), search)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
template<std::size_t smallSz = 0>
|
||||
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, char del) noexcept {
|
||||
ox::Vector<ox::StringView, smallSz> out;
|
||||
constexpr auto nextSeg = [](CRStringView current, char del) {
|
||||
return substr(current, find(current, del) + 1);
|
||||
};
|
||||
for (auto current = str; current.len(); current = nextSeg(current, del)) {
|
||||
const auto next = find(current, del);
|
||||
if (const auto s = substr(current, 0, next); s.len()) {
|
||||
out.emplace_back(s);
|
||||
}
|
||||
current = substr(current, next);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
template<std::size_t smallSz = 0>
|
||||
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, CRStringView del) noexcept {
|
||||
ox::Vector<ox::StringView, smallSz> out;
|
||||
constexpr auto nextSeg = [](CRStringView current, CRStringView del) {
|
||||
return substr(current, find(current, del) + del.len());
|
||||
};
|
||||
for (auto current = str; current.len(); current = nextSeg(current, del)) {
|
||||
const auto next = find(current, del);
|
||||
if (const auto s = substr(current, 0, next); s.len()) {
|
||||
out.emplace_back(s);
|
||||
}
|
||||
current = substr(current, next);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<std::size_t> lastIndexOf(ox::CRStringView str, int character) noexcept {
|
||||
ox::Result<std::size_t> retval = OxError(1, "Character not found");
|
||||
for (auto i = static_cast<int>(str.bytes() - 1); i >= 0; --i) {
|
||||
if (str[static_cast<std::size_t>(i)] == character) {
|
||||
retval = static_cast<std::size_t>(i);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
template<typename Integer, typename T>
|
||||
constexpr T ox_itoa(Integer v, T str) noexcept {
|
||||
if (v) {
|
||||
ox::ResizedInt_t<Integer, 64> mod = 1000000000000000000;
|
||||
ox::ResizedInt_t<Integer, 64> val = v;
|
||||
constexpr auto base = 10;
|
||||
auto it = 0;
|
||||
if (val < 0) {
|
||||
str[static_cast<std::size_t>(it)] = '-';
|
||||
it++;
|
||||
}
|
||||
while (mod) {
|
||||
auto digit = val / mod;
|
||||
val %= mod;
|
||||
mod /= base;
|
||||
if (it || digit) {
|
||||
ox::ResizedInt_t<Integer, 64> start = '0';
|
||||
if (digit >= 10) {
|
||||
start = 'a';
|
||||
digit -= 10;
|
||||
}
|
||||
str[static_cast<std::size_t>(it)] = static_cast<typename ox::remove_reference<decltype(str[0])>::type>(start + digit);
|
||||
it++;
|
||||
}
|
||||
}
|
||||
str[static_cast<std::size_t>(it)] = 0;
|
||||
} else {
|
||||
// 0 is a special case
|
||||
str[0] = '0';
|
||||
str[1] = 0;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
19
deps/ox/src/ox/std/test/tests.cpp
vendored
19
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -12,7 +12,7 @@
|
||||
#include <ox/std/uuid.hpp>
|
||||
#include <ox/std/std.hpp>
|
||||
|
||||
static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
{
|
||||
"malloc",
|
||||
[] {
|
||||
@ -117,6 +117,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
[] {
|
||||
ox::Vector<int> v;
|
||||
oxAssert(v.size() == 0, "Initial Vector size not 0");
|
||||
oxAssert(v.empty(), "Vector::empty() is broken");
|
||||
auto insertTest = [&v](int val, [[maybe_unused]] std::size_t size) {
|
||||
v.push_back(val);
|
||||
oxReturnError(OxError(v.size() != size, "Vector size incorrect"));
|
||||
@ -172,7 +173,7 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
oxAssert(w.write("aoeu", 4), "write failed");
|
||||
oxExpect(b.size(), 8u);
|
||||
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeu");
|
||||
ox::StringView qwerty = "qwerty";
|
||||
ox::StringView constexpr qwerty = "qwerty";
|
||||
oxAssert(w.write(qwerty.data(), qwerty.bytes()), "write failed");
|
||||
oxExpect(b.size(), 14u);
|
||||
oxExpect(ox::StringView(b.data(), b.size()), "asdfaoeuqwerty");
|
||||
@ -313,12 +314,14 @@ static std::map<ox::String, ox::Error(*)()> tests = {
|
||||
};
|
||||
|
||||
int main(int argc, const char **args) {
|
||||
if (argc > 1) {
|
||||
auto testName = args[1];
|
||||
if (tests.find(testName) != tests.end()) {
|
||||
oxAssert(tests[testName](), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
if (argc < 2) {
|
||||
oxError("Must specify test to run");
|
||||
}
|
||||
auto const testName = args[1];
|
||||
auto const func = tests.find(testName);
|
||||
if (func != tests.end()) {
|
||||
oxAssert(func->second(), "Test returned Error");
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
42
deps/ox/src/ox/std/trace.hpp
vendored
42
deps/ox/src/ox/std/trace.hpp
vendored
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 - 2022 gary@drinkingtea.net
|
||||
* Copyright 2015 - 2023 gary@drinkingtea.net
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@ -39,10 +39,10 @@ enum class MsgId: char {
|
||||
struct TraceMsgRcv {
|
||||
static constexpr auto TypeName = "net.drinkingtea.ox.trace.TraceMsg";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
BasicString<50> file = "";
|
||||
BasicString<50> file{""};
|
||||
int line = 0;
|
||||
uint64_t time = 0;
|
||||
BasicString<50> ch = "";
|
||||
BasicString<50> ch{""};
|
||||
BasicString<100> msg;
|
||||
};
|
||||
|
||||
@ -141,39 +141,22 @@ class OutStream {
|
||||
m_msg.msg = msg;
|
||||
}
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
template<std::size_t fmtSegmentCnt, typename ...Args>
|
||||
constexpr OutStream(const char *file, int line, const char *ch, detail::Fmt<fmtSegmentCnt> fmtSegments, std::array<detail::FmtArg, fmtSegmentCnt - 1> elements) noexcept {
|
||||
//static_assert(sizeof...(args) == fmtSegmentCnt - 1, "Wrong number of trace arguments for format.");
|
||||
constexpr OutStream(const char *file, int line, const char *ch, detail::Fmt<fmtSegmentCnt> fmtSegments, Args const&...elements) noexcept {
|
||||
static_assert(sizeof...(elements) == fmtSegmentCnt - 1, "Wrong number of trace arguments for format.");
|
||||
m_msg.file = file;
|
||||
m_msg.line = line;
|
||||
m_msg.ch = ch;
|
||||
const auto &firstSegment = fmtSegments.segments[0];
|
||||
oxIgnoreError(m_msg.msg.append(firstSegment.str, firstSegment.length));
|
||||
//const detail::FmtArg elements[sizeof...(args)] = {args...};
|
||||
for (size_t i = 0; i < fmtSegments.size - 1; ++i) {
|
||||
m_msg.msg += elements[i].out;
|
||||
for (size_t i = 0; auto const&e : std::initializer_list<detail::FmtArg>{elements...}) {
|
||||
m_msg.msg += e.out;
|
||||
const auto &s = fmtSegments.segments[i + 1];
|
||||
oxIgnoreError(m_msg.msg.append(s.str, s.length));
|
||||
++i;
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<std::size_t fmtSegmentCnt, typename ...Args>
|
||||
constexpr OutStream(const char *file, int line, const char *ch, detail::Fmt<fmtSegmentCnt> fmtSegments, Args... args) noexcept {
|
||||
//static_assert(sizeof...(args) == fmtSegmentCnt - 1, "Wrong number of trace arguments for format.");
|
||||
m_msg.file = file;
|
||||
m_msg.line = line;
|
||||
m_msg.ch = ch;
|
||||
const auto &firstSegment = fmtSegments.segments[0];
|
||||
oxIgnoreError(m_msg.msg.append(firstSegment.str, firstSegment.length));
|
||||
const detail::FmtArg elements[sizeof...(args)] = {args...};
|
||||
for (auto i = 0u; i < fmtSegments.size - 1; ++i) {
|
||||
m_msg.msg += elements[i].out;
|
||||
const auto &s = fmtSegments.segments[i + 1];
|
||||
oxIgnoreError(m_msg.msg.append(s.str, s.length));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
inline ~OutStream() noexcept {
|
||||
oxTraceHook(m_msg.file, m_msg.line, m_msg.ch, m_msg.msg.c_str());
|
||||
@ -257,15 +240,10 @@ class NullStream {
|
||||
constexpr NullStream(const char*, int, const char*, const char* = "") noexcept {
|
||||
}
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
template<std::size_t fmtSegmentCnt, typename ...Args>
|
||||
constexpr NullStream(const char*, int, const char*, detail::Fmt<fmtSegmentCnt>, std::array<detail::FmtArg, fmtSegmentCnt - 1>) noexcept {
|
||||
constexpr NullStream(const char*, int, const char*, detail::Fmt<fmtSegmentCnt>, Args const&...elements) noexcept {
|
||||
static_assert(sizeof...(elements) == fmtSegmentCnt - 1, "Wrong number of trace arguments for format.");
|
||||
}
|
||||
#else
|
||||
template<std::size_t fmtSegmentCnt, typename ...Args>
|
||||
constexpr NullStream(const char*, int, const char*, detail::Fmt<fmtSegmentCnt>, Args...) noexcept {
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
constexpr const NullStream &operator<<(const T&) const noexcept {
|
||||
|
2
deps/ox/src/ox/std/types.hpp
vendored
2
deps/ox/src/ox/std/types.hpp
vendored
@ -159,6 +159,8 @@ struct ResizedInt<T, bits, false> {
|
||||
template<typename T, std::size_t bits>
|
||||
using ResizedInt_t = typename ResizedInt<T, bits>::type;
|
||||
|
||||
using ssize_t = Signed<std::size_t>;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
5
deps/ox/src/ox/std/typetraits.hpp
vendored
5
deps/ox/src/ox/std/typetraits.hpp
vendored
@ -273,6 +273,7 @@ template<std::size_t SmallStringSize>
|
||||
class BasicString;
|
||||
template<std::size_t sz>
|
||||
class BString;
|
||||
class CStringView;
|
||||
class StringLiteral;
|
||||
class StringView;
|
||||
|
||||
@ -292,6 +293,10 @@ constexpr auto isOxString(const BString<sz>*) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
constexpr auto isOxString(const CStringView*) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
constexpr auto isOxString(const StringLiteral*) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
6
deps/ox/src/ox/std/utility.hpp
vendored
6
deps/ox/src/ox/std/utility.hpp
vendored
@ -12,6 +12,12 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
struct in_place_t {
|
||||
explicit constexpr in_place_t() = default;
|
||||
};
|
||||
|
||||
inline constexpr ox::in_place_t in_place;
|
||||
|
||||
template<class T>
|
||||
constexpr T &&forward(remove_reference_t<T> &t) noexcept {
|
||||
return static_cast<T&&>(t);
|
||||
|
29
deps/ox/src/ox/std/vector.hpp
vendored
29
deps/ox/src/ox/std/vector.hpp
vendored
@ -16,7 +16,7 @@
|
||||
#include "iterator.hpp"
|
||||
#include "math.hpp"
|
||||
#include "memory.hpp"
|
||||
#include "new.hpp"
|
||||
#include "stringview.hpp"
|
||||
#include "types.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
@ -254,12 +254,12 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool contains(const T&) const noexcept(useNoexcept);
|
||||
constexpr bool contains(MaybeSV_t<T> const&) const noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(
|
||||
std::size_t pos, std::size_t cnt, const T &val) noexcept(useNoexcept);
|
||||
std::size_t pos, std::size_t cnt, MaybeSV_t<T> const&val) noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, const T &val) noexcept(useNoexcept);
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, MaybeSV_t<T> const&val) noexcept(useNoexcept);
|
||||
|
||||
template<typename... Args>
|
||||
constexpr iterator<T&, T*, false> emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept);
|
||||
@ -267,7 +267,9 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
template<typename... Args>
|
||||
constexpr T &emplace_back(Args&&... args) noexcept(useNoexcept);
|
||||
|
||||
constexpr void push_back(const T &item) noexcept(useNoexcept);
|
||||
constexpr void push_back(T &&item) noexcept(useNoexcept);
|
||||
|
||||
constexpr void push_back(MaybeSV_t<T> const&item) noexcept(useNoexcept);
|
||||
|
||||
constexpr void pop_back() noexcept(useNoexcept);
|
||||
|
||||
@ -484,7 +486,7 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::resize(std::size_t size) n
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(const T &v) const noexcept(useNoexcept) {
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeSV_t<T> const&v) const noexcept(useNoexcept) {
|
||||
for (std::size_t i = 0; i < m_size; i++) {
|
||||
if (m_items[i] == v) {
|
||||
return true;
|
||||
@ -496,7 +498,7 @@ constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(const T &v) const
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
std::size_t pos, std::size_t cnt, const T &val) noexcept(useNoexcept) {
|
||||
std::size_t pos, std::size_t cnt, MaybeSV_t<T> const&val) noexcept(useNoexcept) {
|
||||
if (m_size + cnt > m_cap) {
|
||||
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
|
||||
if (pos < m_size) {
|
||||
@ -524,7 +526,7 @@ Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, const T &val) noexcept(useNoexcept) {
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, MaybeSV_t<T> const&val) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
|
||||
if (pos < m_size) {
|
||||
@ -581,7 +583,16 @@ constexpr T &Vector<T, SmallVectorSize, Allocator>::emplace_back(Args&&... args)
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(const T &item) noexcept(useNoexcept) {
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(T &&item) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserve(m_cap ? m_cap * 2 : initialCap);
|
||||
}
|
||||
std::construct_at(&m_items[m_size], std::move(item));
|
||||
++m_size;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(MaybeSV_t<T> const&item) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserve(m_cap ? m_cap * 2 : initialCap);
|
||||
}
|
||||
|
2
deps/teagba/CMakeLists.txt
vendored
2
deps/teagba/CMakeLists.txt
vendored
@ -1,3 +1,5 @@
|
||||
project(TeaGBA ASM CXX)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
install(
|
||||
|
6
deps/teagba/include/teagba/addresses.hpp
vendored
6
deps/teagba/include/teagba/addresses.hpp
vendored
@ -49,7 +49,7 @@ using BgCtl = uint16_t;
|
||||
#define REG_BG3CTL *reinterpret_cast<volatile BgCtl*>(0x0400'000e)
|
||||
|
||||
[[nodiscard]]
|
||||
inline auto ®BgCtl(uintptr_t bgIdx) noexcept {
|
||||
inline volatile BgCtl ®BgCtl(uintptr_t bgIdx) noexcept {
|
||||
return *reinterpret_cast<volatile BgCtl*>(0x0400'0008 + 2 * bgIdx);
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ inline auto ®BgCtl(uintptr_t bgIdx) noexcept {
|
||||
#define REG_BG3HOFS *reinterpret_cast<volatile uint32_t*>(0x0400'001c)
|
||||
|
||||
[[nodiscard]]
|
||||
inline volatile auto ®BgHofs(auto bgIdx) noexcept {
|
||||
inline volatile uint32_t ®BgHofs(auto bgIdx) noexcept {
|
||||
return *reinterpret_cast<volatile uint32_t*>(0x0400'0010 + 4 * bgIdx);
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ inline volatile auto ®BgHofs(auto bgIdx) noexcept {
|
||||
#define REG_BG3VOFS *reinterpret_cast<volatile uint32_t*>(0x0400'001e)
|
||||
|
||||
[[nodiscard]]
|
||||
inline volatile auto ®BgVofs(auto bgIdx) noexcept {
|
||||
inline volatile uint32_t ®BgVofs(auto bgIdx) noexcept {
|
||||
return *reinterpret_cast<volatile uint32_t*>(0x0400'0012 + 4 * bgIdx);
|
||||
}
|
||||
|
||||
|
12
deps/teagba/include/teagba/gfx.hpp
vendored
12
deps/teagba/include/teagba/gfx.hpp
vendored
@ -29,15 +29,13 @@ enum DispCtl {
|
||||
};
|
||||
|
||||
struct OX_ALIGN8 GbaSpriteAttrUpdate {
|
||||
uint16_t attr0 = 0;
|
||||
uint16_t attr1 = 0;
|
||||
uint16_t attr2 = 0;
|
||||
uint16_t idx = 0;
|
||||
|
||||
uint16_t attr0 = 0;
|
||||
uint16_t attr1 = 0;
|
||||
uint16_t attr2 = 0;
|
||||
uint16_t idx = 0;
|
||||
};
|
||||
|
||||
extern volatile uint16_t g_spriteUpdates;
|
||||
extern ox::Array<GbaSpriteAttrUpdate, 128> g_spriteBuffer;
|
||||
GbaSpriteAttrUpdate &spriteAttr(size_t i) noexcept;
|
||||
|
||||
void addSpriteUpdate(const GbaSpriteAttrUpdate &upd) noexcept;
|
||||
|
||||
|
35
deps/teagba/include/teagba/registers.hpp
vendored
35
deps/teagba/include/teagba/registers.hpp
vendored
@ -8,8 +8,8 @@
|
||||
|
||||
namespace teagba {
|
||||
|
||||
inline auto bgSetSbb(volatile BgCtl *bgCtl, unsigned sbb) noexcept {
|
||||
*bgCtl = static_cast<BgCtl>(*bgCtl & ~0b11111'0000'0000u) | static_cast<BgCtl>(sbb << 8);
|
||||
inline auto bgSetSbb(volatile BgCtl &bgCtl, unsigned sbb) noexcept {
|
||||
bgCtl = static_cast<BgCtl>(bgCtl & ~0b11111'0000'0000u) | static_cast<BgCtl>(sbb << 8);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@ -17,14 +17,9 @@ constexpr unsigned bgPri(BgCtl bgCtl) noexcept {
|
||||
return bgCtl & 1;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline auto bgPri(const volatile BgCtl *bgCtl) noexcept {
|
||||
return bgPri(*bgCtl);
|
||||
}
|
||||
|
||||
inline auto bgSetPri(volatile BgCtl *bgCtl, unsigned pri) noexcept {
|
||||
inline auto bgSetPri(volatile BgCtl &bgCtl, unsigned pri) noexcept {
|
||||
pri = pri & 0b1;
|
||||
*bgCtl = static_cast<BgCtl>(*bgCtl & ~0b1u) | static_cast<BgCtl>(pri << 0);
|
||||
bgCtl = static_cast<BgCtl>(bgCtl & ~0b1u) | static_cast<BgCtl>(pri << 0);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@ -32,17 +27,12 @@ constexpr unsigned bgBpp(BgCtl bgCtl) noexcept {
|
||||
return ((bgCtl >> 7) & 1) ? 8 : 4;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline auto bgBpp(const volatile BgCtl *bgCtl) noexcept {
|
||||
return bgBpp(*bgCtl);
|
||||
}
|
||||
|
||||
inline auto bgSetBpp(volatile BgCtl *bgCtl, unsigned bpp) noexcept {
|
||||
inline auto bgSetBpp(volatile BgCtl &bgCtl, unsigned bpp) noexcept {
|
||||
constexpr auto Bpp8 = 1 << 7;
|
||||
if (bpp == 4) {
|
||||
*bgCtl = *bgCtl | ((*bgCtl | Bpp8) ^ Bpp8); // set to use 4 bits per pixel
|
||||
bgCtl = bgCtl | ((bgCtl | Bpp8) ^ Bpp8); // set to use 4 bits per pixel
|
||||
} else {
|
||||
*bgCtl = *bgCtl | Bpp8; // set to use 8 bits per pixel
|
||||
bgCtl = bgCtl | Bpp8; // set to use 8 bits per pixel
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,19 +41,14 @@ constexpr auto bgCbb(BgCtl bgCtl) noexcept {
|
||||
return (bgCtl >> 2) & 0b11u;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline auto bgCbb(const volatile BgCtl *bgCtl) noexcept {
|
||||
return bgCbb(*bgCtl);
|
||||
}
|
||||
|
||||
inline auto bgSetCbb(volatile BgCtl *bgCtl, unsigned cbb) noexcept {
|
||||
inline auto bgSetCbb(volatile BgCtl &bgCtl, unsigned cbb) noexcept {
|
||||
cbb = cbb & 0b11;
|
||||
*bgCtl = static_cast<BgCtl>(*bgCtl & ~0b1100u) | static_cast<BgCtl>(cbb << 2);
|
||||
bgCtl = static_cast<BgCtl>(bgCtl & ~0b1100u) | static_cast<BgCtl>(cbb << 2);
|
||||
}
|
||||
|
||||
constexpr void iterateBgCtl(auto cb) noexcept {
|
||||
for (auto bgCtl = ®_BG0CTL; bgCtl <= ®_BG3CTL; bgCtl += 2) {
|
||||
cb(bgCtl);
|
||||
cb(*bgCtl);
|
||||
}
|
||||
}
|
||||
|
||||
|
2
deps/teagba/src/CMakeLists.txt
vendored
2
deps/teagba/src/CMakeLists.txt
vendored
@ -6,7 +6,7 @@ add_library(
|
||||
gfx.cpp
|
||||
)
|
||||
|
||||
if(TURBINE_BUILD_TYPE STREQUAL "GBA")
|
||||
if(BUILDCORE_TARGET STREQUAL "gba")
|
||||
set_source_files_properties(gfx.cpp PROPERTIES COMPILE_FLAGS -marm)
|
||||
target_sources(
|
||||
TeaGBA PRIVATE
|
||||
|
24
deps/teagba/src/gfx.cpp
vendored
24
deps/teagba/src/gfx.cpp
vendored
@ -10,30 +10,22 @@
|
||||
|
||||
namespace teagba {
|
||||
|
||||
volatile uint16_t g_spriteUpdates = 0;
|
||||
ox::Array<GbaSpriteAttrUpdate, 128> g_spriteBuffer;
|
||||
static ox::Array<GbaSpriteAttrUpdate, 128> g_spriteBuffer;
|
||||
|
||||
GbaSpriteAttrUpdate &spriteAttr(size_t i) noexcept {
|
||||
return g_spriteBuffer[i];
|
||||
}
|
||||
|
||||
void addSpriteUpdate(const GbaSpriteAttrUpdate &upd) noexcept {
|
||||
// block until g_spriteUpdates is less than buffer len
|
||||
if (g_spriteUpdates >= g_spriteBuffer.size()) [[unlikely]] {
|
||||
teagba_vblankintrwait();
|
||||
}
|
||||
const auto ie = REG_IE; // disable vblank interrupt handler
|
||||
REG_IE = REG_IE & static_cast<uint16_t>(~teagba::Int_vblank); // disable vblank interrupt handler
|
||||
const auto updateCnt = g_spriteUpdates;
|
||||
g_spriteBuffer[updateCnt] = upd;
|
||||
g_spriteUpdates = updateCnt + 1;
|
||||
g_spriteBuffer[upd.idx] = upd;
|
||||
REG_IE = ie; // enable vblank interrupt handler
|
||||
}
|
||||
|
||||
void applySpriteUpdates() noexcept {
|
||||
// copy g_spriteUpdates to allow it to use a register instead of reading
|
||||
// from memory every iteration of the loop, needed because g_spriteUpdates
|
||||
// is volatile
|
||||
const unsigned updates = g_spriteUpdates;
|
||||
for (unsigned i = 0; i < updates; ++i) {
|
||||
const auto &oa = g_spriteBuffer[i];
|
||||
MEM_OAM[oa.idx] = *reinterpret_cast<const uint64_t*>(&oa);
|
||||
for (auto const&oa : g_spriteBuffer) {
|
||||
MEM_OAM[oa.idx] = std::bit_cast<uint64_t>(oa);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,6 @@ All components have a platform indicator next to them:
|
||||
(-G) - GBA
|
||||
(P-) - PC
|
||||
|
||||
* GlUtils - OpenGL helpers (P-)
|
||||
* Keel - asset management system (PG)
|
||||
* Turbine - platform abstraction and user I/O (PG)
|
||||
* gba - GBA implementation (PG)
|
||||
* glfw - GLFW implementation (P-)
|
||||
* Studio - where most of the studio code lives as library (P-)
|
||||
* applib - used for per project studio executables
|
||||
* modlib - used for studio modules to interact with studio
|
||||
* Nostalgia
|
||||
* modules
|
||||
* core - graphics system for Nostalgia (PG)
|
||||
@ -42,6 +34,15 @@ All components have a platform indicator next to them:
|
||||
* studio - makes the games (P-)
|
||||
* tools - command line tools (P-)
|
||||
* pack - packs a studio project directory into an OxFS file (P-)
|
||||
* Olympic
|
||||
* Applib - Library for creating apps as libraries that injects Keel and Studio modules
|
||||
* Keel - asset management system (PG)
|
||||
* Studio - where most of the studio code lives as library (P-)
|
||||
* applib - used for per project studio executables
|
||||
* modlib - used for studio modules to interact with studio
|
||||
* Turbine - platform abstraction and user I/O (PG)
|
||||
* gba - GBA implementation (PG)
|
||||
* glfw - GLFW implementation (P-)
|
||||
* deps - project dependencies
|
||||
* Ox - Library of things useful for portable bare metal and userland code. Not really that external...
|
||||
* clargs - Command Line Args processing (PG)
|
||||
@ -54,9 +55,26 @@ All components have a platform indicator next to them:
|
||||
* model - Data structure modelling (PG)
|
||||
* preloader - library for handling preloading of data (PG)
|
||||
* std - Standard-ish Library with a lot missing and some things added (PG)
|
||||
* GlUtils - OpenGL helpers (P-)
|
||||
* teagba - GBA assembly startup code (mostly pulled from devkitPro under MPL
|
||||
2.0), and custom GBA hardware interop code (-G)
|
||||
|
||||
## Platform Notes
|
||||
|
||||
### GBA
|
||||
|
||||
The GBA has two major resources for learning about its hardware:
|
||||
|
||||
* [Tonc](https://www.coranac.com/tonc/text/toc.htm) - This is basically a short
|
||||
book on the GBA and low level development.
|
||||
* [GBATEK](https://rust-console.github.io/gbatek-gbaonly/) - This is a more
|
||||
concise resource that mostly tells about memory ranges and registers.
|
||||
|
||||
#### Graphics
|
||||
|
||||
* Background Palette: 256 colors
|
||||
* Sprite Palette: 256 colors
|
||||
|
||||
## Code Base Conventions
|
||||
|
||||
### Formatting
|
||||
@ -485,17 +503,14 @@ implements a superset of JSON.
|
||||
OrganicClaw requires support for 64 bit integers, whereas normal JSON
|
||||
technically does not.
|
||||
|
||||
These formats do not currently support floats.
|
||||
|
||||
There is also a wrapper format called Claw that provides a header at the
|
||||
beginning of the file and can dynamically switch between the two depending on
|
||||
what the header says is present.
|
||||
The Claw header also includes information about the type and type version of
|
||||
the data.
|
||||
|
||||
Except when the data is exported for loading on the GBA, Claw is always used as
|
||||
a wrapper around the bare formats.
|
||||
|
||||
These formats do not currently support ```float```s.
|
||||
|
||||
Claw header: ```M1;net.drinkingtea.nostalgia.core.NostalgiaPalette;1;```
|
||||
|
||||
That reads:
|
||||
@ -504,6 +519,9 @@ That reads:
|
||||
* Type ID is net.drinkingtea.nostalgia.core.NostalgiaPalette
|
||||
* Type version is 1
|
||||
|
||||
Except when the data is exported for loading on the GBA, Claw is always used as
|
||||
a wrapper around the bare formats.
|
||||
|
||||
#### Metal Claw Example
|
||||
|
||||
##### Read
|
||||
|
45
jenkins/gba/Jenkinsfile
vendored
45
jenkins/gba/Jenkinsfile
vendored
@ -1,45 +0,0 @@
|
||||
pipeline {
|
||||
agent {
|
||||
label 'gba'
|
||||
}
|
||||
stages {
|
||||
stage('Environment') {
|
||||
steps {
|
||||
load 'jenkins/shared/env.gy'
|
||||
sh 'make conan-config'
|
||||
sh 'make conan'
|
||||
}
|
||||
}
|
||||
stage('Build Tools Debug') {
|
||||
steps {
|
||||
sh 'make purge configure-debug'
|
||||
sh 'make install'
|
||||
}
|
||||
}
|
||||
stage('Build GBA Debug') {
|
||||
steps {
|
||||
sh 'make configure-gba-debug'
|
||||
sh 'make'
|
||||
sh 'make pkg-gba'
|
||||
}
|
||||
}
|
||||
stage('Build Tools Release') {
|
||||
steps {
|
||||
sh 'make purge configure-release'
|
||||
sh 'make install'
|
||||
}
|
||||
}
|
||||
stage('Build GBA Release') {
|
||||
steps {
|
||||
sh 'make configure-gba'
|
||||
sh 'make'
|
||||
sh 'make pkg-gba'
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
archiveArtifacts artifacts: 'nostalgia.gba', fingerprint: true
|
||||
}
|
||||
}
|
||||
}
|
47
jenkins/linux/Jenkinsfile
vendored
47
jenkins/linux/Jenkinsfile
vendored
@ -1,47 +0,0 @@
|
||||
pipeline {
|
||||
agent {
|
||||
label 'linux-x86_64'
|
||||
}
|
||||
stages {
|
||||
stage('Environment') {
|
||||
steps {
|
||||
load 'jenkins/shared/env.gy'
|
||||
sh 'make conan-config'
|
||||
sh 'make conan'
|
||||
}
|
||||
}
|
||||
stage('Build Asan') {
|
||||
steps {
|
||||
sh 'make purge configure-asan'
|
||||
sh 'make'
|
||||
}
|
||||
}
|
||||
stage('Test Asan') {
|
||||
steps {
|
||||
sh 'make test'
|
||||
}
|
||||
}
|
||||
stage('Build Debug') {
|
||||
steps {
|
||||
sh 'make purge configure-debug'
|
||||
sh 'make'
|
||||
}
|
||||
}
|
||||
stage('Test Debug') {
|
||||
steps {
|
||||
sh 'make test'
|
||||
}
|
||||
}
|
||||
stage('Build Release') {
|
||||
steps {
|
||||
sh 'make purge configure-release'
|
||||
sh 'make'
|
||||
}
|
||||
}
|
||||
stage('Test Release') {
|
||||
steps {
|
||||
sh 'make test'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
47
jenkins/mac/Jenkinsfile
vendored
47
jenkins/mac/Jenkinsfile
vendored
@ -1,47 +0,0 @@
|
||||
pipeline {
|
||||
agent {
|
||||
label 'mac-x86_64'
|
||||
}
|
||||
stages {
|
||||
stage('Environment') {
|
||||
steps {
|
||||
load 'jenkins/shared/env.gy'
|
||||
sh 'make conan-config'
|
||||
sh 'make conan'
|
||||
}
|
||||
}
|
||||
stage('Build Asan') {
|
||||
steps {
|
||||
sh 'make purge configure-asan'
|
||||
sh 'make'
|
||||
}
|
||||
}
|
||||
stage('Test Asan') {
|
||||
steps {
|
||||
sh 'make test'
|
||||
}
|
||||
}
|
||||
stage('Build Debug') {
|
||||
steps {
|
||||
sh 'make purge configure-debug'
|
||||
sh 'make'
|
||||
}
|
||||
}
|
||||
stage('Test Debug') {
|
||||
steps {
|
||||
sh 'make test'
|
||||
}
|
||||
}
|
||||
stage('Build Release') {
|
||||
steps {
|
||||
sh 'make purge configure-release'
|
||||
sh 'make'
|
||||
}
|
||||
}
|
||||
stage('Test Release') {
|
||||
steps {
|
||||
sh 'make test'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
env.OX_NODEBUG = 1
|
||||
env.BUILDCORE_SUPPRESS_CCACHE = 1
|
@ -0,0 +1,27 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "bpp",
|
||||
"typeId" : "B.int8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "defaultPalette",
|
||||
"typeId" : "net.drinkingtea.ox.FileAddress;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "pixels",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint8;0"
|
||||
}
|
||||
],
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.core.CompactTileSheet",
|
||||
"typeVersion" : 1
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "bpp",
|
||||
"typeId" : "B.int8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "rows",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "columns",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "defaultPalette",
|
||||
"typeId" : "net.drinkingtea.ox.FileAddress;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "pal",
|
||||
"typeId" : "net.drinkingtea.nostalgia.core.Palette;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "pixels",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint8;0"
|
||||
}
|
||||
],
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.core.NostalgiaGraphic",
|
||||
"typeVersion" : 1
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "id",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "name",
|
||||
"typeId" : "net.drinkingtea.ox.BasicString#8#;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "rows",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "columns",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "subsheets",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "net.drinkingtea.nostalgia.core.TileSheet.SubSheet;4"
|
||||
},
|
||||
{
|
||||
"fieldName" : "pixels",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint8;0"
|
||||
}
|
||||
],
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.core.TileSheet.SubSheet",
|
||||
"typeVersion" : 4
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "bpp",
|
||||
"typeId" : "B.int8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "idIt",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "defaultPalette",
|
||||
"typeId" : "net.drinkingtea.ox.FileAddress;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "subsheet",
|
||||
"typeId" : "net.drinkingtea.nostalgia.core.TileSheet.SubSheet;4"
|
||||
}
|
||||
],
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.core.TileSheet",
|
||||
"typeVersion" : 4
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "tilesheet",
|
||||
"typeId" : "net.drinkingtea.ox.BasicString#8#;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "palettes",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "net.drinkingtea.ox.BasicString#8#;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "tiles",
|
||||
"subscriptLevels" : 3,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
},
|
||||
{
|
||||
"subscriptType" : 4
|
||||
},
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "net.drinkingtea.nostalgia.scene.TileDoc;1"
|
||||
}
|
||||
],
|
||||
"preloadable" : true,
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.scene.SceneDoc",
|
||||
"typeVersion" : 1
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "tilesheet",
|
||||
"typeId" : "net.drinkingtea.ox.FileAddress;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "palettes",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "net.drinkingtea.ox.FileAddress;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "columns",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint16;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "rows",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint16;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "tileMapIdx",
|
||||
"subscriptLevels" : 2,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
},
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint16;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "tileType",
|
||||
"subscriptLevels" : 2,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
},
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "layerAttachments",
|
||||
"subscriptLevels" : 2,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"subscriptType" : 4
|
||||
},
|
||||
{
|
||||
"subscriptType" : 4
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint8;0"
|
||||
}
|
||||
],
|
||||
"preloadable" : true,
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.scene.SceneStatic",
|
||||
"typeVersion" : 1
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"fieldList" :
|
||||
[
|
||||
{
|
||||
"fieldName" : "subsheet_id",
|
||||
"typeId" : "B.int32;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "subsheet_path",
|
||||
"typeId" : "net.drinkingtea.ox.BasicString#8#;1"
|
||||
},
|
||||
{
|
||||
"fieldName" : "type",
|
||||
"typeId" : "B.uint8;0"
|
||||
},
|
||||
{
|
||||
"fieldName" : "layer_attachments",
|
||||
"subscriptLevels" : 1,
|
||||
"subscriptStack" :
|
||||
[
|
||||
{
|
||||
"length" : 4,
|
||||
"subscriptType" : 3
|
||||
}
|
||||
],
|
||||
"typeId" : "B.uint8;0"
|
||||
}
|
||||
],
|
||||
"preloadable" : true,
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.nostalgia.scene.TileDoc",
|
||||
"typeVersion" : 1
|
||||
}
|
@ -14,7 +14,6 @@ O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"typeId" : "B.uint64;0"
|
||||
}
|
||||
],
|
||||
"preloadable" : true,
|
||||
"primitiveType" : 6,
|
||||
"typeName" : "net.drinkingtea.ox.FileAddress.Data",
|
||||
"typeVersion" : 1
|
||||
|
@ -10,7 +10,6 @@ O1;net.drinkingtea.ox.TypeDescriptor;1;{
|
||||
"typeId" : "net.drinkingtea.ox.FileAddress.Data"
|
||||
}
|
||||
],
|
||||
"preloadable" : true,
|
||||
"primitiveType" : 5,
|
||||
"typeName" : "net.drinkingtea.ox.FileAddress",
|
||||
"typeVersion" : 1
|
||||
|
@ -1 +1 @@
|
||||
K1;14fc3dd8-42ff-4bf9-81f1-a010cc5ac251;M2;net.drinkingtea.nostalgia.core.Palette;1;<EFBFBD><EFBFBD><07><>
|
||||
K1;14fc3dd8-42ff-4bf9-81f1-a010cc5ac251;M2;net.drinkingtea.nostalgia.core.Palette;1;<EFBFBD><EFBFBD><07><>>
|
Binary file not shown.
1
sample_project/TileSheets/AB.ng
Normal file
1
sample_project/TileSheets/AB.ng
Normal file
@ -0,0 +1 @@
|
||||
K1;e41abcbc-0146-4f74-eaa5-5891d21e5de4;M2;net.drinkingtea.nostalgia.core.TileSheet;3;
|
1
sample_project/TileSheets/CD.ng
Normal file
1
sample_project/TileSheets/CD.ng
Normal file
@ -0,0 +1 @@
|
||||
K1;24d20460-0a28-4642-d846-1a712681cfab;M2;net.drinkingtea.nostalgia.core.TileSheet;3;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user