[ox] Fix remaining implicit conversion issues

This commit is contained in:
Gary Talent 2023-06-06 23:32:23 -05:00
parent acf04665bc
commit 3fdfee33a9
50 changed files with 218 additions and 191 deletions

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

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;
} }
} }
} }

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;

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

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;

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;
} }

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;
} }

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)

View File

@ -11,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(

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
@ -227,14 +227,14 @@ Error FileStoreTemplate<size_t>::setSize(std::size_t size) {
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::incLinks(uint64_t id) { Error FileStoreTemplate<size_t>::incLinks(uint64_t id) {
oxRequireM(item, find(static_cast<size_t>(id)).validate()); 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(uint64_t id) { Error FileStoreTemplate<size_t>::decLinks(uint64_t id) {
oxRequireM(item, find(static_cast<size_t>(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));
} }
@ -421,7 +421,7 @@ ptrarith::Ptr<uint8_t, std::size_t> FileStoreTemplate<size_t>::read(uint64_t id)
template<typename size_t> template<typename size_t>
Error FileStoreTemplate<size_t>::resize() { Error FileStoreTemplate<size_t>::resize() {
oxReturnError(compact()); 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());

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,7 +69,7 @@ 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(std::size_t) { void setSize(std::size_t) {

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;
} }

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>

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);

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));
} }

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 {

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
@ -174,7 +174,7 @@ template<typename size_t, typename Item>
NodeBuffer<size_t, Item>::NodeBuffer(std::size_t size) noexcept { NodeBuffer<size_t, Item>::NodeBuffer(std::size_t size) noexcept {
m_header.size = static_cast<size_t>(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>
@ -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());
} }

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

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());

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

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});
} }

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(

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);
} }

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));
} }

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);
} }

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

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;

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>

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);
} }

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;

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));
} }

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;
} }

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

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

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(

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 {
} }
/** /**

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());
} }

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 {

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

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 {

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);
} }

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;

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 {

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)

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;

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;
} }

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 = [&] {

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;

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';

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;
} }