Compare commits

...

6 Commits

72 changed files with 518 additions and 401 deletions
+2 -1
View File
@@ -49,7 +49,8 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-variable") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-variable")
# release build options # release build options
+5
View File
@@ -12,6 +12,11 @@ set_property(
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON
) )
if(NOT MSVC)
target_compile_options(OxClArgs PRIVATE -Wsign-conversion)
target_compile_options(OxClArgs PRIVATE -Wconversion)
endif()
target_link_libraries( target_link_libraries(
OxClArgs PUBLIC OxClArgs PUBLIC
OxStd OxStd
+4 -4
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -12,7 +12,7 @@
namespace ox { namespace ox {
ClArgs::ClArgs(int argc, const char **args) noexcept { ClArgs::ClArgs(int argc, const char **args) noexcept {
for (int i = 0; i < argc; i++) { for (auto i = 0u; i < static_cast<unsigned>(argc); ++i) {
String arg = args[i]; String arg = args[i];
if (arg[0] == '-') { if (arg[0] == '-') {
while (arg[0] == '-' && arg.len()) { while (arg[0] == '-' && arg.len()) {
@@ -20,7 +20,7 @@ ClArgs::ClArgs(int argc, const char **args) noexcept {
} }
m_bools[arg] = true; m_bools[arg] = true;
// parse additional arguments // parse additional arguments
if (i < argc && args[i + 1]) { if (i < static_cast<unsigned>(argc) && args[i + 1]) {
String val = args[i + 1]; String val = args[i + 1];
if (val.len() && val[i] != '-') { if (val.len() && val[i] != '-') {
if (val == "false") { if (val == "false") {
@@ -30,7 +30,7 @@ ClArgs::ClArgs(int argc, const char **args) noexcept {
if (auto r = ox_atoi(val.c_str()); r.error == 0) { if (auto r = ox_atoi(val.c_str()); r.error == 0) {
m_ints[arg] = r.value; m_ints[arg] = r.value;
} }
i++; ++i;
} }
} }
} }
+4 -2
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -26,13 +26,15 @@ class ClArgs {
bool getBool(ox::CRStringView arg, bool defaultValue) const noexcept; bool getBool(ox::CRStringView arg, bool defaultValue) const noexcept;
[[nodiscard]] [[nodiscard]]
String getString(ox::CRStringView argName, const char *defaultArg) const noexcept; String getString(ox::CRStringView argName, const char *defaultValue) const noexcept;
[[nodiscard]] [[nodiscard]]
int getInt(ox::CRStringView arg, int defaultValue) const noexcept; int getInt(ox::CRStringView arg, int defaultValue) const noexcept;
[[nodiscard]]
Result<bool> getBool(ox::CRStringView arg) const noexcept; Result<bool> getBool(ox::CRStringView arg) const noexcept;
[[nodiscard]]
Result<String> getString(ox::CRStringView argName) const noexcept; Result<String> getString(ox::CRStringView argName) const noexcept;
Result<int> getInt(ox::CRStringView arg) const noexcept; Result<int> getInt(ox::CRStringView arg) const noexcept;
+5
View File
@@ -6,6 +6,11 @@ add_library(
) )
if(NOT MSVC)
target_compile_options(OxClaw PRIVATE -Wsign-conversion)
target_compile_options(OxClaw PRIVATE -Wconversion)
endif()
target_link_libraries( target_link_libraries(
OxClaw PUBLIC OxClaw PUBLIC
OxMetalClaw OxMetalClaw
+4 -4
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -17,7 +17,7 @@ Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcep
if (!s1End) { if (!s1End) {
return OxError(1, "Could not read Claw header"); return OxError(1, "Could not read Claw header");
} }
const auto s1Size = s1End - buff; const auto s1Size = static_cast<std::size_t>(s1End - buff);
const String fmt(buff, s1Size); const String fmt(buff, s1Size);
buff += s1Size + 1; buff += s1Size + 1;
buffLen -= s1Size + 1; buffLen -= s1Size + 1;
@@ -26,7 +26,7 @@ Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcep
if (!s2End) { if (!s2End) {
return OxError(2, "Could not read Claw header"); return OxError(2, "Could not read Claw header");
} }
const auto s2Size = s2End - buff; const auto s2Size = static_cast<std::size_t>(s2End - buff);
const String typeName(buff, s2Size); const String typeName(buff, s2Size);
buff += s2Size + 1; buff += s2Size + 1;
buffLen -= s2Size + 1; buffLen -= s2Size + 1;
@@ -35,7 +35,7 @@ Result<ClawHeader> readClawHeader(const char *buff, std::size_t buffLen) noexcep
if (!s3End) { if (!s3End) {
return OxError(3, "Could not read Claw header"); return OxError(3, "Could not read Claw header");
} }
const auto s3Size = s3End - buff; const auto s3Size = static_cast<std::size_t>(s3End - buff);
const String versionStr(buff, s3Size); const String versionStr(buff, s3Size);
buff += s3Size + 1; buff += s3Size + 1;
buffLen -= s3Size + 1; buffLen -= s3Size + 1;
+2 -2
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -198,7 +198,7 @@ int main(int argc, const char **args) {
if (argc > 0) { if (argc > 0) {
auto testName = args[1]; auto testName = args[1];
if (tests.find(testName) != tests.end()) { if (tests.find(testName) != tests.end()) {
retval = tests[testName](); retval = static_cast<int>(tests[testName]());
} else { } else {
retval = 1; retval = 1;
} }
+2 -2
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -27,7 +27,7 @@ struct TypeInfoCatcher {
int version = 0; int version = 0;
template<typename T = void> template<typename T = void>
constexpr void setTypeInfo(const char *name = T::TypeName, int v = T::TypeVersion, const Vector<String>& = {}, int = 0) noexcept { constexpr void setTypeInfo(const char *name = T::TypeName, int v = T::TypeVersion, const Vector<String>& = {}, std::size_t = 0) noexcept {
this->name = name; this->name = name;
this->version = v; this->version = v;
} }
+1
View File
@@ -5,6 +5,7 @@ add_library(
if(NOT MSVC) if(NOT MSVC)
target_compile_options(OxEvent PRIVATE -Wsign-conversion) target_compile_options(OxEvent PRIVATE -Wsign-conversion)
target_compile_options(OxEvent PRIVATE -Wconversion)
endif() endif()
if(NOT OX_BARE_METAL) if(NOT OX_BARE_METAL)
+6
View File
@@ -1,6 +1,8 @@
add_library( add_library(
OxFS OxFS
ptrarith/nodebuffer.hpp
ptrarith/ptr.hpp
filestore/filestoretemplate.cpp filestore/filestoretemplate.cpp
filesystem/filelocation.cpp filesystem/filelocation.cpp
filesystem/pathiterator.cpp filesystem/pathiterator.cpp
@@ -9,6 +11,10 @@ add_library(
filesystem/passthroughfs.cpp filesystem/passthroughfs.cpp
) )
if(NOT MSVC)
target_compile_options(OxFS PRIVATE -Wsign-conversion)
endif()
if(NOT OX_BARE_METAL) if(NOT OX_BARE_METAL)
if(NOT APPLE AND NOT MSVC) if(NOT APPLE AND NOT MSVC)
target_link_libraries( target_link_libraries(
+51 -49
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -75,25 +75,25 @@ class FileStoreTemplate {
public: public:
FileStoreTemplate() = default; FileStoreTemplate() = default;
FileStoreTemplate(void *buff, size_t buffSize); FileStoreTemplate(void *buff, std::size_t buffSize);
static Error format(void *buffer, size_t bufferSize); static Error format(void *buffer, std::size_t bufferSize);
Error setSize(InodeId_t buffSize); Error setSize(std::size_t buffSize);
Error incLinks(InodeId_t id); Error incLinks(uint64_t id);
Error decLinks(InodeId_t id); Error decLinks(uint64_t id);
Error write(InodeId_t id, const void *data, FsSize_t dataSize, uint8_t fileType = 0); Error write(uint64_t id64, const void *data, FsSize_t dataSize, uint8_t fileType = 0);
Error remove(InodeId_t id); Error remove(uint64_t id);
Error read(InodeId_t id, void *out, FsSize_t outSize, FsSize_t *size = nullptr) const; Error read(uint64_t id, void *out, FsSize_t outSize, FsSize_t *size = nullptr) const;
Error read(InodeId_t id, FsSize_t readStart, FsSize_t readSize, void *data, FsSize_t *size = nullptr) const; Error read(uint64_t id, FsSize_t readStart, FsSize_t readSize, void *data, FsSize_t *size = nullptr) const;
ptrarith::Ptr<uint8_t, std::size_t> read(InodeId_t id) const; ptrarith::Ptr<uint8_t, std::size_t> read(uint64_t id) const;
/** /**
* Reads the "file" at the given id. You are responsible for freeing * Reads the "file" at the given id. You are responsible for freeing
@@ -106,11 +106,11 @@ class FileStoreTemplate {
* @return 0 if read is a success * @return 0 if read is a success
*/ */
template<typename T> template<typename T>
Error read(InodeId_t id, FsSize_t readStart, Error read(uint64_t id, FsSize_t readStart,
FsSize_t readSize, T *data, FsSize_t readSize, T *data,
FsSize_t *size) const; FsSize_t *size) const;
Result<StatInfo> stat(InodeId_t id) const; Result<StatInfo> stat(uint64_t id) const;
Error resize(); Error resize();
@@ -185,23 +185,23 @@ class FileStoreTemplate {
*/ */
ItemPtr rootInode(); ItemPtr rootInode();
bool canWrite(ItemPtr existing, size_t size); bool canWrite(ItemPtr existing, std::size_t size);
}; };
template<typename size_t> template<typename size_t>
FileStoreTemplate<size_t>::FileStoreTemplate(void *buff, size_t buffSize) { FileStoreTemplate<size_t>::FileStoreTemplate(void *buff, std::size_t buffSize) {
m_buffSize = buffSize; m_buffSize = static_cast<size_t>(buffSize);
m_buffer = reinterpret_cast<ptrarith::NodeBuffer<size_t, FileStoreItem<size_t>>*>(buff); m_buffer = reinterpret_cast<ptrarith::NodeBuffer<size_t, FileStoreItem<size_t>>*>(buff);
if (!m_buffer->valid(buffSize)) { if (!m_buffer->valid(m_buffSize)) {
m_buffSize = 0; m_buffSize = 0;
m_buffer = nullptr; m_buffer = nullptr;
} }
} }
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::format(void *buffer, size_t bufferSize) { Error FileStoreTemplate<size_t>::format(void *buffer, std::size_t bufferSize) {
auto nb = new (buffer) Buffer(bufferSize); auto nb = new (buffer) Buffer(static_cast<size_t>(bufferSize));
auto fsData = nb->malloc(sizeof(FileStoreData)).value; auto fsData = nb->malloc(sizeof(FileStoreData)).value;
if (!fsData.valid()) { if (!fsData.valid()) {
oxTrace("ox::fs::FileStoreTemplate::format::fail", "Could not read data section of FileStoreData"); oxTrace("ox::fs::FileStoreTemplate::format::fail", "Could not read data section of FileStoreData");
@@ -213,28 +213,28 @@ Error FileStoreTemplate<size_t>::format(void *buffer, size_t bufferSize) {
return OxError(1, "Could not read data section of FileStoreData"); return OxError(1, "Could not read data section of FileStoreData");
} }
new (data) FileStoreData; new (data) FileStoreData;
return OxError(0); return {};
} }
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::setSize(InodeId_t size) { Error FileStoreTemplate<size_t>::setSize(std::size_t size) {
if (m_buffSize >= size) { if (m_buffSize >= size) {
return m_buffer->setSize(size); return m_buffer->setSize(static_cast<size_t>(size));
} }
return OxError(1); return OxError(1);
} }
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::incLinks(InodeId_t id) { Error FileStoreTemplate<size_t>::incLinks(uint64_t id) {
oxRequireM(item, find(id).validate()); oxRequireM(item, find(static_cast<size_t>(id)).validate());
item->links++; ++item->links;
return OxError(0); return OxError(0);
} }
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::decLinks(InodeId_t id) { Error FileStoreTemplate<size_t>::decLinks(uint64_t id) {
oxRequireM(item, find(id).validate()); oxRequireM(item, find(static_cast<size_t>(id)).validate());
item->links--; --item->links;
if (item->links == 0) { if (item->links == 0) {
oxReturnError(remove(item)); oxReturnError(remove(item));
} }
@@ -242,7 +242,8 @@ Error FileStoreTemplate<size_t>::decLinks(InodeId_t id) {
} }
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::write(InodeId_t id, const void *data, FsSize_t dataSize, uint8_t fileType) { Error FileStoreTemplate<size_t>::write(uint64_t id64, const void *data, FsSize_t dataSize, uint8_t fileType) {
const auto id = static_cast<size_t>(id64);
oxTracef("ox::fs::FileStoreTemplate::write", "Attempting to write to inode {}", id); oxTracef("ox::fs::FileStoreTemplate::write", "Attempting to write to inode {}", id);
auto existing = find(id); auto existing = find(id);
if (!canWrite(existing, dataSize)) { if (!canWrite(existing, dataSize)) {
@@ -308,14 +309,14 @@ Error FileStoreTemplate<size_t>::write(InodeId_t id, const void *data, FsSize_t
} }
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::remove(InodeId_t id) { Error FileStoreTemplate<size_t>::remove(uint64_t id) {
return remove(find(id)); return remove(find(static_cast<size_t>(id)));
} }
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::read(InodeId_t id, void *out, FsSize_t outSize, FsSize_t *size) const { Error FileStoreTemplate<size_t>::read(uint64_t id, void *out, FsSize_t outSize, FsSize_t *size) const {
oxTracef("ox::fs::FileStoreTemplate::read", "Attempting to read from inode {}", id); oxTracef("ox::fs::FileStoreTemplate::read", "Attempting to read from inode {}", id);
auto src = find(id); auto src = find(static_cast<size_t>(id));
// error check // error check
if (!src.valid()) { if (!src.valid()) {
oxTracef("ox::fs::FileStoreTemplate::read::fail", "Could not find requested item: {}", id); oxTracef("ox::fs::FileStoreTemplate::read::fail", "Could not find requested item: {}", id);
@@ -344,9 +345,9 @@ Error FileStoreTemplate<size_t>::read(InodeId_t id, void *out, FsSize_t outSize,
} }
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::read(InodeId_t id, FsSize_t readStart, FsSize_t readSize, void *out, FsSize_t *size) const { Error FileStoreTemplate<size_t>::read(uint64_t id, FsSize_t readStart, FsSize_t readSize, void *out, FsSize_t *size) const {
oxTracef("ox::fs::FileStoreTemplate::read", "Attempting to read from inode {}", id); oxTracef("ox::fs::FileStoreTemplate::read", "Attempting to read from inode {}", id);
auto src = find(id); auto src = find(static_cast<size_t>(id));
// error check // error check
if (!src.valid()) { if (!src.valid()) {
oxTracef("ox::fs::FileStoreTemplate::read::fail", "Could not find requested item: {}", id); oxTracef("ox::fs::FileStoreTemplate::read::fail", "Could not find requested item: {}", id);
@@ -376,10 +377,10 @@ Error FileStoreTemplate<size_t>::read(InodeId_t id, FsSize_t readStart, FsSize_t
template<typename size_t> template<typename size_t>
template<typename T> template<typename T>
Error FileStoreTemplate<size_t>::read(InodeId_t id, FsSize_t readStart, Error FileStoreTemplate<size_t>::read(uint64_t id, FsSize_t readStart,
FsSize_t readSize, T *out, FsSize_t *size) const { FsSize_t readSize, T *out, FsSize_t *size) const {
oxTracef("ox::fs::FileStoreTemplate::read", "Attempting to read from inode {}", id); oxTracef("ox::fs::FileStoreTemplate::read", "Attempting to read from inode {}", id);
auto src = find(id); auto src = find(static_cast<size_t>(id));
// error check // error check
if (!src.valid()) { if (!src.valid()) {
oxTracef("ox::fs::FileStoreTemplate::read::fail", "Could not find requested item: {}", id); oxTracef("ox::fs::FileStoreTemplate::read::fail", "Could not find requested item: {}", id);
@@ -408,8 +409,8 @@ Error FileStoreTemplate<size_t>::read(InodeId_t id, FsSize_t readStart,
} }
template<typename size_t> template<typename size_t>
ptrarith::Ptr<uint8_t, std::size_t> FileStoreTemplate<size_t>::read(InodeId_t id) const { ptrarith::Ptr<uint8_t, std::size_t> FileStoreTemplate<size_t>::read(uint64_t id) const {
auto item = find(id); auto item = find(static_cast<size_t>(id));
if (item.valid()) { if (item.valid()) {
return item->data(); return item->data();
} else { } else {
@@ -420,7 +421,7 @@ ptrarith::Ptr<uint8_t, std::size_t> FileStoreTemplate<size_t>::read(InodeId_t id
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::resize() { Error FileStoreTemplate<size_t>::resize() {
oxReturnError(compact()); oxReturnError(compact());
const auto newSize = size() - available(); const auto newSize = static_cast<std::size_t>(size() - available());
oxTracef("ox::fs::FileStoreTemplate::resize", "resize to: {}", newSize); oxTracef("ox::fs::FileStoreTemplate::resize", "resize to: {}", newSize);
oxReturnError(m_buffer->setSize(newSize)); oxReturnError(m_buffer->setSize(newSize));
oxTracef("ox::fs::FileStoreTemplate::resize", "resized to: {}", m_buffer->size()); oxTracef("ox::fs::FileStoreTemplate::resize", "resized to: {}", m_buffer->size());
@@ -432,17 +433,17 @@ Error FileStoreTemplate<size_t>::resize(std::size_t size, void *newBuff) {
if (m_buffer->size() > size) { if (m_buffer->size() > size) {
return OxError(1); return OxError(1);
} }
m_buffSize = size; m_buffSize = static_cast<size_t>(size);
if (newBuff) { if (newBuff) {
m_buffer = reinterpret_cast<Buffer*>(newBuff); m_buffer = reinterpret_cast<Buffer*>(newBuff);
oxReturnError(m_buffer->setSize(size)); oxReturnError(m_buffer->setSize(static_cast<size_t>(size)));
} }
return OxError(0); return OxError(0);
} }
template<typename size_t> template<typename size_t>
Result<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) const { Result<StatInfo> FileStoreTemplate<size_t>::stat(uint64_t id) const {
oxRequire(inode, find(id).validate()); oxRequire(inode, find(static_cast<size_t>(id)).validate());
return StatInfo { return StatInfo {
id, id,
inode->links, inode->links,
@@ -486,8 +487,8 @@ Result<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>:
return OxError(1); return OxError(1);
} }
for (auto i = 0; i < 100; i++) { for (auto i = 0; i < 100; i++) {
auto inode = fsData->random.gen() % MaxValue<InodeId_t>; auto inode = static_cast<typename FileStoreTemplate<size_t>::InodeId_t>(fsData->random.gen() % MaxValue<InodeId_t>);
if (inode > ReservedInodeEnd && !find(inode).valid()) { if (inode > ReservedInodeEnd && !find(static_cast<size_t>(inode)).valid()) {
return inode; return inode;
} }
} }
@@ -511,7 +512,7 @@ Error FileStoreTemplate<size_t>::compact() {
if (fsData && oldAddr == fsData->rootNode) { if (fsData && oldAddr == fsData->rootNode) {
fsData->rootNode = item.offset(); fsData->rootNode = item.offset();
} }
auto parent = findParent(rootInode(), item->id, oldAddr); auto parent = findParent(rootInode(), item->id, static_cast<size_t>(oldAddr));
oxAssert(parent.valid() || rootInode() == item.offset(), oxAssert(parent.valid() || rootInode() == item.offset(),
"Parent inode not found for item that should have parent."); "Parent inode not found for item that should have parent.");
if (parent.valid()) { if (parent.valid()) {
@@ -753,8 +754,9 @@ typename FileStoreTemplate<size_t>::ItemPtr FileStoreTemplate<size_t>::rootInode
} }
template<typename size_t> template<typename size_t>
bool FileStoreTemplate<size_t>::canWrite(ItemPtr existing, size_t size) { bool FileStoreTemplate<size_t>::canWrite(ItemPtr existing, std::size_t size) {
return existing.size() >= size || m_buffer->spaceNeeded(size) <= m_buffer->available(); const auto sz = static_cast<size_t>(size);
return existing.size() >= sz || m_buffer->spaceNeeded(sz) <= m_buffer->available();
} }
template<typename size_t> template<typename size_t>
+13 -10
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -69,10 +69,10 @@ struct OX_PACKED DirectoryEntry {
[[nodiscard]] [[nodiscard]]
InodeId_t size() const { InodeId_t size() const {
return fullSize() - sizeof(*this); return fullSize() - static_cast<InodeId_t>(sizeof(*this));
} }
void setSize(InodeId_t) { void setSize(std::size_t) {
// ignore set value // ignore set value
} }
@@ -94,9 +94,9 @@ class Directory {
FileStore m_fs; FileStore m_fs;
public: public:
Directory() = default; Directory() noexcept = default;
Directory(FileStore fs, InodeId_t inode); Directory(FileStore fs, uint64_t inode) noexcept;
/** /**
* Initializes Directory. * Initializes Directory.
@@ -108,24 +108,26 @@ class Directory {
/** /**
* @param parents indicates the operation should create non-existent directories in the path, like mkdir -p * @param parents indicates the operation should create non-existent directories in the path, like mkdir -p
*/ */
Error write(PathIterator path, InodeId_t inode, FileName *nameBuff = nullptr) noexcept; Error write(PathIterator path, uint64_t inode64, FileName *nameBuff = nullptr) noexcept;
Error remove(PathIterator path, FileName *nameBuff = nullptr) noexcept; Error remove(PathIterator path, FileName *nameBuff = nullptr) noexcept;
template<typename F> template<typename F>
Error ls(F cb) noexcept; Error ls(F cb) noexcept;
[[nodiscard]]
Result<typename FileStore::InodeId_t> findEntry(const FileName &name) const noexcept; Result<typename FileStore::InodeId_t> findEntry(const FileName &name) const noexcept;
[[nodiscard]]
Result<typename FileStore::InodeId_t> find(PathIterator name, FileName *nameBuff = nullptr) const noexcept; Result<typename FileStore::InodeId_t> find(PathIterator name, FileName *nameBuff = nullptr) const noexcept;
}; };
template<typename FileStore, typename InodeId_t> template<typename FileStore, typename InodeId_t>
Directory<FileStore, InodeId_t>::Directory(FileStore fs, InodeId_t inodeId) { Directory<FileStore, InodeId_t>::Directory(FileStore fs, uint64_t inodeId) noexcept {
m_fs = fs; m_fs = fs;
m_inodeId = inodeId; m_inodeId = static_cast<InodeId_t>(inodeId);
auto buff = m_fs.read(inodeId).template to<Buffer>(); auto buff = m_fs.read(static_cast<InodeId_t>(inodeId)).template to<Buffer>();
if (buff.valid()) { if (buff.valid()) {
m_size = buff.size(); m_size = buff.size();
} }
@@ -192,7 +194,8 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents, Fi
} }
template<typename FileStore, typename InodeId_t> template<typename FileStore, typename InodeId_t>
Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t inode, FileName *nameBuff) noexcept { Error Directory<FileStore, InodeId_t>::write(PathIterator path, uint64_t inode64, FileName *nameBuff) noexcept {
const auto inode = static_cast<InodeId_t>(inode64);
// reuse nameBuff if it has already been allocated, as it is a rather large variable // reuse nameBuff if it has already been allocated, as it is a rather large variable
if (nameBuff == nullptr) { if (nameBuff == nullptr) {
nameBuff = new (ox_alloca(sizeof(FileName))) FileName; nameBuff = new (ox_alloca(sizeof(FileName))) FileName;
+3 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -39,14 +39,14 @@ Error FileSystem::read(const FileAddress &addr, void *buffer, std::size_t size)
Result<Buffer> FileSystem::read(const FileAddress &addr) noexcept { Result<Buffer> FileSystem::read(const FileAddress &addr) noexcept {
oxRequire(s, stat(addr)); oxRequire(s, stat(addr));
Buffer buff(s.size); Buffer buff(static_cast<std::size_t>(s.size));
oxReturnError(read(addr, buff.data(), buff.size())); oxReturnError(read(addr, buff.data(), buff.size()));
return buff; return buff;
} }
Result<Buffer> FileSystem::read(CRStringView path) noexcept { Result<Buffer> FileSystem::read(CRStringView path) noexcept {
oxRequire(s, statPath(path)); oxRequire(s, statPath(path));
Buffer buff(s.size); Buffer buff(static_cast<std::size_t>(s.size));
oxReturnError(readFilePath(path, buff.data(), buff.size())); oxReturnError(readFilePath(path, buff.data(), buff.size()));
return buff; return buff;
} }
+9 -9
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -240,7 +240,7 @@ FileSystemTemplate<FileStore, Directory>::FileSystemTemplate(FileStore fs) noexc
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
FileSystemTemplate<FileStore, Directory>::FileSystemTemplate(void *buffer, uint64_t bufferSize, void(*freeBuffer)(char*)) noexcept: FileSystemTemplate<FileStore, Directory>::FileSystemTemplate(void *buffer, uint64_t bufferSize, void(*freeBuffer)(char*)) noexcept:
m_fs(buffer, bufferSize), m_fs(buffer, static_cast<std::size_t>(bufferSize)),
m_freeBuffer(freeBuffer) { m_freeBuffer(freeBuffer) {
} }
@@ -253,8 +253,8 @@ FileSystemTemplate<FileStore, Directory>::~FileSystemTemplate() noexcept {
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
Error FileSystemTemplate<FileStore, Directory>::format(void *buff, uint64_t buffSize) noexcept { Error FileSystemTemplate<FileStore, Directory>::format(void *buff, uint64_t buffSize) noexcept {
oxReturnError(FileStore::format(buff, buffSize)); oxReturnError(FileStore::format(buff, static_cast<size_t>(buffSize)));
FileStore fs(buff, buffSize); FileStore fs(buff, static_cast<size_t>(buffSize));
constexpr auto rootDirInode = MaxValue<typename FileStore::InodeId_t> / 2; constexpr auto rootDirInode = MaxValue<typename FileStore::InodeId_t> / 2;
Directory rootDir(fs, rootDirInode); Directory rootDir(fs, rootDirInode);
@@ -298,7 +298,7 @@ Error FileSystemTemplate<FileStore, Directory>::readFilePath(CRStringView path,
if (s.size > buffSize) { if (s.size > buffSize) {
return OxError(1, "Buffer to small to load file"); return OxError(1, "Buffer to small to load file");
} }
return readFileInodeRange(s.inode, 0, s.size, buffer, &buffSize); return readFileInodeRange(s.inode, 0, static_cast<size_t>(s.size), buffer, &buffSize);
} }
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
@@ -315,7 +315,7 @@ Error FileSystemTemplate<FileStore, Directory>::readFileInode(uint64_t inode, vo
if (s.size > buffSize) { if (s.size > buffSize) {
return OxError(1, "Buffer to small to load file"); return OxError(1, "Buffer to small to load file");
} }
return readFileInodeRange(inode, 0, s.size, buffer, &buffSize); return readFileInodeRange(inode, 0, static_cast<size_t>(s.size), buffer, &buffSize);
} }
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
@@ -377,7 +377,7 @@ Error FileSystemTemplate<FileStore, Directory>::resize() noexcept {
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
Error FileSystemTemplate<FileStore, Directory>::resize(uint64_t size, void *buffer) noexcept { Error FileSystemTemplate<FileStore, Directory>::resize(uint64_t size, void *buffer) noexcept {
oxReturnError(m_fs.resize(size, buffer)); oxReturnError(m_fs.resize(static_cast<size_t>(size), buffer));
return OxError(0); return OxError(0);
} }
@@ -396,7 +396,7 @@ Error FileSystemTemplate<FileStore, Directory>::writeFilePath(CRStringView path,
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept { Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
return m_fs.write(inode, buffer, size, static_cast<uint8_t>(fileType)); return m_fs.write(inode, buffer, static_cast<size_t>(size), static_cast<uint8_t>(fileType));
} }
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
@@ -418,7 +418,7 @@ Result<FileStat> FileSystemTemplate<FileStore, Directory>::statPath(CRStringView
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
uint64_t FileSystemTemplate<FileStore, Directory>::spaceNeeded(uint64_t size) const noexcept { uint64_t FileSystemTemplate<FileStore, Directory>::spaceNeeded(uint64_t size) const noexcept {
return m_fs.spaceNeeded(size); return m_fs.spaceNeeded(static_cast<size_t>(size));
} }
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
+8 -8
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -39,7 +39,7 @@ Error PassThroughFS::mkdir(CRStringView path, bool recursive) noexcept {
success = true; success = true;
} else { } else {
success = std::filesystem::create_directories(p, ec); success = std::filesystem::create_directories(p, ec);
oxReturnError(OxError(ec.value(), "PassThroughFS: mkdir failed")); oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
} }
} else { } else {
std::error_code ec; std::error_code ec;
@@ -48,7 +48,7 @@ Error PassThroughFS::mkdir(CRStringView path, bool recursive) noexcept {
success = true; success = true;
} else { } else {
success = std::filesystem::create_directory(p, ec); success = std::filesystem::create_directory(p, ec);
oxReturnError(OxError(ec.value(), "PassThroughFS: mkdir failed")); oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed"));
} }
} }
return OxError(success ? 0 : 1); return OxError(success ? 0 : 1);
@@ -67,7 +67,7 @@ Result<Vector<String>> PassThroughFS::ls(CRStringView dir) const noexcept {
Vector<String> out; Vector<String> out;
std::error_code ec; std::error_code ec;
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec); const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
oxReturnError(OxError(ec.value(), "PassThroughFS: ls failed")); oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
for (const auto &p : di) { for (const auto &p : di) {
const auto u8p = p.path().filename().u8string(); const auto u8p = p.path().filename().u8string();
out.emplace_back(reinterpret_cast<const char*>(u8p.c_str())); out.emplace_back(reinterpret_cast<const char*>(u8p.c_str()));
@@ -102,7 +102,7 @@ Result<FileStat> PassThroughFS::statPath(CRStringView path) const noexcept {
const uint64_t size = type == FileType::Directory ? 0 : std::filesystem::file_size(p, ec); const uint64_t size = type == FileType::Directory ? 0 : std::filesystem::file_size(p, ec);
oxTracef("ox::fs::PassThroughFS::statInode", "{} {}", ec.message(), path); 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(ec.value(), "PassThroughFS: stat failed")); oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: stat failed"));
return FileStat{0, 0, size, type}; return FileStat{0, 0, size, type};
} }
@@ -113,14 +113,14 @@ uint64_t PassThroughFS::spaceNeeded(uint64_t size) const noexcept {
Result<uint64_t> PassThroughFS::available() const noexcept { Result<uint64_t> PassThroughFS::available() const noexcept {
std::error_code ec; std::error_code ec;
const auto s = std::filesystem::space(m_path, ec); const auto s = std::filesystem::space(m_path, ec);
oxReturnError(OxError(ec.value(), "PassThroughFS: could not get FS size")); oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
return s.available; return s.available;
} }
Result<uint64_t> PassThroughFS::size() const noexcept { Result<uint64_t> PassThroughFS::size() const noexcept {
std::error_code ec; std::error_code ec;
const auto s = std::filesystem::space(m_path, ec); const auto s = std::filesystem::space(m_path, ec);
oxReturnError(OxError(ec.value(), "PassThroughFS: could not get FS size")); oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: could not get FS size"));
return s.capacity; return s.capacity;
} }
@@ -144,7 +144,7 @@ bool PassThroughFS::valid() const noexcept {
Error PassThroughFS::readFilePath(CRStringView path, void *buffer, std::size_t buffSize) noexcept { Error PassThroughFS::readFilePath(CRStringView path, void *buffer, std::size_t buffSize) noexcept {
try { try {
std::ifstream file((m_path / stripSlash(path)), std::ios::binary | std::ios::ate); std::ifstream file((m_path / stripSlash(path)), std::ios::binary | std::ios::ate);
const std::size_t size = file.tellg(); const std::size_t size = static_cast<std::size_t>(file.tellg());
file.seekg(0, std::ios::beg); file.seekg(0, std::ios::beg);
if (size > buffSize) { if (size > buffSize) {
oxTracef("ox::fs::PassThroughFS::read::error", "Read failed: Buffer too small: {}", path); oxTracef("ox::fs::PassThroughFS::read::error", "Read failed: Buffer too small: {}", path);
+2 -2
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -92,7 +92,7 @@ template<typename F>
Error PassThroughFS::ls(CRStringView dir, F cb) const noexcept { Error PassThroughFS::ls(CRStringView dir, F cb) const noexcept {
std::error_code ec; std::error_code ec;
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec); const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
oxReturnError(OxError(ec.value(), "PassThroughFS: ls failed")); oxReturnError(OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: ls failed"));
for (auto &p : di) { for (auto &p : di) {
oxReturnError(cb(p.path().filename().c_str(), 0)); oxReturnError(cb(p.path().filename().c_str(), 0));
} }
+13 -13
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -29,8 +29,8 @@ PathIterator::PathIterator(CRStringView path): PathIterator(path.data(), path.by
* @return 0 if no error * @return 0 if no error
*/ */
Error PathIterator::dirPath(char *out, std::size_t outSize) { Error PathIterator::dirPath(char *out, std::size_t outSize) {
int idx = ox_lastIndexOf(m_path, '/', m_maxSize); const auto idx = ox_lastIndexOf(m_path, '/', m_maxSize);
std::size_t size = idx + 1; const auto size = static_cast<std::size_t>(idx + 1);
if (idx >= 0 && size < outSize) { if (idx >= 0 && size < outSize) {
ox_memcpy(out, m_path, size); ox_memcpy(out, m_path, size);
out[size] = 0; out[size] = 0;
@@ -47,7 +47,7 @@ Error PathIterator::fileName(char *out, std::size_t outSize) {
auto idx = ox_lastIndexOf(m_path, '/', m_maxSize); auto idx = ox_lastIndexOf(m_path, '/', m_maxSize);
if (idx >= 0) { if (idx >= 0) {
idx++; // pass up the preceding / idx++; // pass up the preceding /
std::size_t fileNameSize = ox_strlen(&m_path[idx]); std::size_t fileNameSize = static_cast<size_t>(ox_strlen(&m_path[idx]));
if (fileNameSize < outSize) { if (fileNameSize < outSize) {
ox_memcpy(out, &m_path[idx], fileNameSize); ox_memcpy(out, &m_path[idx], fileNameSize);
out[fileNameSize] = 0; out[fileNameSize] = 0;
@@ -81,7 +81,7 @@ Error PathIterator::get(char *pathOut, std::size_t pathOutSize) {
if (!substr) { if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start); substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
} }
std::size_t end = substr - m_path; const auto end = static_cast<size_t>(substr - m_path);
size = end - start; size = end - start;
// cannot fit the output in the output parameter // cannot fit the output in the output parameter
if (size >= pathOutSize || size == 0) { if (size >= pathOutSize || size == 0) {
@@ -105,14 +105,14 @@ Error PathIterator::next(char *pathOut, std::size_t pathOutSize) {
if (m_path[m_iterator] == '/') { if (m_path[m_iterator] == '/') {
m_iterator++; m_iterator++;
} }
std::size_t start = m_iterator; const auto start = m_iterator;
// end is at the next / // end is at the next /
const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start); const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start);
// correct end if it is invalid, which happens if there is no next / // correct end if it is invalid, which happens if there is no next /
if (!substr) { if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start); substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
} }
std::size_t end = substr - m_path; const auto end = static_cast<size_t>(substr - m_path);
size = end - start; size = end - start;
// cannot fit the output in the output parameter // cannot fit the output in the output parameter
if (size >= pathOutSize) { if (size >= pathOutSize) {
@@ -152,14 +152,14 @@ Result<std::size_t> PathIterator::nextSize() const {
if (m_path[it] == '/') { if (m_path[it] == '/') {
it++; it++;
} }
std::size_t start = it; const auto start = it;
// end is at the next / // end is at the next /
const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start); const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start);
// correct end if it is invalid, which happens if there is no next / // correct end if it is invalid, which happens if there is no next /
if (!substr) { if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start); substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
} }
std::size_t end = substr - m_path; const auto end = static_cast<std::size_t>(substr - m_path);
size = end - start; size = end - start;
} }
it += size; it += size;
@@ -179,7 +179,7 @@ bool PathIterator::hasNext() const {
if (!substr) { if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start); substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
} }
std::size_t end = substr - m_path; const auto end = static_cast<std::size_t>(substr - m_path);
size = end - start; size = end - start;
} }
return size > 0; return size > 0;
@@ -196,18 +196,18 @@ PathIterator PathIterator::next() const {
if (m_path[iterator] == '/') { if (m_path[iterator] == '/') {
iterator++; iterator++;
} }
std::size_t start = iterator; const auto start = iterator;
// end is at the next / // end is at the next /
const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start); const char *substr = ox_strchr(&m_path[start], '/', m_maxSize - start);
// correct end if it is invalid, which happens if there is no next / // correct end if it is invalid, which happens if there is no next /
if (!substr) { if (!substr) {
substr = ox_strchr(&m_path[start], 0, m_maxSize - start); substr = ox_strchr(&m_path[start], 0, m_maxSize - start);
} }
std::size_t end = substr - m_path; const auto end = static_cast<std::size_t>(substr - m_path);
size = end - start; size = end - start;
} }
iterator += size; iterator += size;
return PathIterator(m_path, m_maxSize, iterator + 1); return {m_path, m_maxSize, iterator + 1};
} }
const char *PathIterator::fullPath() const { const char *PathIterator::fullPath() const {
+23 -22
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -97,9 +97,9 @@ class OX_PACKED NodeBuffer {
Header m_header; Header m_header;
public: public:
NodeBuffer(const NodeBuffer &other, size_t size) noexcept; NodeBuffer(const NodeBuffer &other, std::size_t size) noexcept;
explicit NodeBuffer(size_t size) noexcept; explicit NodeBuffer(std::size_t size) noexcept;
[[nodiscard]] [[nodiscard]]
const Iterator iterator() const noexcept; const Iterator iterator() const noexcept;
@@ -129,7 +129,7 @@ class OX_PACKED NodeBuffer {
ItemPtr ptr(size_t offset) noexcept; ItemPtr ptr(size_t offset) noexcept;
Result<ItemPtr> malloc(size_t size) noexcept; Result<ItemPtr> malloc(std::size_t size) noexcept;
Error free(ItemPtr item) noexcept; Error free(ItemPtr item) noexcept;
@@ -139,7 +139,7 @@ class OX_PACKED NodeBuffer {
/** /**
* Set size, capacity. * Set size, capacity.
*/ */
Error setSize(size_t size) noexcept; Error setSize(std::size_t size) noexcept;
/** /**
* Get size, capacity. * Get size, capacity.
@@ -159,7 +159,7 @@ class OX_PACKED NodeBuffer {
* bytes * bytes
*/ */
[[nodiscard]] [[nodiscard]]
static size_t spaceNeeded(size_t size) noexcept; static size_t spaceNeeded(std::size_t size) noexcept;
template<typename F> template<typename F>
Error compact(F cb = [](uint64_t, ItemPtr) {}) noexcept; Error compact(F cb = [](uint64_t, ItemPtr) {}) noexcept;
@@ -171,14 +171,14 @@ class OX_PACKED NodeBuffer {
}; };
template<typename size_t, typename Item> template<typename size_t, typename Item>
NodeBuffer<size_t, Item>::NodeBuffer(size_t size) noexcept { NodeBuffer<size_t, Item>::NodeBuffer(std::size_t size) noexcept {
m_header.size = size; m_header.size = static_cast<size_t>(size);
ox_memset(this + 1, 0, size - sizeof(*this)); ox_memset(this + 1, 0, size - sizeof(*this));
oxTrace("ox::NodeBuffer::constructor") << m_header.firstItem; oxTracef("ox::NodeBuffer::constructor", "{}", m_header.firstItem.get());
} }
template<typename size_t, typename Item> template<typename size_t, typename Item>
NodeBuffer<size_t, Item>::NodeBuffer(const NodeBuffer &other, size_t size) noexcept { NodeBuffer<size_t, Item>::NodeBuffer(const NodeBuffer &other, std::size_t size) noexcept {
oxTracef("ox::ptrarith::NodeBuffer::copy", "other.m_header.firstItem: {}", other.m_header.firstItem.get()); oxTracef("ox::ptrarith::NodeBuffer::copy", "other.m_header.firstItem: {}", other.m_header.firstItem.get());
ox_memset(this + 1, 0, size - sizeof(*this)); ox_memset(this + 1, 0, size - sizeof(*this));
ox_memcpy(this, &other, size); ox_memcpy(this, &other, size);
@@ -191,7 +191,7 @@ const typename NodeBuffer<size_t, Item>::Iterator NodeBuffer<size_t, Item>::iter
template<typename size_t, typename Item> template<typename size_t, typename Item>
typename NodeBuffer<size_t, Item>::Iterator NodeBuffer<size_t, Item>::iterator() noexcept { typename NodeBuffer<size_t, Item>::Iterator NodeBuffer<size_t, Item>::iterator() noexcept {
oxTrace("ox::ptrarith::NodeBuffer::iterator::size") << m_header.size; oxTracef("ox::ptrarith::NodeBuffer::iterator::size", "{}", m_header.size.get());
return Iterator(this, firstItem()); return Iterator(this, firstItem());
} }
@@ -265,9 +265,10 @@ typename NodeBuffer<size_t, Item>::ItemPtr NodeBuffer<size_t, Item>::ptr(size_t
} }
template<typename size_t, typename Item> template<typename size_t, typename Item>
Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::malloc(size_t size) noexcept { Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::malloc(std::size_t size) noexcept {
oxTracef("ox::ptrarith::NodeBuffer::malloc", "Size: {}", size); const auto sz = static_cast<std::size_t>(size);
size_t fullSize = size + sizeof(Item); oxTracef("ox::ptrarith::NodeBuffer::malloc", "Size: {}", sz);
size_t fullSize = static_cast<size_t>(sz + sizeof(Item));
if (m_header.size - m_header.bytesUsed >= fullSize) { if (m_header.size - m_header.bytesUsed >= fullSize) {
auto last = lastItem(); auto last = lastItem();
size_t addr; size_t addr;
@@ -277,7 +278,7 @@ Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::mal
// there is no first item, so this must be the first item // there is no first item, so this must be the first item
if (!m_header.firstItem) { if (!m_header.firstItem) {
oxTrace("ox::ptrarith::NodeBuffer::malloc", "No first item, initializing."); oxTrace("ox::ptrarith::NodeBuffer::malloc", "No first item, initializing.");
m_header.firstItem = sizeof(m_header); m_header.firstItem = static_cast<size_t>(sizeof(m_header));
addr = m_header.firstItem; addr = m_header.firstItem;
} else { } else {
oxTrace("ox::ptrarith::NodeBuffer::malloc::fail", "NodeBuffer is in invalid state."); oxTrace("ox::ptrarith::NodeBuffer::malloc::fail", "NodeBuffer is in invalid state.");
@@ -292,7 +293,7 @@ Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::mal
} }
ox_memset(out, 0, fullSize); ox_memset(out, 0, fullSize);
new (out) Item; new (out) Item;
out->setSize(size); out->setSize(sz);
auto first = firstItem(); auto first = firstItem();
auto oldLast = last; auto oldLast = last;
@@ -355,7 +356,7 @@ Error NodeBuffer<size_t, Item>::free(ItemPtr item) noexcept {
} }
template<typename size_t, typename Item> template<typename size_t, typename Item>
Error NodeBuffer<size_t, Item>::setSize(size_t size) noexcept { Error NodeBuffer<size_t, Item>::setSize(std::size_t size) noexcept {
oxTracef("ox::ptrarith::NodeBuffer::setSize", "{} to {}", m_header.size.get(), size); oxTracef("ox::ptrarith::NodeBuffer::setSize", "{} to {}", m_header.size.get(), size);
auto last = lastItem(); auto last = lastItem();
auto end = last.valid() ? last.end() : sizeof(m_header); auto end = last.valid() ? last.end() : sizeof(m_header);
@@ -364,7 +365,7 @@ Error NodeBuffer<size_t, Item>::setSize(size_t size) noexcept {
// resizing to less than buffer size // resizing to less than buffer size
return OxError(1); return OxError(1);
} else { } else {
m_header.size = size; m_header.size = static_cast<size_t>(size);
auto data = reinterpret_cast<uint8_t*>(this) + end; auto data = reinterpret_cast<uint8_t*>(this) + end;
ox_memset(data, 0, size - end); ox_memset(data, 0, size - end);
return OxError(0); return OxError(0);
@@ -387,8 +388,8 @@ size_t NodeBuffer<size_t, Item>::available() const noexcept {
} }
template<typename size_t, typename Item> template<typename size_t, typename Item>
size_t NodeBuffer<size_t, Item>::spaceNeeded(size_t size) noexcept { size_t NodeBuffer<size_t, Item>::spaceNeeded(std::size_t size) noexcept {
return sizeof(Item) + size; return static_cast<size_t>(sizeof(Item) + size);
} }
template<typename size_t, typename Item> template<typename size_t, typename Item>
@@ -442,8 +443,8 @@ struct OX_PACKED Item {
return m_size; return m_size;
} }
void setSize(size_t size) { void setSize(std::size_t size) {
m_size = size; m_size = static_cast<size_t>(size);
} }
}; };
+22 -6
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -29,7 +29,13 @@ class [[nodiscard]] Ptr {
constexpr Ptr(std::nullptr_t) noexcept; constexpr Ptr(std::nullptr_t) noexcept;
constexpr Ptr(void *dataStart, size_t dataSize, size_t itemStart, size_t itemSize = sizeof(T), size_t itemTypeSize = sizeof(T), bool prevalidated = false) noexcept; constexpr Ptr(
void *pDataStart,
std::size_t pDataSize,
std::size_t pItemStart,
std::size_t pItemSize = sizeof(T),
std::size_t pItemTypeSize = sizeof(T),
bool pPrevalidated = false) noexcept;
[[nodiscard]] [[nodiscard]]
constexpr bool valid() const noexcept; constexpr bool valid() const noexcept;
@@ -86,17 +92,27 @@ constexpr Ptr<T, size_t, minOffset>::Ptr(std::nullptr_t) noexcept {
} }
template<typename T, typename size_t, size_t minOffset> template<typename T, typename size_t, size_t minOffset>
constexpr Ptr<T, size_t, minOffset>::Ptr(void *dataStart, size_t dataSize, size_t itemStart, size_t itemSize, size_t itemTypeSize, bool prevalidated) noexcept { constexpr Ptr<T, size_t, minOffset>::Ptr(
void *pDataStart,
std::size_t pDataSize,
std::size_t pItemStart,
std::size_t pItemSize,
std::size_t pItemTypeSize,
bool pPrevalidated) noexcept {
const auto dataSize = static_cast<size_t>(pDataSize);
const auto itemStart = static_cast<size_t>(pItemStart);
const auto itemSize = static_cast<size_t>(pItemSize);
const auto itemTypeSize = static_cast<size_t>(pItemTypeSize);
// do some sanity checks before assuming this is valid // do some sanity checks before assuming this is valid
if (itemSize >= itemTypeSize && if (itemSize >= itemTypeSize &&
dataStart && pDataStart &&
itemStart >= minOffset && itemStart >= minOffset &&
itemStart + itemSize <= dataSize) { itemStart + itemSize <= dataSize) {
m_dataStart = reinterpret_cast<uint8_t*>(dataStart); m_dataStart = reinterpret_cast<uint8_t*>(pDataStart);
m_dataSize = dataSize; m_dataSize = dataSize;
m_itemOffset = itemStart; m_itemOffset = itemStart;
m_itemSize = itemSize; m_itemSize = itemSize;
m_validated = prevalidated; m_validated = pPrevalidated;
} }
} }
+2 -2
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -26,7 +26,7 @@ static ox::Result<Buff> loadFsBuff(const char *path) noexcept {
const auto size = static_cast<std::size_t>(file.tellg()); const auto size = static_cast<std::size_t>(file.tellg());
file.seekg(0, std::ios::beg); file.seekg(0, std::ios::beg);
const auto buff = new char[size]; const auto buff = new char[size];
file.read(buff, size); file.read(buff, static_cast<std::streamsize>(size));
return Buff{buff, size}; return Buff{buff, size};
} catch (const std::ios_base::failure &e) { } catch (const std::ios_base::failure &e) {
oxErrorf("Could not read OxFS file: {}", e.what()); oxErrorf("Could not read OxFS file: {}", e.what());
+4
View File
@@ -12,6 +12,10 @@ set_property(
POSITION_INDEPENDENT_CODE ON POSITION_INDEPENDENT_CODE ON
) )
if(NOT MSVC)
target_compile_options(OxLogConn PRIVATE -Wsign-conversion)
endif()
target_link_libraries( target_link_libraries(
OxLogConn PUBLIC OxLogConn PUBLIC
OxStd OxStd
+2 -2
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -40,7 +40,7 @@ ox::Error LoggerConn::initConn(const char *appName) noexcept {
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(5590); addr.sin_port = htons(5590);
m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
oxReturnError(OxError(connect(m_socket, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)))); oxReturnError(OxError(static_cast<ox::ErrorCode>(connect(m_socket, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)))));
return sendInit({.appName = appName}); return sendInit({.appName = appName});
} }
+1
View File
@@ -7,6 +7,7 @@ add_library(
if(NOT MSVC) if(NOT MSVC)
target_compile_options(OxMetalClaw PRIVATE -Wsign-conversion) target_compile_options(OxMetalClaw PRIVATE -Wsign-conversion)
target_compile_options(OxMetalClaw PRIVATE -Wconversion)
endif() endif()
target_link_libraries( target_link_libraries(
+5 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -11,6 +11,8 @@
#include <ox/std/error.hpp> #include <ox/std/error.hpp>
#include <ox/std/types.hpp> #include <ox/std/types.hpp>
#include "err.hpp"
namespace ox { namespace ox {
template<typename T> template<typename T>
@@ -83,9 +85,9 @@ constexpr Error FieldBitmap::set(std::size_t i, bool on) noexcept {
if (on) { if (on) {
m_map[i / 8] |= 1 << (i % 8); m_map[i / 8] |= 1 << (i % 8);
} else { } else {
m_map[i / 8] &= ~(1 << (i % 8)); m_map[i / 8] &= ~static_cast<uint8_t>(1 << (i % 8));
} }
return OxError(0); return {};
} else { } else {
return OxError(MC_PRESENCEMASKOUTBOUNDS); return OxError(MC_PRESENCEMASKOUTBOUNDS);
} }
+24 -24
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -31,8 +31,8 @@ class MetalClawReaderTemplate {
private: private:
FieldBitmapReader<const uint8_t*> m_fieldPresence; FieldBitmapReader<const uint8_t*> m_fieldPresence;
int m_fields = 0; std::size_t m_fields = 0;
int m_field = 0; std::size_t m_field = 0;
int m_unionIdx = -1; int m_unionIdx = -1;
std::size_t m_buffIt = 0; std::size_t m_buffIt = 0;
std::size_t m_buffLen = 0; std::size_t m_buffLen = 0;
@@ -100,7 +100,7 @@ class MetalClawReaderTemplate {
template<typename T = std::nullptr_t> template<typename T = std::nullptr_t>
constexpr void setTypeInfo(const char *name = T::TypeName, int version = T::TypeVersion, constexpr void setTypeInfo(const char *name = T::TypeName, int version = T::TypeVersion,
const Vector<String>& = {}, int fields = ModelFieldCount_v<T>) noexcept; const Vector<String>& = {}, std::size_t fields = ModelFieldCount_v<T>) noexcept;
/** /**
* Returns a MetalClawReader to parse a child object. * Returns a MetalClawReader to parse a child object.
@@ -200,7 +200,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, uint64
template<auto HandlerMaker> template<auto HandlerMaker>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, bool *val) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, bool *val) noexcept {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
auto valErr = m_fieldPresence.get(static_cast<std::size_t>(m_field)); auto valErr = m_fieldPresence.get(static_cast<std::size_t>(m_field));
*val = valErr.value; *val = valErr.value;
oxReturnError(valErr.error); oxReturnError(valErr.error);
@@ -212,7 +212,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, bool *
// array handler // array handler
template<auto HandlerMaker> template<auto HandlerMaker>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, auto *val, std::size_t valLen) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, auto *val, std::size_t valLen) noexcept {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
// read the length // read the length
if (m_buffIt >= m_buffLen) { if (m_buffIt >= m_buffLen) {
@@ -225,7 +225,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, a
if (valLen >= len) { if (valLen >= len) {
auto reader = child(""); auto reader = child("");
auto handler = HandlerMaker(&reader); auto handler = HandlerMaker(&reader);
handler.setTypeInfo("List", 0, {}, static_cast<int>(len)); handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len));
for (std::size_t i = 0; i < len; ++i) { for (std::size_t i = 0; i < len; ++i) {
oxReturnError(handler.field("", &val[i])); oxReturnError(handler.field("", &val[i]));
} }
@@ -242,7 +242,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, a
template<auto HandlerMaker> template<auto HandlerMaker>
template<typename T> template<typename T>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, HashMap<String, T> *val) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, HashMap<String, T> *val) noexcept {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
// read the length // read the length
if (m_buffIt >= m_buffLen) { if (m_buffIt >= m_buffLen) {
@@ -254,12 +254,12 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, HashMa
// read the list // read the list
auto reader = child(""); auto reader = child("");
auto handler = HandlerMaker(&reader); auto handler = HandlerMaker(&reader);
handler.setTypeInfo("List", 0, {}, static_cast<int>(len)); handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len));
for (std::size_t i = 0; i < len; ++i) { for (std::size_t i = 0; i < len; ++i) {
const auto keyLen = handler.stringLength(nullptr); const auto keyLen = handler.stringLength(nullptr);
auto wkey = ox_malloca(keyLen + 1, char, 0); auto wkey = ox_malloca(keyLen + 1, char, 0);
auto wkeyPtr = wkey.get(); auto wkeyPtr = wkey.get();
oxReturnError(handler.fieldCString("", &wkeyPtr, static_cast<int>(keyLen + 1))); oxReturnError(handler.fieldCString("", &wkeyPtr, keyLen + 1));
oxReturnError(handler.field("", &val->operator[](wkey.get()))); oxReturnError(handler.field("", &val->operator[](wkey.get())));
} }
} }
@@ -272,7 +272,7 @@ template<auto HandlerMaker>
template<typename T> template<typename T>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, T *val) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, T *val) noexcept {
if constexpr(isVector_v<T>) { if constexpr(isVector_v<T>) {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
// set size of val if the field is present, don't worry about it if not // set size of val if the field is present, don't worry about it if not
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
oxRequire(len, arrayLength(name, false)); oxRequire(len, arrayLength(name, false));
@@ -283,7 +283,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, T
++m_field; ++m_field;
return {}; return {};
} else if constexpr(isArray_v<T>) { } else if constexpr(isArray_v<T>) {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
// set size of val if the field is present, don't worry about it if not // set size of val if the field is present, don't worry about it if not
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
oxRequire(len, arrayLength(name, false)); oxRequire(len, arrayLength(name, false));
@@ -296,7 +296,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, T
++m_field; ++m_field;
return {}; return {};
} else { } else {
if ((m_unionIdx == -1 || m_unionIdx == m_field) && val) { if ((m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) && val) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
auto reader = child(""); auto reader = child("");
auto handler = HandlerMaker(&reader); auto handler = HandlerMaker(&reader);
@@ -311,7 +311,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char *name, T
template<auto HandlerMaker> template<auto HandlerMaker>
template<typename U, bool force> template<typename U, bool force>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, UnionView<U, force> val) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, UnionView<U, force> val) noexcept {
if ((m_unionIdx == -1 || m_unionIdx == m_field) && val.get()) { if ((m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) && val.get()) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
auto reader = child("", val.idx()); auto reader = child("", val.idx());
auto handler = HandlerMaker(&reader); auto handler = HandlerMaker(&reader);
@@ -325,7 +325,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, UnionV
template<auto HandlerMaker> template<auto HandlerMaker>
template<std::size_t SmallStringSize> template<std::size_t SmallStringSize>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, BasicString<SmallStringSize> *val) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, BasicString<SmallStringSize> *val) noexcept {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
// read the length // read the length
if (m_buffIt >= m_buffLen) { if (m_buffIt >= m_buffLen) {
@@ -419,7 +419,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::fieldCString(const char*,
template<auto HandlerMaker> template<auto HandlerMaker>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::fieldCString(const char*, char **val, std::size_t buffLen) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::fieldCString(const char*, char **val, std::size_t buffLen) noexcept {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
// read the length // read the length
if (m_buffIt >= m_buffLen) { if (m_buffIt >= m_buffLen) {
@@ -457,7 +457,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::fieldCString(const char*,
template<auto HandlerMaker> template<auto HandlerMaker>
constexpr Result<ArrayLength> MetalClawReaderTemplate<HandlerMaker>::arrayLength(const char*, bool pass) noexcept { constexpr Result<ArrayLength> MetalClawReaderTemplate<HandlerMaker>::arrayLength(const char*, bool pass) noexcept {
if ((m_unionIdx == -1 || m_unionIdx == m_field)) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
// read the length // read the length
if (m_buffIt >= m_buffLen) { if (m_buffIt >= m_buffLen) {
@@ -477,7 +477,7 @@ constexpr Result<ArrayLength> MetalClawReaderTemplate<HandlerMaker>::arrayLength
template<auto HandlerMaker> template<auto HandlerMaker>
template<typename I> template<typename I>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::readInteger(I *val) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::readInteger(I *val) noexcept {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
std::size_t bytesRead = 0; std::size_t bytesRead = 0;
if (m_buffIt >= m_buffLen) { if (m_buffIt >= m_buffLen) {
@@ -499,7 +499,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::readInteger(I *val) noexc
template<auto HandlerMaker> template<auto HandlerMaker>
template<typename T, typename CB> template<typename T, typename CB>
constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, CB cb) noexcept { constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, CB cb) noexcept {
if (m_unionIdx == -1 || m_unionIdx == m_field) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
// read the length // read the length
if (m_buffIt >= m_buffLen) { if (m_buffIt >= m_buffLen) {
@@ -512,7 +512,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, CB cb)
// read the list // read the list
auto reader = child(""); auto reader = child("");
auto handler = HandlerMaker(&reader); auto handler = HandlerMaker(&reader);
handler.setTypeInfo("List", 0, {}, static_cast<int>(len)); handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len));
for (std::size_t i = 0; i < len; ++i) { for (std::size_t i = 0; i < len; ++i) {
T val; T val;
oxReturnError(handler.field("", &val)); oxReturnError(handler.field("", &val));
@@ -526,7 +526,7 @@ constexpr Error MetalClawReaderTemplate<HandlerMaker>::field(const char*, CB cb)
template<auto HandlerMaker> template<auto HandlerMaker>
constexpr StringLength MetalClawReaderTemplate<HandlerMaker>::stringLength(const char*) noexcept { constexpr StringLength MetalClawReaderTemplate<HandlerMaker>::stringLength(const char*) noexcept {
if ((m_unionIdx == -1 || m_unionIdx == m_field)) { if (m_unionIdx == -1 || static_cast<std::size_t>(m_unionIdx) == m_field) {
if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) { if (m_fieldPresence.get(static_cast<std::size_t>(m_field))) {
// read the length // read the length
std::size_t bytesRead = 0; std::size_t bytesRead = 0;
@@ -539,10 +539,10 @@ constexpr StringLength MetalClawReaderTemplate<HandlerMaker>::stringLength(const
template<auto HandlerMaker> template<auto HandlerMaker>
template<typename T> template<typename T>
constexpr void MetalClawReaderTemplate<HandlerMaker>::setTypeInfo(const char*, int, const Vector<String>&, int fields) noexcept { constexpr void MetalClawReaderTemplate<HandlerMaker>::setTypeInfo(const char*, int, const Vector<String>&, std::size_t fields) noexcept {
m_fields = fields; m_fields = fields;
m_buffIt = static_cast<std::size_t>((fields / 8 + 1) - (fields % 8 == 0)); m_buffIt = static_cast<std::size_t>((fields / 8 + 1) - (fields % 8 == 0));
m_fieldPresence.setFields(fields); m_fieldPresence.setFields(static_cast<int>(fields));
m_fieldPresence.setMaxLen(static_cast<int>(m_buffIt)); m_fieldPresence.setMaxLen(static_cast<int>(m_buffIt));
} }
@@ -565,7 +565,7 @@ template<auto HandlerMaker>
[[nodiscard]] [[nodiscard]]
constexpr int MetalClawReaderTemplate<HandlerMaker>::whichFieldPresent(const char*, const ModelUnion &u) const noexcept { constexpr int MetalClawReaderTemplate<HandlerMaker>::whichFieldPresent(const char*, const ModelUnion &u) const noexcept {
FieldBitmapReader<const uint8_t*> p(m_buff + m_buffIt, m_buffLen - m_buffIt); FieldBitmapReader<const uint8_t*> p(m_buff + m_buffIt, m_buffLen - m_buffIt);
p.setFields(u.fieldCount()); p.setFields(static_cast<int>(u.fieldCount()));
for (auto i = 0u; i < u.fieldCount(); ++i) { for (auto i = 0u; i < u.fieldCount(); ++i) {
if (p.get(i)) { if (p.get(i)) {
return static_cast<int>(i); return static_cast<int>(i);
+6 -6
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -104,7 +104,7 @@ class MetalClawWriter {
template<typename T = std::nullptr_t> template<typename T = std::nullptr_t>
constexpr void setTypeInfo(const char *name = T::TypeName, int version = T::TypeVersion, constexpr void setTypeInfo(const char *name = T::TypeName, int version = T::TypeVersion,
const Vector<String>& = {}, int fields = ModelFieldCount_v<T>) noexcept; const Vector<String>& = {}, std::size_t fields = ModelFieldCount_v<T>) noexcept;
/** /**
* stringLength is not implemented in MetalClawWriter * stringLength is not implemented in MetalClawWriter
@@ -342,7 +342,7 @@ constexpr Error MetalClawWriter::field(const char*, T *val, std::size_t len) noe
MetalClawWriter writer(m_buff + m_buffIt, m_buffLen - m_buffIt); MetalClawWriter writer(m_buff + m_buffIt, m_buffLen - m_buffIt);
ModelHandlerInterface handler{&writer}; ModelHandlerInterface handler{&writer};
handler.setTypeInfo<T>("List", 0, {}, static_cast<int>(len)); handler.setTypeInfo<T>("List", 0, {}, static_cast<std::size_t>(len));
// write the array // write the array
for (std::size_t i = 0; i < len; i++) { for (std::size_t i = 0; i < len; i++) {
@@ -400,9 +400,9 @@ constexpr Error MetalClawWriter::field(const char *name, HashMap<String, T> *val
} }
template<typename T> template<typename T>
constexpr void MetalClawWriter::setTypeInfo(const char*, int, const Vector<String>&, int fields) noexcept { constexpr void MetalClawWriter::setTypeInfo(const char*, int, const Vector<String>&, std::size_t fields) noexcept {
m_fields = fields; m_fields = static_cast<int>(fields);
m_fieldPresence.setFields(fields); m_fieldPresence.setFields(static_cast<int>(fields));
m_buffIt = static_cast<std::size_t>(m_fieldPresence.getMaxLen()); m_buffIt = static_cast<std::size_t>(m_fieldPresence.getMaxLen());
ox_memset(m_buff, 0, m_buffIt); ox_memset(m_buff, 0, m_buffIt);
} }
+5
View File
@@ -5,6 +5,11 @@ add_library(
modelvalue.cpp modelvalue.cpp
) )
if(NOT MSVC)
target_compile_options(OxModel PRIVATE -Wconversion)
target_compile_options(OxModel PRIVATE -Wsign-conversion)
endif()
target_link_libraries( target_link_libraries(
OxModel PUBLIC OxModel PUBLIC
OxStd OxStd
+3 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -94,7 +94,7 @@ class TypeDescWriter {
constexpr void setTypeInfo(CRStringView name = T::TypeName, constexpr void setTypeInfo(CRStringView name = T::TypeName,
int version = T::TypeVersion, int version = T::TypeVersion,
const TypeParamPack &typeParams = {}, const TypeParamPack &typeParams = {},
int fields = ModelFieldCount_v<T>) noexcept; std::size_t fields = ModelFieldCount_v<T>) noexcept;
template<typename T> template<typename T>
constexpr Error field(CRStringView name, const T *val, std::size_t valLen, constexpr Error field(CRStringView name, const T *val, std::size_t valLen,
@@ -179,7 +179,7 @@ constexpr TypeDescWriter::TypeDescWriter(TypeStore *typeStore) noexcept: m_typeS
template<typename T> template<typename T>
constexpr void TypeDescWriter::setTypeInfo(CRStringView typeName, int typeVersion, constexpr void TypeDescWriter::setTypeInfo(CRStringView typeName, int typeVersion,
const TypeParamPack &typeParams, int) noexcept { const TypeParamPack &typeParams, std::size_t) noexcept {
PrimitiveType pt; PrimitiveType pt;
if constexpr(is_union_v<T>) { if constexpr(is_union_v<T>) {
pt = PrimitiveType::Union; pt = PrimitiveType::Union;
+2 -2
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -24,7 +24,7 @@ class FieldCounter {
int fields = 0; int fields = 0;
template<typename U = std::nullptr_t> template<typename U = std::nullptr_t>
constexpr void setTypeInfo(CRStringView = "", int = 0, const Vector<String>& = {}, int = 0) { constexpr void setTypeInfo(CRStringView = "", int = 0, const Vector<String>& = {}, std::size_t = 0) {
} }
template<typename U> template<typename U>
+6 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -24,8 +24,11 @@ class ModelHandlerInterface {
} }
template<typename T = std::nullptr_t> template<typename T = std::nullptr_t>
constexpr void setTypeInfo(const char *name = T::TypeName, int version = T::TypeVersion, constexpr void setTypeInfo(
const Vector<String> &typeParams = {}, int fields = ModelFieldCount_v<T>) noexcept { const char *name = T::TypeName,
int version = T::TypeVersion,
const Vector<String> &typeParams = {},
std::size_t fields = ModelFieldCount_v<T>) noexcept {
m_handler->template setTypeInfo<T>(name, version, typeParams, fields); m_handler->template setTypeInfo<T>(name, version, typeParams, fields);
} }
+1 -5
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -272,10 +272,6 @@ class Equals {
} }
} }
template<typename T = void>
constexpr void setTypeInfo(const char* = T::TypeName, const Vector<String>& = {}, int = T::Fields) noexcept {
}
[[nodiscard]] [[nodiscard]]
static constexpr auto opType() noexcept { static constexpr auto opType() noexcept {
return OpType::Read; return OpType::Read;
+3 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -769,7 +769,7 @@ constexpr std::size_t alignOf(const ModelValue &t) noexcept {
} }
constexpr Error model(auto *h, CommonPtrWith<ModelObject> auto *obj) noexcept { constexpr Error model(auto *h, CommonPtrWith<ModelObject> auto *obj) noexcept {
h->template setTypeInfo<ModelObject>(obj->typeName().c_str(), obj->typeVersion(), {}, static_cast<int>(obj->m_fieldsOrder.size())); h->template setTypeInfo<ModelObject>(obj->typeName().c_str(), obj->typeVersion(), {}, obj->m_fieldsOrder.size());
for (auto &f : obj->m_fieldsOrder) { for (auto &f : obj->m_fieldsOrder) {
oxReturnError(h->field(f->name.c_str(), &f->value)); oxReturnError(h->field(f->name.c_str(), &f->value));
} }
@@ -777,7 +777,7 @@ constexpr Error model(auto *h, CommonPtrWith<ModelObject> auto *obj) noexcept {
} }
constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept { constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept {
h->template setTypeInfo<ModelUnion>(obj->typeName().c_str(), obj->typeVersion(), {}, static_cast<int>(obj->m_fieldsOrder.size())); h->template setTypeInfo<ModelUnion>(obj->typeName().c_str(), obj->typeVersion(), {}, obj->m_fieldsOrder.size());
for (auto &f : obj->m_fieldsOrder) { for (auto &f : obj->m_fieldsOrder) {
oxReturnError(h->field(f->name.c_str(), &f->value)); oxReturnError(h->field(f->name.c_str(), &f->value));
} }
+3 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -25,7 +25,7 @@ struct TypeNameCatcher {
constexpr TypeNameCatcher() noexcept = default; constexpr TypeNameCatcher() noexcept = default;
template<typename T = std::nullptr_t> template<typename T = std::nullptr_t>
constexpr void setTypeInfo(const char *n = T::TypeName, int v = T::TypeVersion, const Vector<String>& = {}, int = 0) noexcept { constexpr void setTypeInfo(const char *n = T::TypeName, int v = T::TypeVersion, const Vector<String>& = {}, std::size_t = 0) noexcept {
this->name = n; this->name = n;
this->version = v; this->version = v;
} }
@@ -59,7 +59,7 @@ struct TypeInfoCatcher {
constexpr TypeInfoCatcher() noexcept = default; constexpr TypeInfoCatcher() noexcept = default;
template<typename T = std::nullptr_t> template<typename T = std::nullptr_t>
constexpr void setTypeInfo(const char *n = T::TypeName, int v = T::TypeVersion, const Vector<String>& = {}, int = 0) noexcept { constexpr void setTypeInfo(const char *n = T::TypeName, int v = T::TypeVersion, const Vector<String>& = {}, std::size_t = 0) noexcept {
this->name = n; this->name = n;
this->version = v; this->version = v;
} }
+1 -1
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
+1 -1
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
+1
View File
@@ -6,6 +6,7 @@ add_library(
if(NOT MSVC) if(NOT MSVC)
target_compile_options(OxOrganicClaw PRIVATE -Wsign-conversion) target_compile_options(OxOrganicClaw PRIVATE -Wsign-conversion)
target_compile_options(OxOrganicClaw PRIVATE -Wconversion)
endif() endif()
target_link_libraries( target_link_libraries(
+3 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -107,7 +107,7 @@ class OrganicClawReader {
} }
template<typename T = void> template<typename T = void>
constexpr void setTypeInfo(const char*, int, const Vector<String>& = {}, int = {}) noexcept { constexpr void setTypeInfo(const char*, int, const Vector<String>& = {}, std::size_t = {}) noexcept {
} }
/** /**
@@ -205,7 +205,7 @@ Error OrganicClawReader::field(const char *key, BasicString<L> *val) noexcept {
template<std::size_t L> template<std::size_t L>
Error OrganicClawReader::field(const char *key, BString<L> *val) noexcept { Error OrganicClawReader::field(const char *key, BString<L> *val) noexcept {
return field(key, SerStr(val->data(), val->cap())); return field(key, SerStr(val->data(), static_cast<int>(val->cap())));
} }
// array handler // array handler
+3 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -332,7 +332,7 @@ const std::map<std::string_view, ox::Error(*)()> tests = {
} }
case ox::PrimitiveType::String: { case ox::PrimitiveType::String: {
ox::Vector<char> v(rdr->stringLength(fieldName) + 1); ox::Vector<char> v(rdr->stringLength(fieldName) + 1);
oxAssert(rdr->field(fieldName, ox::SerStr(v.data(), v.size())), "Walking model failed."); oxAssert(rdr->field(fieldName, ox::SerStr(v.data(), static_cast<int>(v.size()))), "Walking model failed.");
oxOutf("{}:\tstring:\t{}\n", fieldName, v.data()); oxOutf("{}:\tstring:\t{}\n", fieldName, v.data());
break; break;
} }
@@ -362,5 +362,5 @@ int main(int argc, const char **args) {
oxErrorf("Test {} not found", testName); oxErrorf("Test {} not found", testName);
return 1; return 1;
} }
return test(); return static_cast<int>(test());
} }
+3 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -146,7 +146,7 @@ class OrganicClawWriter {
template<std::size_t L> template<std::size_t L>
Error field(const char *key, BString<L> *val) noexcept { Error field(const char *key, BString<L> *val) noexcept {
return field(key, SerStr(val->data(), val->cap())); return field(key, SerStr(val->data(), static_cast<int>(val->cap())));
} }
template<std::size_t L> template<std::size_t L>
@@ -180,7 +180,7 @@ class OrganicClawWriter {
template<typename T = void> template<typename T = void>
constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion, constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion,
const Vector<String>& = {}, int = ModelFieldCount_v<T>) noexcept { const Vector<String>& = {}, std::size_t = ModelFieldCount_v<T>) noexcept {
} }
static constexpr auto opType() noexcept { static constexpr auto opType() noexcept {
+5
View File
@@ -4,6 +4,11 @@ add_library(
preloader.cpp preloader.cpp
) )
if(NOT MSVC)
target_compile_options(OxPreloader PRIVATE -Wsign-conversion)
target_compile_options(OxPreloader PRIVATE -Wconversion)
endif()
target_link_libraries( target_link_libraries(
OxPreloader PUBLIC OxPreloader PUBLIC
OxClaw OxClaw
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/ */
#pragma once #pragma once
@@ -27,7 +27,7 @@ struct AlignmentCatcher: public ModelHandlerBase<AlignmentCatcher<PlatSpec>> {
template<typename T> template<typename T>
constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion, constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion,
const Vector<String>& = {}, int = ModelFieldCount_v<T>) noexcept {} const Vector<String>& = {}, std::size_t = ModelFieldCount_v<T>) noexcept {}
template<typename T, bool force> template<typename T, bool force>
constexpr ox::Error field(CRStringView name, const UnionView<T, force> val) noexcept { constexpr ox::Error field(CRStringView name, const UnionView<T, force> val) noexcept {
+19 -10
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/ */
#pragma once #pragma once
@@ -78,8 +78,11 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>> {
std::size_t sz = 0) noexcept; std::size_t sz = 0) noexcept;
template<typename T> template<typename T>
constexpr void setTypeInfo(ox::CRStringView = T::TypeName, int = T::TypeVersion, constexpr void setTypeInfo(
const Vector<String>& = {}, int = ModelFieldCount_v<T>) noexcept {} ox::CRStringView = T::TypeName,
int = T::TypeVersion,
const Vector<String>& = {},
std::size_t = ModelFieldCount_v<T>) noexcept {}
template<typename U, bool force> template<typename U, bool force>
constexpr ox::Error field(CRStringView, const ox::UnionView<U, force> val) noexcept; constexpr ox::Error field(CRStringView, const ox::UnionView<U, force> val) noexcept;
@@ -276,7 +279,7 @@ template<typename PlatSpec>
constexpr ox::Error Preloader<PlatSpec>::offsetPtrs(std::size_t offset) noexcept { constexpr ox::Error Preloader<PlatSpec>::offsetPtrs(std::size_t offset) noexcept {
for (const auto &p : m_ptrs) { for (const auto &p : m_ptrs) {
oxReturnError(m_writer.seekp(p.loc)); oxReturnError(m_writer.seekp(p.loc));
const auto val = PlatSpec::template correctEndianness<typename PlatSpec::PtrType>(p.value + offset); const auto val = PlatSpec::template correctEndianness<typename PlatSpec::PtrType>(static_cast<typename PlatSpec::PtrType>(p.value + offset));
oxReturnError(ox::serialize(&m_writer, val)); oxReturnError(ox::serialize(&m_writer, val));
} }
oxReturnError(m_writer.seekp(0, ox::ios_base::end)); oxReturnError(m_writer.seekp(0, ox::ios_base::end));
@@ -307,18 +310,22 @@ constexpr ox::Error Preloader<PlatSpec>::fieldVector(CRStringView name, const ox
template<typename PlatSpec> template<typename PlatSpec>
template<typename T, std::size_t SmallVectorSize, typename Allocator> template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr ox::Error Preloader<PlatSpec>::fieldVector(CRStringView name, const ox::Vector<T, SmallVectorSize, Allocator> *val) noexcept { constexpr ox::Error Preloader<PlatSpec>::fieldVector(
CRStringView name, const ox::Vector<T, SmallVectorSize, Allocator> *val) noexcept {
// serialize the Vector // serialize the Vector
ox::VectorMemMap<PlatSpec> vecVal{ ox::VectorMemMap<PlatSpec> vecVal{
.smallVecSize = SmallVectorSize * sizeOf<PlatSpec>(static_cast<T*>(nullptr)), .smallVecSize = SmallVectorSize * sizeOf<PlatSpec>(static_cast<T*>(nullptr)),
.size = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(val->size())), .size = PlatSpec::correctEndianness(
.cap = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(val->size())), static_cast<typename PlatSpec::size_t>(val->size())),
.cap = PlatSpec::correctEndianness(
static_cast<typename PlatSpec::size_t>(val->size())),
}; };
return fieldVector(name, val, vecVal); return fieldVector(name, val, vecVal);
} }
template<typename PlatSpec> template<typename PlatSpec>
constexpr ox::Error Preloader<PlatSpec>::fieldVector(CRStringView, const auto *val, ox::VectorMemMap<PlatSpec> vecVal) noexcept { constexpr ox::Error Preloader<PlatSpec>::fieldVector(
CRStringView, const auto *val, ox::VectorMemMap<PlatSpec> vecVal) noexcept {
oxReturnError(pad(&vecVal)); oxReturnError(pad(&vecVal));
const auto vecValPt = m_writer.tellp(); const auto vecValPt = m_writer.tellp();
// serialize the Vector elements // serialize the Vector elements
@@ -331,7 +338,8 @@ constexpr ox::Error Preloader<PlatSpec>::fieldVector(CRStringView, const auto *v
oxReturnError(this->interface()->field(nullptr, &val->operator[](i))); oxReturnError(this->interface()->field(nullptr, &val->operator[](i)));
} }
m_unionIdx.pop_back(); m_unionIdx.pop_back();
vecVal.items = PlatSpec::correctEndianness(p + PlatSpec::RomStart); vecVal.items = PlatSpec::correctEndianness(
static_cast<typename PlatSpec::size_t>(p + PlatSpec::RomStart));
oxReturnError(m_writer.seekp(vecValPt)); oxReturnError(m_writer.seekp(vecValPt));
} else { } else {
vecVal.items = 0; vecVal.items = 0;
@@ -349,7 +357,8 @@ constexpr bool Preloader<PlatSpec>::unionCheckAndIt() noexcept {
} }
template<typename PlatSpec, typename T> template<typename PlatSpec, typename T>
constexpr ox::Error preload(Preloader<PlatSpec> *pl, ox::CommonPtrWith<T> auto *obj) noexcept { constexpr ox::Error preload(
Preloader<PlatSpec> *pl, ox::CommonPtrWith<T> auto *obj) noexcept {
oxReturnError(model(pl->interface(), obj)); oxReturnError(model(pl->interface(), obj));
return pl->pad(obj); return pl->pad(obj);
} }
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/ */
#pragma once #pragma once
@@ -33,7 +33,7 @@ class SizeCatcher: public ModelHandlerBase<SizeCatcher<PlatSpec>> {
template<typename T> template<typename T>
constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion, constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion,
const Vector<String>& = {}, int = ModelFieldCount_v<T>) noexcept {} const Vector<String>& = {}, std::size_t = ModelFieldCount_v<T>) noexcept {}
template<typename T, bool force> template<typename T, bool force>
constexpr ox::Error field(const char*, UnionView<T, force>) noexcept; constexpr ox::Error field(const char*, UnionView<T, force>) noexcept;
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/ */
#pragma once #pragma once
@@ -21,7 +21,7 @@ class UnionSizeCatcher: public ModelHandlerBase<UnionSizeCatcher<PlatSpec>> {
public: public:
template<typename T> template<typename T>
constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion, constexpr void setTypeInfo(const char* = T::TypeName, int = T::TypeVersion,
const Vector<String>& = {}, int = ModelFieldCount_v<T>) noexcept {} const Vector<String>& = {}, std::size_t = ModelFieldCount_v<T>) noexcept {}
template<typename T, bool force> template<typename T, bool force>
constexpr ox::Error field(CRStringView, const UnionView<T, force> val) noexcept { constexpr ox::Error field(CRStringView, const UnionView<T, force> val) noexcept {
+1
View File
@@ -43,6 +43,7 @@ add_library(
if(NOT MSVC) if(NOT MSVC)
target_compile_options(OxStd PRIVATE -Wsign-conversion) target_compile_options(OxStd PRIVATE -Wsign-conversion)
target_compile_options(OxStd PRIVATE -Wconversion)
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
target_compile_options(OxStd PUBLIC -export-dynamic) target_compile_options(OxStd PUBLIC -export-dynamic)
#target_link_options(OxStd PUBLIC -W1,-E) #target_link_options(OxStd PUBLIC -W1,-E)
+19 -38
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -24,7 +24,7 @@ constexpr T byteSwap(typename enable_if<sizeof(T) == 1, T>::type i) noexcept {
template<typename T> template<typename T>
[[nodiscard]] [[nodiscard]]
constexpr T byteSwap(typename enable_if<sizeof(T) == 2, T>::type i) noexcept { constexpr T byteSwap(typename enable_if<sizeof(T) == 2, T>::type i) noexcept {
return (i << 8) | (i >> 8); return static_cast<T>(i << 8) | static_cast<T>(i >> 8);
} }
template<typename T> template<typename T>
@@ -102,73 +102,54 @@ class OX_PACKED ByteSwapInteger {
constexpr ByteSwapInteger(T value) noexcept: m_value(conditionalByteSwap<T, byteSwap>(value)) { constexpr ByteSwapInteger(T value) noexcept: m_value(conditionalByteSwap<T, byteSwap>(value)) {
} }
constexpr const ByteSwapInteger &operator=(const ByteSwapInteger &other) noexcept { constexpr ByteSwapInteger &operator=(const ByteSwapInteger &other) noexcept {
m_value = other.m_value; m_value = other.m_value;
return *this; return *this;
} }
template<typename I> constexpr ByteSwapInteger &operator=(T value) noexcept {
constexpr T operator=(I value) noexcept {
m_value = conditionalByteSwap<T, byteSwap>(value); m_value = conditionalByteSwap<T, byteSwap>(value);
return value; return *this;
} }
constexpr operator T() const noexcept { constexpr operator T() const noexcept {
return conditionalByteSwap<T, byteSwap>(m_value); return conditionalByteSwap<T, byteSwap>(m_value);
} }
template<typename I> constexpr ByteSwapInteger operator+=(T other) noexcept {
constexpr T operator+=(I other) noexcept { const auto newVal = static_cast<T>(*this + other);
auto newVal = *this + other;
m_value = conditionalByteSwap<T, byteSwap>(newVal); m_value = conditionalByteSwap<T, byteSwap>(newVal);
return newVal; return *this;
} }
template<typename I> constexpr ByteSwapInteger operator-=(T other) noexcept {
constexpr T operator-=(I other) noexcept { const auto newVal = static_cast<T>(*this - other);
auto newVal = *this - other;
m_value = conditionalByteSwap<T, byteSwap>(newVal); m_value = conditionalByteSwap<T, byteSwap>(newVal);
return newVal; return *this;
} }
template<typename I> constexpr ByteSwapInteger operator*=(T other) noexcept {
constexpr T operator*=(I other) noexcept { const auto newVal = static_cast<T>(*this * other);
auto newVal = *this * other;
m_value = conditionalByteSwap<T, byteSwap>(newVal); m_value = conditionalByteSwap<T, byteSwap>(newVal);
return newVal; return *this;
} }
template<typename I> constexpr ByteSwapInteger operator/=(T other) noexcept {
constexpr T operator/=(I other) noexcept { const auto newVal = static_cast<T>(*this / other);
auto newVal = *this / other;
m_value = conditionalByteSwap<T, byteSwap>(newVal); m_value = conditionalByteSwap<T, byteSwap>(newVal);
return newVal; return *this;
} }
// Prefix increment // Prefix increment
constexpr T operator++() noexcept { constexpr ByteSwapInteger operator++() noexcept {
return operator+=(1); return operator+=(1);
} }
// Postfix increment
constexpr T operator++(int) noexcept {
auto old = *this;
++*this;
return old;
}
// Prefix decrement // Prefix decrement
constexpr T operator--() noexcept { constexpr ByteSwapInteger operator--() noexcept {
return operator-=(1); return operator-=(1);
} }
// Postfix decrement
constexpr T operator--(int) noexcept {
auto old = *this;
--*this;
return old;
}
template<typename I> template<typename I>
constexpr T operator&=(I other) noexcept { constexpr T operator&=(I other) noexcept {
auto newVal = *this & other; auto newVal = *this & other;
+3 -3
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -51,7 +51,7 @@ struct [[nodiscard]] Error {
explicit constexpr Error(const char *file, uint32_t line, ErrorCode errCode, const char *msg = nullptr) noexcept { explicit constexpr Error(const char *file, uint32_t line, ErrorCode errCode, const char *msg = nullptr) noexcept {
this->file = file; this->file = file;
this->line = line; this->line = static_cast<uint16_t>(line);
this->msg = msg; this->msg = msg;
this->errCode = errCode; this->errCode = errCode;
} }
@@ -96,7 +96,7 @@ struct Exception: public std::exception {
explicit inline Exception(const char *file, uint32_t line, ErrorCode errCode, const char *msg = "") noexcept { explicit inline Exception(const char *file, uint32_t line, ErrorCode errCode, const char *msg = "") noexcept {
this->file = file; this->file = file;
this->line = line; this->line = static_cast<uint16_t>(line);
this->msg = msg; this->msg = msg;
this->errCode = errCode; this->errCode = errCode;
} }
+5 -4
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -148,7 +148,8 @@ template<typename K, typename T>
constexpr T &HashMap<K, T>::operator[](const K &k) { constexpr T &HashMap<K, T>::operator[](const K &k) {
auto &p = access(m_pairs, k); auto &p = access(m_pairs, k);
if (p == nullptr) { if (p == nullptr) {
if (m_pairs.size() * 0.7 < m_keys.size()) { if (static_cast<double>(m_pairs.size()) * 0.7 <
static_cast<double>(m_keys.size())) {
expand(); expand();
} }
p = new Pair; p = new Pair;
@@ -247,7 +248,7 @@ constexpr uint64_t HashMap<K, T>::hash(auto k) noexcept {
template<typename K, typename T> template<typename K, typename T>
constexpr typename HashMap<K, T>::Pair *const&HashMap<K, T>::access(const Vector<Pair*> &pairs, const K &k) const { constexpr typename HashMap<K, T>::Pair *const&HashMap<K, T>::access(const Vector<Pair*> &pairs, const K &k) const {
auto h = hash(k) % pairs.size(); auto h = static_cast<std::size_t>(hash(k) % pairs.size());
while (true) { while (true) {
const auto &p = pairs[h]; const auto &p = pairs[h];
if (p == nullptr || ox_strcmp(p->key, k) == 0) { if (p == nullptr || ox_strcmp(p->key, k) == 0) {
@@ -260,7 +261,7 @@ constexpr typename HashMap<K, T>::Pair *const&HashMap<K, T>::access(const Vector
template<typename K, typename T> template<typename K, typename T>
constexpr typename HashMap<K, T>::Pair *&HashMap<K, T>::access(Vector<Pair*> &pairs, const K &k) { constexpr typename HashMap<K, T>::Pair *&HashMap<K, T>::access(Vector<Pair*> &pairs, const K &k) {
auto h = hash(k) % pairs.size(); auto h = static_cast<std::size_t>(hash(k) % pairs.size());
while (true) { while (true) {
auto &p = pairs[h]; auto &p = pairs[h];
bool matches = [&] { bool matches = [&] {
+1 -1
View File
@@ -357,7 +357,7 @@ constexpr ox::Result<int> ox_atoi(ox::CRStringView str) noexcept {
int total = 0; int total = 0;
int multiplier = 1; int multiplier = 1;
for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) { for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) {
auto s = static_cast<uint64_t>(i); auto s = static_cast<std::size_t>(i);
if (str[s] >= '0' && str[s] <= '9') { if (str[s] >= '0' && str[s] <= '9') {
total += (str[s] - '0') * multiplier; total += (str[s] - '0') * multiplier;
multiplier *= 10; multiplier *= 10;
+5 -4
View File
@@ -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 * 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 * License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -129,15 +129,16 @@ template<typename Integer, typename T>
constexpr T ox_itoa(Integer v, T str) noexcept { constexpr T ox_itoa(Integer v, T str) noexcept {
if (v) { if (v) {
ox::ResizedInt_t<Integer, 64> mod = 1000000000000000000; ox::ResizedInt_t<Integer, 64> mod = 1000000000000000000;
ox::ResizedInt_t<Integer, 64> val = v;
constexpr auto base = 10; constexpr auto base = 10;
auto it = 0; auto it = 0;
if (v < 0) { if (val < 0) {
str[it] = '-'; str[it] = '-';
it++; it++;
} }
while (mod) { while (mod) {
auto digit = v / mod; auto digit = val / mod;
v %= mod; val %= mod;
mod /= base; mod /= base;
if (it || digit) { if (it || digit) {
ox::ResizedInt_t<Integer, 64> start = '0'; ox::ResizedInt_t<Integer, 64> start = '0';
+1 -1
View File
@@ -57,7 +57,7 @@ constexpr ox::Result<uint8_t> fromHex(ox::CRStringView v) noexcept {
return OxError(2); return OxError(2);
} }
uint8_t out = 0; uint8_t out = 0;
out += valMap[static_cast<unsigned char>(v[0])] * 16u; out += static_cast<uint8_t>(valMap[static_cast<unsigned char>(v[0])] * 16);
out += valMap[static_cast<unsigned char>(v[1])]; out += valMap[static_cast<unsigned char>(v[1])];
return out; return out;
} }
+8 -2
View File
@@ -70,7 +70,10 @@ void bind(const FrameBuffer &fb) noexcept {
} }
static ox::Result<GLShader> buildShader(GLuint shaderType, const GLchar *src, ox::CRStringView shaderName) noexcept { static ox::Result<GLShader> buildShader(
GLuint shaderType,
const GLchar *src,
ox::CRStringView shaderName) noexcept {
GLShader shader(glCreateShader(shaderType)); GLShader shader(glCreateShader(shaderType));
glShaderSource(shader, 1, &src, nullptr); glShaderSource(shader, 1, &src, nullptr);
glCompileShader(shader); glCompileShader(shader);
@@ -99,7 +102,10 @@ ox::Result<GLProgram> buildShaderProgram(const GLchar *vert, const GLchar *frag,
return prgm; return prgm;
} }
ox::Result<GLProgram> buildShaderProgram(const ox::String &vert, const ox::String &frag, const ox::String &geo) noexcept { 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()); return buildShaderProgram(vert.c_str(), frag.c_str(), geo.c_str());
} }
+2 -2
View File
@@ -116,7 +116,7 @@ ox::Result<std::size_t> getPreloadAddr(keel::Context *ctx, ox::CRStringView path
oxRequire(stat, ctx->rom->stat(path)); oxRequire(stat, ctx->rom->stat(path));
oxRequire(buff, static_cast<ox::MemFS*>(ctx->rom.get())->directAccess(path)); oxRequire(buff, static_cast<ox::MemFS*>(ctx->rom.get())->directAccess(path));
PreloadPtr p; PreloadPtr p;
oxReturnError(ox::readMC(buff, stat.size, &p)); oxReturnError(ox::readMC(buff, static_cast<std::size_t>(stat.size), &p));
return static_cast<std::size_t>(p.preloadAddr) + ctx->preloadSectionOffset; return static_cast<std::size_t>(p.preloadAddr) + ctx->preloadSectionOffset;
} }
@@ -124,7 +124,7 @@ ox::Result<std::size_t> getPreloadAddr(keel::Context *ctx, const ox::FileAddress
oxRequire(stat, ctx->rom->stat(file)); oxRequire(stat, ctx->rom->stat(file));
oxRequire(buff, static_cast<ox::MemFS*>(ctx->rom.get())->directAccess(file)); oxRequire(buff, static_cast<ox::MemFS*>(ctx->rom.get())->directAccess(file));
PreloadPtr p; PreloadPtr p;
oxReturnError(ox::readMC(buff, stat.size, &p)); oxReturnError(ox::readMC(buff, static_cast<std::size_t>(stat.size), &p));
return static_cast<std::size_t>(p.preloadAddr) + ctx->preloadSectionOffset; return static_cast<std::size_t>(p.preloadAddr) + ctx->preloadSectionOffset;
} }
+1 -1
View File
@@ -26,7 +26,7 @@ if(TURBINE_BUILD_TYPE STREQUAL "Native")
target_link_libraries( target_link_libraries(
NostalgiaStudioModules PUBLIC NostalgiaStudioModules PUBLIC
StudioAppLib StudioAppLib
NostalgiaCore-Studio NostalgiaCore-Studio-ImGui
NostalgiaScene-Studio NostalgiaScene-Studio
) )
if(NOT MSVC) if(NOT MSVC)
+1
View File
@@ -13,6 +13,7 @@ endif()
if(NOT MSVC) if(NOT MSVC)
target_compile_options(NostalgiaCore PUBLIC -Wsign-conversion) target_compile_options(NostalgiaCore PUBLIC -Wsign-conversion)
target_compile_options(NostalgiaCore PRIVATE -Wconversion)
endif() endif()
target_link_libraries( target_link_libraries(
+14 -3
View File
@@ -46,7 +46,7 @@ constexpr uint8_t blue16(Color16 c) noexcept {
[[nodiscard]] [[nodiscard]]
constexpr uint8_t alpha16(Color16 c) noexcept { constexpr uint8_t alpha16(Color16 c) noexcept {
return c >> 15; return static_cast<uint8_t>(c >> 15);
} }
[[nodiscard]] [[nodiscard]]
@@ -66,7 +66,7 @@ constexpr uint8_t blue32(Color16 c) noexcept {
[[nodiscard]] [[nodiscard]]
constexpr uint8_t alpha32(Color16 c) noexcept { constexpr uint8_t alpha32(Color16 c) noexcept {
return (c >> 15) * 255; return static_cast<uint8_t>((c >> 15) * 255);
} }
@@ -128,9 +128,20 @@ constexpr float bluef(Color32 c) noexcept {
} }
[[nodiscard]]
constexpr Color16 color16(int r, int g, int b, int a = 0) noexcept {
return static_cast<Color16>(ox::min<uint8_t>(static_cast<uint8_t>(r), 31))
| static_cast<Color16>(ox::min<uint8_t>(static_cast<uint8_t>(g), 31) << 5)
| static_cast<Color16>(ox::min<uint8_t>(static_cast<uint8_t>(b), 31) << 10)
| static_cast<Color16>(a << 15);
}
[[nodiscard]] [[nodiscard]]
constexpr Color16 color16(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0) noexcept { constexpr Color16 color16(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0) noexcept {
return ox::min<uint8_t>(r, 31) | (ox::min<uint8_t>(g, 31) << 5) | (ox::min<uint8_t>(b, 31) << 10) | (a << 15); return static_cast<Color16>(ox::min<uint8_t>(r, 31))
| static_cast<Color16>(ox::min<uint8_t>(g, 31) << 5)
| static_cast<Color16>(ox::min<uint8_t>(b, 31) << 10)
| static_cast<Color16>(a << 15);
} }
static_assert(color16(0, 31, 0) == 992); static_assert(color16(0, 31, 0) == 992);
+14 -12
View File
@@ -138,12 +138,12 @@ ox::Error loadBgTileSheet(Context *ctx,
target.pal.palette = MEM_BG_PALETTE; target.pal.palette = MEM_BG_PALETTE;
target.cbbData = &g_cbbData[cbb]; target.cbbData = &g_cbbData[cbb];
target.tileMap = MEM_BG_TILES[cbb].data(); target.tileMap = MEM_BG_TILES[cbb].data();
oxReturnError(ox::readMC(ts, tsStat.size, &target)); oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
// load external palette if available // load external palette if available
if (paletteAddr) { if (paletteAddr) {
oxRequire(palStat, gctx.rom().stat(paletteAddr)); oxRequire(palStat, gctx.rom().stat(paletteAddr));
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr)); oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
oxReturnError(ox::readMC(pal, palStat.size, &target.pal)); oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
} }
// update bpp of all bgs with the updated cbb // update bpp of all bgs with the updated cbb
const auto bpp = g_cbbData[cbb].bpp; const auto bpp = g_cbbData[cbb].bpp;
@@ -164,12 +164,12 @@ ox::Error loadSpriteTileSheet(Context *ctx,
GbaTileMapTarget target; GbaTileMapTarget target;
target.pal.palette = MEM_SPRITE_PALETTE; target.pal.palette = MEM_SPRITE_PALETTE;
target.tileMap = MEM_SPRITE_TILES; target.tileMap = MEM_SPRITE_TILES;
oxReturnError(ox::readMC(ts, tsStat.size, &target)); oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
// load external palette if available // load external palette if available
if (paletteAddr) { if (paletteAddr) {
oxRequire(palStat, gctx.rom().stat(paletteAddr)); oxRequire(palStat, gctx.rom().stat(paletteAddr));
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr)); oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
oxReturnError(ox::readMC(pal, palStat.size, &target.pal)); oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target.pal));
} }
return {}; return {};
} }
@@ -180,7 +180,7 @@ ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAd
target.palette = MEM_BG_PALETTE; target.palette = MEM_BG_PALETTE;
oxRequire(palStat, gctx.rom().stat(paletteAddr)); oxRequire(palStat, gctx.rom().stat(paletteAddr));
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr)); oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
oxReturnError(ox::readMC(pal, palStat.size, &target)); oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
return {}; return {};
} }
@@ -190,7 +190,7 @@ ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &p
target.palette = &MEM_SPRITE_PALETTE[cbb]; target.palette = &MEM_SPRITE_PALETTE[cbb];
oxRequire(palStat, gctx.rom().stat(paletteAddr)); oxRequire(palStat, gctx.rom().stat(paletteAddr));
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr)); oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
oxReturnError(ox::readMC(pal, palStat.size, &target)); oxReturnError(ox::readMC(pal, static_cast<std::size_t>(palStat.size), &target));
return {}; return {};
} }
@@ -217,7 +217,7 @@ void hideSprite(Context*, unsigned idx) noexcept {
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); //oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
teagba::GbaSpriteAttrUpdate oa; teagba::GbaSpriteAttrUpdate oa;
oa.attr0 = 2 << 8; oa.attr0 = 2 << 8;
oa.idx = idx; oa.idx = static_cast<uint16_t>(idx);
teagba::addSpriteUpdate(oa); teagba::addSpriteUpdate(oa);
} }
@@ -231,14 +231,16 @@ void setSprite(Context*,
unsigned flipX) noexcept { unsigned flipX) noexcept {
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); //oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
teagba::GbaSpriteAttrUpdate oa; teagba::GbaSpriteAttrUpdate oa;
oa.attr0 = static_cast<uint16_t>(y & ox::onMask<uint8_t>(0b111'1111)) oa.attr0 = static_cast<uint16_t>(
static_cast<uint16_t>(y & ox::onMask<uint8_t>(0b111'1111))
| (static_cast<uint16_t>(1) << 10) // enable alpha | (static_cast<uint16_t>(1) << 10) // enable alpha
| (static_cast<uint16_t>(spriteShape) << 14); | (static_cast<uint16_t>(spriteShape) << 14));
oa.attr1 = (static_cast<uint16_t>(x) & ox::onMask<uint8_t>(8)) oa.attr1 = static_cast<uint16_t>(
(static_cast<uint16_t>(x) & ox::onMask<uint8_t>(8))
| (static_cast<uint16_t>(flipX) << 12) | (static_cast<uint16_t>(flipX) << 12)
| (static_cast<uint16_t>(spriteSize) << 14); | (static_cast<uint16_t>(spriteSize) << 14));
oa.attr2 = static_cast<uint16_t>(tileIdx & ox::onMask<uint16_t>(8)); oa.attr2 = static_cast<uint16_t>(tileIdx & ox::onMask<uint16_t>(8));
oa.idx = idx; oa.idx = static_cast<uint16_t>(idx);
teagba::addSpriteUpdate(oa); teagba::addSpriteUpdate(oa);
} }
+16 -5
View File
@@ -154,7 +154,14 @@ static void initBackgroundBufferObjects(Context *ctx, glutils::BufferSet *bg) no
const auto i = bgVertexRow(x, y); const auto i = bgVertexRow(x, y);
auto vbo = &bg->vertices[i * static_cast<std::size_t>(BgVertexVboLength)]; auto vbo = &bg->vertices[i * static_cast<std::size_t>(BgVertexVboLength)];
auto ebo = &bg->elements[i * static_cast<std::size_t>(BgVertexEboLength)]; auto ebo = &bg->elements[i * static_cast<std::size_t>(BgVertexEboLength)];
setTileBufferObject(ctx, i * BgVertexVboRows, static_cast<float>(x), static_cast<float>(y), 0, vbo, ebo); setTileBufferObject(
ctx,
static_cast<unsigned>(i * BgVertexVboRows),
static_cast<float>(x),
static_cast<float>(y),
0,
vbo,
ebo);
} }
} }
} }
@@ -437,7 +444,7 @@ void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept {
} }
void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept { void glearTileLayer(Context *ctx, unsigned bgIdx) noexcept {
auto &gctx = static_cast<GlContext&>(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
auto &bg = gctx.cbbs[static_cast<std::size_t>(bgIdx)]; auto &bg = gctx.cbbs[static_cast<std::size_t>(bgIdx)];
initBackgroundBufferObjects(&gctx, &bg); initBackgroundBufferObjects(&gctx, &bg);
@@ -526,9 +533,13 @@ void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) no
auto vbo = &bg.vertices[i * renderer::BgVertexVboLength]; auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
auto ebo = &bg.elements[i * renderer::BgVertexEboLength]; auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
renderer::setTileBufferObject( renderer::setTileBufferObject(
ctx, i * renderer::BgVertexVboRows, ctx,
static_cast<float>(x), static_cast<float>(y), static_cast<unsigned>(i * renderer::BgVertexVboRows),
tile, vbo, ebo); static_cast<float>(x),
static_cast<float>(y),
tile,
vbo,
ebo);
bg.updated = true; bg.updated = true;
} }
+17 -5
View File
@@ -1,23 +1,34 @@
add_library( add_library(
NostalgiaCore-Studio OBJECT NostalgiaCore-Studio
studiomodule.cpp
paletteeditor.cpp paletteeditor.cpp
paletteeditor-imgui.cpp
tilesheeteditor-imgui.cpp
tilesheeteditorview.cpp tilesheeteditorview.cpp
tilesheeteditormodel.cpp tilesheeteditormodel.cpp
tilesheetpixelgrid.cpp tilesheetpixelgrid.cpp
tilesheetpixels.cpp tilesheetpixels.cpp
) )
add_library(
NostalgiaCore-Studio-ImGui OBJECT
studiomodule.cpp
paletteeditor-imgui.cpp
tilesheeteditor-imgui.cpp
)
if(NOT MSVC) if(NOT MSVC)
target_compile_options(NostalgiaCore-Studio PRIVATE -Wsign-conversion) target_compile_options(NostalgiaCore-Studio PRIVATE -Wsign-conversion)
target_compile_options(NostalgiaCore-Studio-ImGui PRIVATE -Wsign-conversion)
endif() endif()
target_link_libraries( target_link_libraries(
NostalgiaCore-Studio PUBLIC NostalgiaCore-Studio PUBLIC
Studio
NostalgiaCore NostalgiaCore
Studio
)
target_link_libraries(
NostalgiaCore-Studio-ImGui PUBLIC
NostalgiaCore-Studio
Studio
lodepng lodepng
) )
@@ -25,6 +36,7 @@ target_link_libraries(
install( install(
TARGETS TARGETS
NostalgiaCore-Studio-ImGui
NostalgiaCore-Studio NostalgiaCore-Studio
LIBRARY DESTINATION LIBRARY DESTINATION
${NOSTALGIA_DIST_MODULE} ${NOSTALGIA_DIST_MODULE}
@@ -52,13 +52,15 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
{ {
const auto sz = ImVec2(70, 24); const auto sz = ImVec2(70, 24);
if (ImGui::Button("Add", sz)) { if (ImGui::Button("Add", sz)) {
undoStack()->push(ox::make<AddColorCommand>(&m_pal, 0, m_pal.colors.size())); const auto colorSz = static_cast<int>(m_pal.colors.size());
constexpr Color16 c = 0;
undoStack()->push(ox::make<AddColorCommand>(&m_pal, c, colorSz));
} }
ImGui::SameLine(); ImGui::SameLine();
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size()); ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size());
{ {
if (ImGui::Button("Remove", sz)) { if (ImGui::Button("Remove", sz)) {
undoStack()->push(ox::make<RemoveColorCommand>(&m_pal, m_pal.colors[static_cast<std::size_t>(m_selectedRow)], m_selectedRow)); undoStack()->push(ox::make<RemoveColorCommand>(&m_pal, m_pal.colors[static_cast<std::size_t>(m_selectedRow)], static_cast<int>(m_selectedRow)));
m_selectedRow = ox::min(m_pal.colors.size() - 1, m_selectedRow); m_selectedRow = ox::min(m_pal.colors.size() - 1, m_selectedRow);
} }
ImGui::SameLine(); ImGui::SameLine();
@@ -134,7 +136,7 @@ void PaletteEditorImGui::draw(turbine::Context*) noexcept {
ImGui::InputInt("Blue", &b, 1, 5); ImGui::InputInt("Blue", &b, 1, 5);
const auto newColor = color16(r, g, b, a); const auto newColor = color16(r, g, b, a);
if (c != newColor) { if (c != newColor) {
undoStack()->push(ox::make<UpdateColorCommand>(&m_pal, m_selectedRow, c, newColor)); undoStack()->push(ox::make<UpdateColorCommand>(&m_pal, static_cast<int>(m_selectedRow), c, newColor));
} }
} }
ImGui::EndChild(); ImGui::EndChild();
@@ -35,7 +35,7 @@ ox::Error toPngFile(const ox::String &path, const TileSheet::SubSheet &s, const
++idx; ++idx;
} }
constexpr auto fmt = alpha ? LCT_RGBA : LCT_RGB; constexpr auto fmt = alpha ? LCT_RGBA : LCT_RGB;
return OxError(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8)); return OxError(static_cast<ox::ErrorCode>(lodepng_encode_file(path.c_str(), outData.data(), width, height, fmt, 8)));
} }
TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::CRStringView path): m_tileSheetEditor(ctx, path) { TileSheetEditorImGui::TileSheetEditorImGui(turbine::Context *ctx, ox::CRStringView path): m_tileSheetEditor(ctx, path) {
@@ -361,8 +361,8 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept {
} }
// header // header
if (ImGui::BeginTable("PaletteTable", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingStretchProp)) { if (ImGui::BeginTable("PaletteTable", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingStretchProp)) {
ImGui::TableSetupColumn("No.", 0, 0.45); ImGui::TableSetupColumn("No.", 0, 0.45f);
ImGui::TableSetupColumn("", 0, 0.22); ImGui::TableSetupColumn("", 0, 0.22f);
ImGui::TableSetupColumn("Color16", 0, 3); ImGui::TableSetupColumn("Color16", 0, 3);
ImGui::TableHeadersRow(); ImGui::TableHeadersRow();
if (auto pal = m_tileSheetEditor.pal()) { if (auto pal = m_tileSheetEditor.pal()) {
@@ -130,7 +130,7 @@ class DrawCommand: public TileSheetCommand {
}); });
if (existing == m_changes.cend()) { if (existing == m_changes.cend()) {
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx)); m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx));
subsheet.setPixel(m_img->bpp, idx, m_palIdx); subsheet.setPixel(m_img->bpp, idx, static_cast<uint8_t>(m_palIdx));
return true; return true;
} }
} }
@@ -148,14 +148,14 @@ class DrawCommand: public TileSheetCommand {
void redo() noexcept final { void redo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx); auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) { for (const auto &c : m_changes) {
subsheet.setPixel(m_img->bpp, c.idx, m_palIdx); subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(m_palIdx));
} }
} }
void undo() noexcept final { void undo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx); auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) { for (const auto &c : m_changes) {
subsheet.setPixel(m_img->bpp, c.idx, c.oldPalIdx); subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
} }
} }
@@ -205,14 +205,14 @@ class CutPasteCommand: public TileSheetCommand {
void redo() noexcept final { void redo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx); auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) { for (const auto &c : m_changes) {
subsheet.setPixel(m_img->bpp, c.idx, c.newPalIdx); subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(c.newPalIdx));
} }
} }
void undo() noexcept final { void undo() noexcept final {
auto &subsheet = m_img->getSubSheet(m_subSheetIdx); auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
for (const auto &c : m_changes) { for (const auto &c : m_changes) {
subsheet.setPixel(m_img->bpp, c.idx, c.oldPalIdx); subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
} }
} }
+10 -8
View File
@@ -138,8 +138,8 @@ struct TileSheet {
} else { } else {
if (pBpp == 4) { if (pBpp == 4) {
for (auto p: this->pixels) { for (auto p: this->pixels) {
pPixels->emplace_back(p & 0b1111); pPixels->emplace_back(static_cast<uint8_t>(p & 0b1111));
pPixels->emplace_back(p >> 4); pPixels->emplace_back(static_cast<uint8_t>(p >> 4));
} }
} else { } else {
for (auto p: this->pixels) { for (auto p: this->pixels) {
@@ -226,13 +226,14 @@ struct TileSheet {
pixels.size()); pixels.size());
//oxAssert(pixels.size() == pixelCnt, "Pixel count does not match rows and columns"); //oxAssert(pixels.size() == pixelCnt, "Pixel count does not match rows and columns");
for (std::size_t i = 0; i < pixelCnt; ++i) { for (std::size_t i = 0; i < pixelCnt; ++i) {
const auto colorIdx1 = pixels[i] & 0xF; const auto colorIdx1 = static_cast<uint8_t>(pixels[i] & 0xF);
const auto colorIdx2 = pixels[i] >> 4; const auto colorIdx2 = static_cast<uint8_t>(pixels[i] >> 4);
callback(i * 2 + 0, colorIdx1); callback(i * 2 + 0, colorIdx1);
callback(i * 2 + 1, colorIdx2); callback(i * 2 + 1, colorIdx2);
} }
} else { } else {
const auto pixelCnt = ox::min<std::size_t>(static_cast<std::size_t>(columns * rows * PixelsPerTile), const auto pixelCnt = ox::min<std::size_t>(
static_cast<std::size_t>(columns * rows * PixelsPerTile),
pixels.size()); pixels.size());
for (std::size_t i = 0; i < pixelCnt; ++i) { for (std::size_t i = 0; i < pixelCnt; ++i) {
const auto p = pixels[i]; const auto p = pixels[i];
@@ -242,10 +243,10 @@ struct TileSheet {
} }
constexpr void setPixel(int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept { constexpr void setPixel(int8_t pBpp, uint64_t idx, uint8_t palIdx) noexcept {
auto &pixel = this->pixels[idx / 2]; auto &pixel = this->pixels[static_cast<std::size_t>(idx / 2)];
if (pBpp == 4) { if (pBpp == 4) {
if (idx & 1) { if (idx & 1) {
pixel = (pixel & 0b0000'1111) | (palIdx << 4); pixel = static_cast<uint8_t>((pixel & 0b0000'1111) | (palIdx << 4));
} else { } else {
pixel = (pixel & 0b1111'0000) | (palIdx); pixel = (pixel & 0b1111'0000) | (palIdx);
} }
@@ -279,7 +280,8 @@ struct TileSheet {
*/ */
[[nodiscard]] [[nodiscard]]
constexpr unsigned pixelCnt(int8_t pBpp) const noexcept { constexpr unsigned pixelCnt(int8_t pBpp) const noexcept {
return pBpp == 4 ? pixels.size() * 2 : pixels.size(); const auto pixelsSize = static_cast<unsigned>(pixels.size());
return pBpp == 4 ? pixelsSize * 2 : pixelsSize;
} }
/** /**
+5 -4
View File
@@ -28,10 +28,11 @@ ox::Error Scene::setupDisplay(core::Context *ctx) noexcept {
auto y = 0; auto y = 0;
auto width = m_sceneStatic.rows[layerNo]; auto width = m_sceneStatic.rows[layerNo];
for (const auto &tile : layer) { for (const auto &tile : layer) {
core::setTile(ctx, layerNo, x, y, tile); auto tile8 = static_cast<uint8_t >(tile);
core::setTile(ctx, layerNo, x + 1, y, tile + 1); core::setTile(ctx, layerNo, x, y, tile8);
core::setTile(ctx, layerNo, x, y + 1, tile + 2); core::setTile(ctx, layerNo, x + 1, y, tile8 + 1);
core::setTile(ctx, layerNo, x + 1, y + 1, tile + 3); core::setTile(ctx, layerNo, x, y + 1, tile8 + 2);
core::setTile(ctx, layerNo, x + 1, y + 1, tile8 + 3);
x += 2; x += 2;
if (x >= width * 2) { if (x >= width * 2) {
x = 0; x = 0;
+10 -6
View File
@@ -102,16 +102,20 @@ oxModelEnd()
constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept { constexpr void setTopEdge(uint8_t &layerAttachments, unsigned val) noexcept {
layerAttachments = (layerAttachments & 0b11111100) | val; const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11111100) | val8;
} }
constexpr void setBottomEdge(uint8_t &layerAttachments, unsigned val) noexcept { constexpr void setBottomEdge(uint8_t &layerAttachments, unsigned val) noexcept {
layerAttachments = (layerAttachments & 0b11110011) | (val << 2); const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11110011) | static_cast<uint8_t>(val8 << 2);
} }
constexpr void setLeftEdge(uint8_t &layerAttachments, unsigned val) noexcept { constexpr void setLeftEdge(uint8_t &layerAttachments, unsigned val) noexcept {
layerAttachments = (layerAttachments & 0b11001111) | (val << 4); const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b11001111) | static_cast<uint8_t>(val8 << 4);
} }
constexpr void setRightEdge(uint8_t &layerAttachments, unsigned val) noexcept { constexpr void setRightEdge(uint8_t &layerAttachments, unsigned val) noexcept {
layerAttachments = (layerAttachments & 0b00111111) | (val << 6); const auto val8 = static_cast<uint8_t>(val);
layerAttachments = (layerAttachments & 0b00111111) | static_cast<uint8_t>(val8 << 6);
} }
[[nodiscard]] [[nodiscard]]
@@ -171,8 +175,8 @@ struct SceneStatic {
return {tileMapIdx[i], tileType[i], layerAttachments[i]}; return {tileMapIdx[i], tileType[i], layerAttachments[i]};
} }
constexpr auto setDimensions(ox::Size dim) noexcept { constexpr auto setDimensions(ox::Size dim) noexcept {
columns = dim.width; columns = static_cast<uint16_t>(dim.width);
rows = dim.height; rows = static_cast<uint16_t>(dim.height);
const auto tileCnt = static_cast<unsigned>(columns * rows); const auto tileCnt = static_cast<unsigned>(columns * rows);
tileMapIdx.resize(tileCnt); tileMapIdx.resize(tileCnt);
tileType.resize(tileCnt); tileType.resize(tileCnt);
+1 -2
View File
@@ -60,9 +60,8 @@ void NewMenu::drawNewItemType(turbine::Context *ctx) noexcept {
items[i] = im->name.c_str(); items[i] = im->name.c_str();
++i; ++i;
} }
ImGui::ListBox("Item Type", &m_selectedType, items.get(), m_types.size()); ImGui::ListBox("Item Type", &m_selectedType, items.get(), static_cast<int>(m_types.size()));
drawFirstPageButtons(); drawFirstPageButtons();
ImGui::EndPopup();
}); });
} }
+3 -10
View File
@@ -4,14 +4,14 @@
#pragma once #pragma once
#include <functional>
#include <ox/event/signal.hpp> #include <ox/event/signal.hpp>
#include <ox/std/string.hpp> #include <ox/std/string.hpp>
#include <ox/std/vec.hpp> #include <ox/std/vec.hpp>
#include <turbine/context.hpp> #include <turbine/context.hpp>
#include "imguiuitl.hpp"
namespace studio { namespace studio {
@@ -47,14 +47,7 @@ class Popup {
return m_title; return m_title;
} }
void drawWindow(turbine::Context *ctx, bool *open, auto drawContents) { void drawWindow(turbine::Context *ctx, bool *open, const std::function<void()> &drawContents);
studio::ig::centerNextWindow(ctx);
ImGui::SetNextWindowSize(static_cast<ImVec2>(m_size));
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal(m_title.c_str(), open, modalFlags)) {
drawContents();
}
}
}; };
+2 -1
View File
@@ -44,7 +44,8 @@ ox::Result<ox::String> saveFile(const ox::Vector<FDFilterItem> &filters) noexcep
filterItems[i].spec = f.spec.data(); filterItems[i].spec = f.spec.data();
++i; ++i;
} }
return toResult(NFD::SaveDialog(path, filterItems.data(), filterItems.size()), path); const auto filterItemsCnt = static_cast<nfdfiltersize_t>(filterItems.size());
return toResult(NFD::SaveDialog(path, filterItems.data(), filterItemsCnt), path);
} }
ox::Result<ox::String> chooseDirectory() noexcept { ox::Result<ox::String> chooseDirectory() noexcept {
+12
View File
@@ -2,6 +2,18 @@
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/ */
#include <studio/imguiuitl.hpp>
#include <studio/popup.hpp>
namespace studio { namespace studio {
void Popup::drawWindow(turbine::Context *ctx, bool *open, const std::function<void()> &drawContents) {
studio::ig::centerNextWindow(ctx);
ImGui::SetNextWindowSize(static_cast<ImVec2>(m_size));
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal(m_title.c_str(), open, modalFlags)) {
drawContents();
}
}
} }
+1 -1
View File
@@ -35,7 +35,7 @@ Project::Project(keel::Context *ctx, ox::String path, ox::CRStringView projectDa
ox::Error Project::create() noexcept { ox::Error Project::create() noexcept {
std::error_code ec; std::error_code ec;
std::filesystem::create_directory(m_path.toStdString(), ec); std::filesystem::create_directory(m_path.toStdString(), ec);
return OxError(ec.value(), "PassThroughFS: mkdir failed"); return OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed");
} }
ox::FileSystem *Project::romFs() noexcept { ox::FileSystem *Project::romFs() noexcept {
+3 -2
View File
@@ -16,9 +16,10 @@ extern "C" void turbine_isr();
namespace turbine { namespace turbine {
// Timer Consts // Timer Consts
constexpr int NanoSecond = 1000000000; constexpr int NanoSecond = 1'000'000'000;
constexpr int MilliSecond = 1000; constexpr int MilliSecond = 1000;
constexpr int TicksMs59ns = 65535 - (NanoSecond / MilliSecond) / 59.59; constexpr int TicksMs59ns =
65535 - static_cast<uint16_t>(static_cast<double>(NanoSecond / MilliSecond) / 59.59);
extern volatile gba_timer_t g_timerMs; extern volatile gba_timer_t g_timerMs;
+60 -53
View File
@@ -141,60 +141,67 @@ static void themeImgui() noexcept {
style.ButtonTextAlign = ImVec2(0.5, 0.5); style.ButtonTextAlign = ImVec2(0.5, 0.5);
style.SelectableTextAlign = ImVec2(0.0, 0.0); style.SelectableTextAlign = ImVec2(0.0, 0.0);
// colors // colors
style.Colors[ImGuiCol_Text] = ImVec4(0.9490196108818054, 0.95686274766922, 0.9764705896377563, 1.0); constexpr auto imVec4 = [](double r, double g, double b, double a) {
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.3568627536296844, 0.4196078479290009, 0.4666666686534882, 1.0); return ImVec4(
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0); static_cast<float>(r),
style.Colors[ImGuiCol_ChildBg] = ImVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0); static_cast<float>(g),
style.Colors[ImGuiCol_PopupBg] = ImVec4(0.0784313753247261, 0.0784313753247261, 0.0784313753247261, 0.9399999976158142); static_cast<float>(b),
style.Colors[ImGuiCol_Border] = ImVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0); static_cast<float>(a));
style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.0, 0.0, 0.0, 0.0); };
style.Colors[ImGuiCol_FrameBg] = ImVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0); style.Colors[ImGuiCol_Text] = imVec4(0.9490196108818054, 0.95686274766922, 0.9764705896377563, 1.0);
style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.1176470592617989, 0.2000000029802322, 0.2784313857555389, 1.0); style.Colors[ImGuiCol_TextDisabled] = imVec4(0.3568627536296844, 0.4196078479290009, 0.4666666686534882, 1.0);
style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 1.0); style.Colors[ImGuiCol_WindowBg] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
style.Colors[ImGuiCol_TitleBg] = ImVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 0.6499999761581421); style.Colors[ImGuiCol_ChildBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0); style.Colors[ImGuiCol_PopupBg] = imVec4(0.0784313753247261, 0.0784313753247261, 0.0784313753247261, 0.9399999976158142);
style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.0, 0.0, 0.0, 0.5099999904632568); style.Colors[ImGuiCol_Border] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0); style.Colors[ImGuiCol_BorderShadow] = imVec4(0.0, 0.0, 0.0, 0.0);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.01960784383118153, 0.01960784383118153, 0.01960784383118153, 0.3899999856948853); style.Colors[ImGuiCol_FrameBg] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0); style.Colors[ImGuiCol_FrameBgHovered] = imVec4(0.1176470592617989, 0.2000000029802322, 0.2784313857555389, 1.0);
style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.1764705926179886, 0.2196078449487686, 0.2470588237047195, 1.0); style.Colors[ImGuiCol_FrameBgActive] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 1.0);
style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.08627451211214066, 0.2078431397676468, 0.3098039329051971, 1.0); style.Colors[ImGuiCol_TitleBg] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 0.6499999761581421);
style.Colors[ImGuiCol_CheckMark] = ImVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0); style.Colors[ImGuiCol_TitleBgActive] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0); style.Colors[ImGuiCol_TitleBgCollapsed] = imVec4(0.0, 0.0, 0.0, 0.5099999904632568);
style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.3686274588108063, 0.6078431606292725, 1.0, 1.0); style.Colors[ImGuiCol_MenuBarBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
style.Colors[ImGuiCol_Button] = ImVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0); style.Colors[ImGuiCol_ScrollbarBg] = imVec4(0.01960784383118153, 0.01960784383118153, 0.01960784383118153, 0.3899999856948853);
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0); style.Colors[ImGuiCol_ScrollbarGrab] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.05882352963089943, 0.529411792755127, 0.9764705896377563, 1.0); style.Colors[ImGuiCol_ScrollbarGrabHovered] = imVec4(0.1764705926179886, 0.2196078449487686, 0.2470588237047195, 1.0);
style.Colors[ImGuiCol_ScrollbarGrabActive] = imVec4(0.08627451211214066, 0.2078431397676468, 0.3098039329051971, 1.0);
style.Colors[ImGuiCol_CheckMark] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
style.Colors[ImGuiCol_SliderGrab] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
style.Colors[ImGuiCol_SliderGrabActive] = imVec4(0.3686274588108063, 0.6078431606292725, 1.0, 1.0);
style.Colors[ImGuiCol_Button] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
style.Colors[ImGuiCol_ButtonHovered] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
style.Colors[ImGuiCol_ButtonActive] = imVec4(0.05882352963089943, 0.529411792755127, 0.9764705896377563, 1.0);
// custom value // custom value
style.Colors[ImGuiCol_Header] = ImVec4(0.4000000029802322, 0.4470588237047195, 0.4862745225429535, 0.550000011920929); style.Colors[ImGuiCol_Header] = imVec4(0.4000000029802322, 0.4470588237047195, 0.4862745225429535, 0.550000011920929);
style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929); style.Colors[ImGuiCol_HeaderHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0); style.Colors[ImGuiCol_HeaderActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
style.Colors[ImGuiCol_Separator] = ImVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0); style.Colors[ImGuiCol_Separator] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 0.7799999713897705); style.Colors[ImGuiCol_SeparatorHovered] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 0.7799999713897705);
style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 1.0); style.Colors[ImGuiCol_SeparatorActive] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 1.0);
style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.25); style.Colors[ImGuiCol_ResizeGrip] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.25);
style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.6700000166893005); style.Colors[ImGuiCol_ResizeGripHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.6700000166893005);
style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.949999988079071); style.Colors[ImGuiCol_ResizeGripActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.949999988079071);
style.Colors[ImGuiCol_Tab] = ImVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0); style.Colors[ImGuiCol_Tab] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
style.Colors[ImGuiCol_TabHovered] = ImVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929); style.Colors[ImGuiCol_TabHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
style.Colors[ImGuiCol_TabActive] = ImVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0); style.Colors[ImGuiCol_TabActive] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0); style.Colors[ImGuiCol_TabUnfocused] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0); style.Colors[ImGuiCol_TabUnfocusedActive] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
style.Colors[ImGuiCol_PlotLines] = ImVec4(0.6078431606292725, 0.6078431606292725, 0.6078431606292725, 1.0); style.Colors[ImGuiCol_PlotLines] = imVec4(0.6078431606292725, 0.6078431606292725, 0.6078431606292725, 1.0);
style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.0, 0.4274509847164154, 0.3490196168422699, 1.0); style.Colors[ImGuiCol_PlotLinesHovered] = imVec4(1.0, 0.4274509847164154, 0.3490196168422699, 1.0);
style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.8980392217636108, 0.6980392336845398, 0.0, 1.0); style.Colors[ImGuiCol_PlotHistogram] = imVec4(0.8980392217636108, 0.6980392336845398, 0.0, 1.0);
style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.0, 0.6000000238418579, 0.0, 1.0); style.Colors[ImGuiCol_PlotHistogramHovered] = imVec4(1.0, 0.6000000238418579, 0.0, 1.0);
style.Colors[ImGuiCol_TableHeaderBg] = ImVec4(0.1882352977991104, 0.1882352977991104, 0.2000000029802322, 1.0); style.Colors[ImGuiCol_TableHeaderBg] = imVec4(0.1882352977991104, 0.1882352977991104, 0.2000000029802322, 1.0);
style.Colors[ImGuiCol_TableBorderStrong] = ImVec4(0.3098039329051971, 0.3098039329051971, 0.3490196168422699, 1.0); style.Colors[ImGuiCol_TableBorderStrong] = imVec4(0.3098039329051971, 0.3098039329051971, 0.3490196168422699, 1.0);
style.Colors[ImGuiCol_TableBorderLight] = ImVec4(0.2274509817361832, 0.2274509817361832, 0.2470588237047195, 1.0); style.Colors[ImGuiCol_TableBorderLight] = imVec4(0.2274509817361832, 0.2274509817361832, 0.2470588237047195, 1.0);
style.Colors[ImGuiCol_TableRowBg] = ImVec4(0.0, 0.0, 0.0, 0.0); style.Colors[ImGuiCol_TableRowBg] = imVec4(0.0, 0.0, 0.0, 0.0);
style.Colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.0, 1.0, 1.0, 0.05999999865889549); style.Colors[ImGuiCol_TableRowBgAlt] = imVec4(1.0, 1.0, 1.0, 0.05999999865889549);
style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.3499999940395355); style.Colors[ImGuiCol_TextSelectedBg] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.3499999940395355);
style.Colors[ImGuiCol_DragDropTarget] = ImVec4(1.0, 1.0, 0.0, 0.8999999761581421); style.Colors[ImGuiCol_DragDropTarget] = imVec4(1.0, 1.0, 0.0, 0.8999999761581421);
style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0); style.Colors[ImGuiCol_NavHighlight] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.0, 1.0, 1.0, 0.699999988079071); style.Colors[ImGuiCol_NavWindowingHighlight] = imVec4(1.0, 1.0, 1.0, 0.699999988079071);
style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.2000000029802322); style.Colors[ImGuiCol_NavWindowingDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.2000000029802322);
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.3499999940395355); style.Colors[ImGuiCol_ModalWindowDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.3499999940395355);
} }
ox::Error initGfx(Context &ctx) noexcept { ox::Error initGfx(Context &ctx) noexcept {