diff --git a/deps/ox/src/ox/clargs/clargs.cpp b/deps/ox/src/ox/clargs/clargs.cpp index 9acdecbb..c6edb9c8 100644 --- a/deps/ox/src/ox/clargs/clargs.cpp +++ b/deps/ox/src/ox/clargs/clargs.cpp @@ -27,7 +27,7 @@ ClArgs::ClArgs(int argc, const char **args) noexcept { m_bools[arg] = false; } m_strings[arg] = val; - 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; } ++i; diff --git a/deps/ox/src/ox/claw/read.cpp b/deps/ox/src/ox/claw/read.cpp index 2df7a1a9..c4e43c1d 100644 --- a/deps/ox/src/ox/claw/read.cpp +++ b/deps/ox/src/ox/claw/read.cpp @@ -13,7 +13,7 @@ namespace ox { Result readClawHeader(const char *buff, std::size_t buffLen) noexcept { - const auto s1End = ox_strchr(buff, ';', buffLen); + const auto s1End = ox::strchr(buff, ';', buffLen); if (!s1End) { return OxError(1, "Could not read Claw header"); } @@ -22,7 +22,7 @@ Result readClawHeader(const char *buff, std::size_t buffLen) noexcep buff += s1Size + 1; buffLen -= s1Size + 1; - const auto s2End = ox_strchr(buff, ';', buffLen); + const auto s2End = ox::strchr(buff, ';', buffLen); if (!s2End) { return OxError(2, "Could not read Claw header"); } @@ -31,7 +31,7 @@ Result readClawHeader(const char *buff, std::size_t buffLen) noexcep buff += s2Size + 1; buffLen -= s2Size + 1; - const auto s3End = ox_strchr(buff, ';', buffLen); + const auto s3End = ox::strchr(buff, ';', buffLen); if (!s3End) { return OxError(3, "Could not read Claw header"); } @@ -49,7 +49,7 @@ Result readClawHeader(const char *buff, std::size_t buffLen) noexcep return OxError(4, "Claw format does not match any supported format/version combo"); } hdr.typeName = typeName; - if (auto r = ox_atoi(versionStr.c_str()); r.error == 0) { + if (auto r = ox::atoi(versionStr.c_str()); r.error == 0) { hdr.typeVersion = r.value; } hdr.data = buff; @@ -64,7 +64,7 @@ Result readClawHeader(const ox::Buffer &buff) noexcept { Result stripClawHeader(const char *buff, std::size_t buffLen) noexcept { oxRequire(header, readClawHeader(buff, buffLen)); Buffer out(header.dataSize); - ox_memcpy(out.data(), header.data, out.size()); + ox::listcpy(out.data(), header.data, out.size()); return out; } diff --git a/deps/ox/src/ox/claw/write.hpp b/deps/ox/src/ox/claw/write.hpp index e8ec3bf0..f2d45dcb 100644 --- a/deps/ox/src/ox/claw/write.hpp +++ b/deps/ox/src/ox/claw/write.hpp @@ -88,7 +88,7 @@ ox::Error writeClawHeader(Writer_c auto &writer, const T *t, ClawFormat fmt) noe oxReturnError(writer.put(';')); const auto tn = detail::getTypeVersion(t); if (tn > -1) { - oxReturnError(ox::itoa(tn, writer)); + oxReturnError(ox::writeItoa(tn, writer)); } oxReturnError(writer.put(';')); return {}; diff --git a/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp b/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp index 6c00005c..ef4706c1 100644 --- a/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp +++ b/deps/ox/src/ox/fs/filestore/filestoretemplate.hpp @@ -279,7 +279,7 @@ Error FileStoreTemplate::write(uint64_t id64, const void *data, FsSize_t oxAssert(destData.size() == dataSize, "Allocation size does not match data."); // write data if any was provided if (data != nullptr) { - ox_memcpy(destData, data, dest->size()); + ox::memcpy(destData, data, dest->size()); oxTrace("ox.fs.FileStoreTemplate.write", "Data written"); } auto fsData = fileStoreData(); @@ -336,7 +336,7 @@ Error FileStoreTemplate::read(uint64_t id, void *out, FsSize_t outSize, return OxError(1); } - ox_memcpy(out, srcData, srcData.size()); + ox::memcpy(out, srcData, srcData.size()); if (size) { *size = src.size(); } @@ -367,7 +367,7 @@ Error FileStoreTemplate::read(uint64_t id, FsSize_t readStart, FsSize_t return OxError(1); } - ox_memcpy(out, srcData.get() + readStart, readSize); + ox::memcpy(out, srcData.get() + readStart, readSize); if (size) { *size = src.size(); } @@ -400,7 +400,7 @@ Error FileStoreTemplate::read(uint64_t id, FsSize_t readStart, return OxError(1); } - ox_memcpy(out, srcData.get() + readStart, readSize); + ox::memcpy(out, srcData.get() + readStart, readSize); if (size) { *size = src.size(); } diff --git a/deps/ox/src/ox/fs/filesystem/directory.hpp b/deps/ox/src/ox/fs/filesystem/directory.hpp index 10407529..ed67b75f 100644 --- a/deps/ox/src/ox/fs/filesystem/directory.hpp +++ b/deps/ox/src/ox/fs/filesystem/directory.hpp @@ -48,7 +48,7 @@ struct OX_PACKED DirectoryEntry { auto d = data(); if (d.valid()) { d->inode = inode; - ox_strncpy(d->name, name, ox::min(bufferSize, static_cast(MaxFileNameLength))); + ox::strncpy(d->name, name, ox::min(bufferSize, static_cast(MaxFileNameLength))); return OxError(0); } return OxError(1); diff --git a/deps/ox/src/ox/fs/filesystem/filelocation.cpp b/deps/ox/src/ox/fs/filesystem/filelocation.cpp index 88f9ee21..15cd529f 100644 --- a/deps/ox/src/ox/fs/filesystem/filelocation.cpp +++ b/deps/ox/src/ox/fs/filesystem/filelocation.cpp @@ -46,9 +46,9 @@ FileAddress &FileAddress::operator=(const FileAddress &other) noexcept { case FileAddressType::Path: { if (other.m_data.path) { - auto strSize = ox_strlen(other.m_data.path) + 1; + auto strSize = ox::strlen(other.m_data.path) + 1; m_data.path = new char[strSize]; - ox_memcpy(m_data.path, other.m_data.path, strSize); + ox::memcpy(m_data.path, other.m_data.path, strSize); } else { m_data.constPath = ""; m_type = FileAddressType::ConstPath; diff --git a/deps/ox/src/ox/fs/filesystem/filelocation.hpp b/deps/ox/src/ox/fs/filesystem/filelocation.hpp index ded301e9..436d6cf1 100644 --- a/deps/ox/src/ox/fs/filesystem/filelocation.hpp +++ b/deps/ox/src/ox/fs/filesystem/filelocation.hpp @@ -44,13 +44,10 @@ class FileAddress { protected: FileAddressType m_type = FileAddressType::None; - Data m_data; + Data m_data{}; public: - constexpr FileAddress() noexcept { - m_data.inode = 0; - m_type = FileAddressType::None; - } + constexpr FileAddress() noexcept = default; FileAddress(const FileAddress &other) noexcept; diff --git a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp index d9cd254a..e600e1be 100644 --- a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp +++ b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp @@ -186,7 +186,7 @@ Error PassThroughFS::writeFileInode(uint64_t, const void*, uint64_t, FileType) n } std::string_view PassThroughFS::stripSlash(StringView path) noexcept { - const auto pathLen = ox_strlen(path); + const auto pathLen = ox::strlen(path); for (auto i = 0u; i < pathLen && path[0] == '/'; i++) { path = substr(path, 1); } diff --git a/deps/ox/src/ox/fs/filesystem/pathiterator.cpp b/deps/ox/src/ox/fs/filesystem/pathiterator.cpp index d6edf192..87885d61 100644 --- a/deps/ox/src/ox/fs/filesystem/pathiterator.cpp +++ b/deps/ox/src/ox/fs/filesystem/pathiterator.cpp @@ -19,7 +19,7 @@ PathIterator::PathIterator(const char *path, std::size_t maxSize, std::size_t it m_iterator = iterator; } -PathIterator::PathIterator(const char *path): PathIterator(path, ox_strlen(path)) { +PathIterator::PathIterator(const char *path): PathIterator(path, ox::strlen(path)) { } PathIterator::PathIterator(CRStringView path): PathIterator(path.data(), path.bytes()) { @@ -29,10 +29,10 @@ PathIterator::PathIterator(CRStringView path): PathIterator(path.data(), path.by * @return 0 if no error */ Error PathIterator::dirPath(char *out, std::size_t outSize) { - const auto idx = ox_lastIndexOf(m_path, '/', m_maxSize); + const auto idx = ox::lastIndexOf(m_path, '/', m_maxSize); const auto size = static_cast(idx + 1); if (idx >= 0 && size < outSize) { - ox_memcpy(out, m_path, size); + ox::memcpy(out, m_path, size); out[size] = 0; return OxError(0); } else { @@ -44,12 +44,12 @@ Error PathIterator::dirPath(char *out, std::size_t outSize) { * @return 0 if no error */ 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) { idx++; // pass up the preceding / - std::size_t fileNameSize = static_cast(ox_strlen(&m_path[idx])); + std::size_t fileNameSize = static_cast(ox::strlen(&m_path[idx])); if (fileNameSize < outSize) { - ox_memcpy(out, &m_path[idx], fileNameSize); + ox::memcpy(out, &m_path[idx], fileNameSize); out[fileNameSize] = 0; return OxError(0); } else { @@ -67,8 +67,8 @@ Error PathIterator::get(char *pathOut, std::size_t pathOutSize) { oxTracef("ox.fs.PathIterator.get", "m_iterator ({}) >= m_maxSize ({})", m_iterator, m_maxSize); return OxError(1); } - if (!ox_strlen(&m_path[m_iterator])) { - oxTrace("ox.fs.PathIterator.get", "!ox_strlen(&m_path[m_iterator])"); + if (!ox::strlen(&m_path[m_iterator])) { + oxTrace("ox.fs.PathIterator.get", "!ox::strlen(&m_path[m_iterator])"); return OxError(1); } auto start = m_iterator; @@ -76,10 +76,10 @@ Error PathIterator::get(char *pathOut, std::size_t pathOutSize) { start++; } // 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 / if (!substr) { - substr = ox_strchr(&m_path[start], 0, m_maxSize - start); + substr = ox::strchr(&m_path[start], 0, m_maxSize - start); } const auto end = static_cast(substr - m_path); size = end - start; @@ -87,7 +87,7 @@ Error PathIterator::get(char *pathOut, std::size_t pathOutSize) { if (size >= pathOutSize || size == 0) { return OxError(1); } - ox_memcpy(pathOut, &m_path[start], size); + ox::memcpy(pathOut, &m_path[start], size); // truncate trailing / if (size && pathOut[size - 1] == '/') { size--; @@ -100,17 +100,17 @@ Error PathIterator::get(char *pathOut, std::size_t pathOutSize) { Error PathIterator::next(char *pathOut, std::size_t pathOutSize) { std::size_t size = 0; auto retval = OxError(1); - if (m_iterator < m_maxSize && ox_strlen(&m_path[m_iterator])) { + if (m_iterator < m_maxSize && ox::strlen(&m_path[m_iterator])) { retval = OxError(0); if (m_path[m_iterator] == '/') { m_iterator++; } const auto start = m_iterator; // 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 / if (!substr) { - substr = ox_strchr(&m_path[start], 0, m_maxSize - start); + substr = ox::strchr(&m_path[start], 0, m_maxSize - start); } const auto end = static_cast(substr - m_path); size = end - start; @@ -118,7 +118,7 @@ Error PathIterator::next(char *pathOut, std::size_t pathOutSize) { if (size >= pathOutSize) { return OxError(1); } - ox_memcpy(pathOut, &m_path[start], size); + ox::memcpy(pathOut, &m_path[start], size); } // truncate trailing / if (size && pathOut[size - 1] == '/') { @@ -147,17 +147,17 @@ Result PathIterator::nextSize() const { std::size_t size = 0; auto retval = OxError(1); auto it = m_iterator; - if (it < m_maxSize && ox_strlen(&m_path[it])) { + if (it < m_maxSize && ox::strlen(&m_path[it])) { retval = OxError(0); if (m_path[it] == '/') { it++; } const auto start = it; // 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 / if (!substr) { - substr = ox_strchr(&m_path[start], 0, m_maxSize - start); + substr = ox::strchr(&m_path[start], 0, m_maxSize - start); } const auto end = static_cast(substr - m_path); size = end - start; @@ -168,16 +168,16 @@ Result PathIterator::nextSize() const { bool PathIterator::hasNext() const { std::size_t size = 0; - if (m_iterator < m_maxSize && ox_strlen(&m_path[m_iterator])) { + if (m_iterator < m_maxSize && ox::strlen(&m_path[m_iterator])) { std::size_t start = m_iterator; if (m_path[start] == '/') { start++; } // 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 / if (!substr) { - substr = ox_strchr(&m_path[start], 0, m_maxSize - start); + substr = ox::strchr(&m_path[start], 0, m_maxSize - start); } const auto end = static_cast(substr - m_path); size = end - start; @@ -192,16 +192,16 @@ bool PathIterator::valid() const { PathIterator PathIterator::next() const { std::size_t size = 0; auto iterator = m_iterator; - if (iterator < m_maxSize && ox_strlen(&m_path[iterator])) { + if (iterator < m_maxSize && ox::strlen(&m_path[iterator])) { if (m_path[iterator] == '/') { iterator++; } const auto start = iterator; // 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 / if (!substr) { - substr = ox_strchr(&m_path[start], 0, m_maxSize - start); + substr = ox::strchr(&m_path[start], 0, m_maxSize - start); } const auto end = static_cast(substr - m_path); size = end - start; diff --git a/deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp b/deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp index c9bce570..e5ba4dd6 100644 --- a/deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp +++ b/deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp @@ -173,15 +173,15 @@ class OX_PACKED NodeBuffer { template NodeBuffer::NodeBuffer(std::size_t size) noexcept { m_header.size = static_cast(size); - ox_memset(this + 1, 0, size - sizeof(*this)); + ox::memset(this + 1, 0, size - sizeof(*this)); oxTracef("ox.NodeBuffer.constructor", "{}", m_header.firstItem.get()); } template NodeBuffer::NodeBuffer(const NodeBuffer &other, std::size_t size) noexcept { oxTracef("ox.ptrarith.NodeBuffer.copy", "other.m_header.firstItem: {}", other.m_header.firstItem.get()); - ox_memset(this + 1, 0, size - sizeof(*this)); - ox_memcpy(this, &other, size); + ox::memset(this + 1, 0, size - sizeof(*this)); + ox::memcpy(this, &other, size); } template @@ -291,7 +291,7 @@ Result::ItemPtr> NodeBuffer::mal oxTrace("ox.ptrarith.NodeBuffer.malloc.fail", "Unknown"); return OxError(1, "NodeBuffer::malloc: unknown failure"); } - ox_memset(out, 0, fullSize); + ox::memset(out, 0, fullSize); new (out) Item; out->setSize(sz); @@ -367,7 +367,7 @@ Error NodeBuffer::setSize(std::size_t size) noexcept { } else { m_header.size = static_cast(size); auto data = reinterpret_cast(this) + end; - ox_memset(data, 0, size - end); + ox::memset(data, 0, size - end); return OxError(0); } } @@ -405,7 +405,7 @@ Error NodeBuffer::compact(F cb) noexcept { return OxError(2); } // move node - ox_memcpy(dest, src, src->fullSize()); + ox::memcpy(dest, src, src->fullSize()); oxReturnError(cb(src, dest)); // update surrounding nodes auto prev = ptr(dest->prev); diff --git a/deps/ox/src/ox/fs/test/tests.cpp b/deps/ox/src/ox/fs/test/tests.cpp index be6fdb2c..154b0e0a 100644 --- a/deps/ox/src/ox/fs/test/tests.cpp +++ b/deps/ox/src/ox/fs/test/tests.cpp @@ -61,9 +61,9 @@ const std::map> tests = auto const path = ox::String("/usr/share/charset.gbag"); ox::PathIterator it(path.c_str(), path.len()); auto buff = static_cast(ox_alloca(path.len() + 1)); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next"); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next"); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "usr") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "share") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next"); return OxError(0); } }, @@ -73,8 +73,8 @@ const std::map> tests = auto const path = ox::String("/usr/share/"); ox::PathIterator it(path.c_str(), path.len()); auto buff = static_cast(ox_alloca(path.len() + 1)); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next"); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "usr") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "share") == 0, "PathIterator shows wrong next"); return OxError(0); } }, @@ -84,7 +84,7 @@ const std::map> tests = auto const path = ox::String("/"); ox::PathIterator it(path.c_str(), path.len()); auto buff = static_cast(ox_alloca(path.len() + 1)); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "\0") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "\0") == 0, "PathIterator shows wrong next"); return OxError(0); } }, @@ -94,9 +94,9 @@ const std::map> tests = auto const path = ox::String("usr/share/charset.gbag"); ox::PathIterator it(path.c_str(), path.len()); auto buff = static_cast(ox_alloca(path.len() + 1)); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next"); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next"); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "usr") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "share") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "charset.gbag") == 0, "PathIterator shows wrong next"); return OxError(0); } }, @@ -106,8 +106,8 @@ const std::map> tests = auto const path = ox::String("usr/share/"); ox::PathIterator it(path.c_str(), path.len()); auto buff = static_cast(ox_alloca(path.len() + 1)); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next"); - oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "share") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "usr") == 0, "PathIterator shows wrong next"); + oxAssert(it.next(buff, path.len()) == 0 && ox::strcmp(buff, "share") == 0, "PathIterator shows wrong next"); return OxError(0); } }, @@ -117,7 +117,7 @@ const std::map> tests = auto const path = ox::String("/usr/share/charset.gbag"); ox::PathIterator it(path.c_str(), path.len()); auto buff = static_cast(ox_alloca(path.len() + 1)); - oxAssert(it.dirPath(buff, path.len()) == 0 && ox_strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path"); + oxAssert(it.dirPath(buff, path.len()) == 0 && ox::strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path"); return OxError(0); } }, @@ -127,7 +127,7 @@ const std::map> tests = auto const path = ox::String("/usr/share/charset.gbag"); ox::PathIterator it(path.c_str(), path.len()); auto buff = static_cast(ox_alloca(path.len() + 1)); - oxAssert(it.fileName(buff, path.len()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows incorrect file name"); + oxAssert(it.fileName(buff, path.len()) == 0 && ox::strcmp(buff, "charset.gbag") == 0, "PathIterator shows incorrect file name"); return OxError(0); } }, @@ -135,7 +135,7 @@ const std::map> tests = "PathIterator::hasNext", [](ox::StringView) { const auto path = "/file1"; - ox::PathIterator it(path, ox_strlen(path)); + ox::PathIterator it(path, ox::strlen(path)); oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext"); oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext"); return OxError(0); @@ -171,9 +171,9 @@ const std::map> tests = [](ox::StringView) { constexpr auto buffLen = 5000; constexpr auto str1 = "Hello, World!"; - constexpr auto str1Len = ox_strlen(str1) + 1; + constexpr auto str1Len = ox::strlen(str1) + 1; constexpr auto str2 = "Hello, Moon!"; - constexpr auto str2Len = ox_strlen(str2) + 1; + constexpr auto str2Len = ox::strlen(str2) + 1; auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer>(buffLen); oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed."); ox::FileStore32 fileStore(list, buffLen); diff --git a/deps/ox/src/ox/logconn/circularbuff.hpp b/deps/ox/src/ox/logconn/circularbuff.hpp index 69a2c32f..32c0a3ee 100644 --- a/deps/ox/src/ox/logconn/circularbuff.hpp +++ b/deps/ox/src/ox/logconn/circularbuff.hpp @@ -47,13 +47,13 @@ class CirculerBuffer { } // write seg 1 const auto seg1Sz = ox::min(sz, m_buff.size() - m_writePt); - ox_memcpy(&m_buff[m_writePt], &buff[0], seg1Sz); + ox::listcpy(&m_buff[m_writePt], &buff[0], seg1Sz); m_writePt += sz; if (seg1Sz != sz) { m_writePt -= m_buff.size(); // write seg 2 const auto seg2Sz = sz - seg1Sz; - ox_memcpy(&m_buff[0], &buff[seg1Sz], seg2Sz); + ox::listcpy(&m_buff[0], &buff[seg1Sz], seg2Sz); oxAssert(m_buff[0] == buff[seg1Sz], "break"); } return {}; @@ -70,7 +70,7 @@ class CirculerBuffer { return {}; } - constexpr ox::Error seekp(int, ios_base::seekdir) { + constexpr ox::Error seekp(int, ios_base::seekdir) noexcept { return OxError(1, "Unimplemented"); } @@ -84,13 +84,13 @@ class CirculerBuffer { const auto bytesRead = ox::min(outSize, m_buff.size() - avail()); // read seg 1 const auto seg1Sz = ox::min(bytesRead, m_buff.size() - m_readPt); - ox_memcpy(&out[0], &m_buff[m_readPt], seg1Sz); + ox::listcpy(&out[0], &m_buff[m_readPt], seg1Sz); m_readPt += bytesRead; if (seg1Sz != bytesRead) { m_readPt -= m_buff.size(); // read seg 2 const auto seg2Sz = bytesRead - seg1Sz; - ox_memcpy(&out[seg1Sz], &m_buff[0], seg2Sz); + ox::listcpy(&out[seg1Sz], &m_buff[0], seg2Sz); } return bytesRead; } diff --git a/deps/ox/src/ox/mc/intops.hpp b/deps/ox/src/ox/mc/intops.hpp index b9c6bd92..7f369ef6 100644 --- a/deps/ox/src/ox/mc/intops.hpp +++ b/deps/ox/src/ox/mc/intops.hpp @@ -71,7 +71,7 @@ constexpr McInt encodeInteger(I pInput) noexcept { // move input to uint64_t to allow consistent bit manipulation, and to avoid // overflow concerns uint64_t val = 0; - ox_memcpy(&val, &input, sizeof(input)); + ox::memcpy(&val, &input, sizeof(input)); if (val) { // bits needed to represent number factoring in space possibly // needed for signed bit @@ -94,7 +94,7 @@ constexpr McInt encodeInteger(I pInput) noexcept { } if (bytes == 9) { out.data[0] = bytesIndicator; - ox_memcpy(&out.data[1], &leVal, 8); + ox::memcpy(&out.data[1], &leVal, 8); if (inputNegative) { out.data[1] |= 0b1000'0000; } @@ -104,7 +104,7 @@ constexpr McInt encodeInteger(I pInput) noexcept { auto intermediate = static_cast(leVal.raw() | (negBit << (valBits - 1))) << bytes | static_cast(bytesIndicator); - ox_memcpy(out.data, &intermediate, sizeof(intermediate)); + ox::memcpy(out.data, &intermediate, sizeof(intermediate)); } out.length = bytes; } @@ -160,7 +160,7 @@ constexpr Result decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe ox::Array d = {}; //d[0] = decoded & 0xffff'ffff; //d[1] = decoded >> 32; - ox_memcpy(d.data(), &decoded, sizeof(decoded)); + ox::memcpy(d.data(), &decoded, sizeof(decoded)); auto bit = negBit; for (; bit < ox::min(Bits, 32); ++bit) { d[0] |= 1 << bit; @@ -175,7 +175,7 @@ constexpr Result decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe d[0] = d[1]; d[1] = d0Tmp; } - ox_memcpy(&out, d.data(), sizeof(out)); + ox::memcpy(&out, d.data(), sizeof(out)); return out; } } diff --git a/deps/ox/src/ox/mc/write.hpp b/deps/ox/src/ox/mc/write.hpp index 8eb94808..b3453b6d 100644 --- a/deps/ox/src/ox/mc/write.hpp +++ b/deps/ox/src/ox/mc/write.hpp @@ -214,7 +214,7 @@ template constexpr Error MetalClawWriter::fieldCString(const char*, const char *const*val, std::size_t) noexcept { bool fieldSet = false; if (!m_unionIdx.has_value() || *m_unionIdx == m_field) { - const auto strLen = *val ? ox_strlen(*val) : 0; + const auto strLen = *val ? ox::strlen(*val) : 0; // write the length const auto strLenBuff = mc::encodeInteger(strLen); oxReturnError(m_writer.write(reinterpret_cast(strLenBuff.data), strLenBuff.length)); diff --git a/deps/ox/src/ox/model/modelvalue.hpp b/deps/ox/src/ox/model/modelvalue.hpp index 53130335..416c894f 100644 --- a/deps/ox/src/ox/model/modelvalue.hpp +++ b/deps/ox/src/ox/model/modelvalue.hpp @@ -995,7 +995,7 @@ constexpr ModelValue::ModelValue(const ModelValue &other) noexcept { case Type::SignedInteger16: case Type::SignedInteger32: case Type::SignedInteger64: - ox_memcpy(&m_data, &other.m_data, sizeof(m_data)); + ox::memcpy(&m_data, &other.m_data, sizeof(m_data)); break; case Type::String: m_data.str = new String(other.get()); @@ -1028,8 +1028,8 @@ constexpr ModelValue::ModelValue(ModelValue &&other) noexcept { case Type::SignedInteger16: case Type::SignedInteger32: case Type::SignedInteger64: - ox_memcpy(&m_data, &other.m_data, sizeof(m_data)); - ox_memset(&other.m_data, 0, sizeof(m_data)); + ox::memcpy(&m_data, &other.m_data, sizeof(m_data)); + ox::memset(&other.m_data, 0, sizeof(m_data)); break; case Type::String: m_data.str = other.m_data.str; @@ -1220,7 +1220,7 @@ constexpr ModelValue &ModelValue::operator=(const ModelValue &other) noexcept { case Type::SignedInteger16: case Type::SignedInteger32: case Type::SignedInteger64: - ox_memcpy(&m_data, &other.m_data, sizeof(m_data)); + ox::memcpy(&m_data, &other.m_data, sizeof(m_data)); break; case Type::String: m_data.str = new String(other.get()); @@ -1258,8 +1258,8 @@ constexpr ModelValue &ModelValue::operator=(ModelValue &&other) noexcept { case Type::SignedInteger16: case Type::SignedInteger32: case Type::SignedInteger64: - ox_memcpy(&m_data, &other.m_data, sizeof(m_data)); - ox_memset(&other.m_data, 0, sizeof(m_data)); + ox::memcpy(&m_data, &other.m_data, sizeof(m_data)); + ox::memset(&other.m_data, 0, sizeof(m_data)); break; case Type::String: m_data.str = other.m_data.str; diff --git a/deps/ox/src/ox/oc/read.cpp b/deps/ox/src/ox/oc/read.cpp index 33a7d057..a6d634f5 100644 --- a/deps/ox/src/ox/oc/read.cpp +++ b/deps/ox/src/ox/oc/read.cpp @@ -15,7 +15,7 @@ namespace ox { OrganicClawReader::OrganicClawReader(const uint8_t *buff, std::size_t buffSize) { auto json = reinterpret_cast(buff); - auto jsonLen = ox_strnlen(json, buffSize); + auto jsonLen = ox::strnlen(json, buffSize); Json::CharReaderBuilder parserBuilder; auto parser = std::unique_ptr(parserBuilder.newCharReader()); if (!parser->parse(json, json + jsonLen, &m_json, nullptr)) { @@ -198,7 +198,7 @@ Error OrganicClawReader::fieldCString(const char *key, char *val, std::size_t bu if (strSize >= buffLen) { err = OxError(2, "String size exceeds capacity of destination"); } else { - ox_memcpy(data, begin, static_cast(strSize)); + ox::memcpy(data, begin, static_cast(strSize)); data[strSize] = 0; } } else { @@ -224,7 +224,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val) noexcept { const auto strSize = static_cast(end - begin); safeDelete(*val); *val = new char[strSize + 1]; - ox_memcpy(data, begin, static_cast(strSize)); + ox::memcpy(data, begin, static_cast(strSize)); data[strSize] = 0; } else { err = OxError(1, "Type mismatch"); @@ -242,7 +242,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t b if (jv.empty()) { auto data = val; if (data) { - data[0] = 0; + data[0] = nullptr; } } else if (jv.isString()) { jv.getString(&begin, &end); @@ -252,8 +252,8 @@ Error OrganicClawReader::fieldCString(const char *key, char **val, std::size_t b safeDelete(*val); *val = new char[strSize + 1]; } - ox_memcpy(data, begin, static_cast(strSize)); - data[strSize] = 0; + ox::memcpy(data, begin, static_cast(strSize)); + data[strSize] = nullptr; } else { err = OxError(1, "Type mismatch"); } diff --git a/deps/ox/src/ox/oc/read.hpp b/deps/ox/src/ox/oc/read.hpp index 5c16ff72..15ecb7e6 100644 --- a/deps/ox/src/ox/oc/read.hpp +++ b/deps/ox/src/ox/oc/read.hpp @@ -274,7 +274,7 @@ Result readOC(const char *json, std::size_t jsonLen) noexcept { template Result readOC(const char *json) noexcept { - return readOC(json, ox_strlen(json)); + return readOC(json, ox::strlen(json)); } template diff --git a/deps/ox/src/ox/oc/write.cpp b/deps/ox/src/ox/oc/write.cpp index 024e3545..ddec2ce4 100644 --- a/deps/ox/src/ox/oc/write.cpp +++ b/deps/ox/src/ox/oc/write.cpp @@ -27,7 +27,7 @@ Error OrganicClawWriter::fieldCString(const char *key, const char *const*val, in } Error OrganicClawWriter::fieldCString(const char *key, const char *const*val) noexcept { - return fieldCString(key, const_cast(val), static_cast(ox_strlen(val))); + return fieldCString(key, const_cast(val), static_cast(ox::strlen(val))); } Error OrganicClawWriter::field(const char *key, const UUID *uuid) noexcept { diff --git a/deps/ox/src/ox/std/CMakeLists.txt b/deps/ox/src/ox/std/CMakeLists.txt index f6ba8673..fbf8adb9 100644 --- a/deps/ox/src/ox/std/CMakeLists.txt +++ b/deps/ox/src/ox/std/CMakeLists.txt @@ -106,6 +106,7 @@ install( ignore.hpp iterator.hpp math.hpp + maybeview.hpp memops.hpp memory.hpp new.hpp diff --git a/deps/ox/src/ox/std/anyptr.hpp b/deps/ox/src/ox/std/anyptr.hpp new file mode 100644 index 00000000..ac11e484 --- /dev/null +++ b/deps/ox/src/ox/std/anyptr.hpp @@ -0,0 +1,102 @@ + +#pragma once + +#include "assert.hpp" +#include "array.hpp" +#include "def.hpp" +#include "span.hpp" + +namespace ox { + +class AnyPtr { + private: + struct WrapBase { + virtual constexpr ~WrapBase() = default; + virtual constexpr WrapBase *copyTo(ox::Span s) noexcept = 0; + virtual constexpr operator bool() const noexcept = 0; + }; + + template + struct Wrap: public WrapBase { + T *data{}; + constexpr Wrap(T *pData) noexcept: data(pData) { + } + constexpr WrapBase *copyTo(ox::Span s) noexcept override { + oxAssert(s.size() >= sizeof(Wrap), "too small buffer"); + if (std::is_constant_evaluated()) { + return new Wrap(data); + } else { + return new(s.data()) Wrap(data); + } + } + constexpr operator bool() const noexcept override { + return data != nullptr; + } + }; + + WrapBase *m_wrapPtr{}; + ox::Array)> m_wrapData; + + public: + constexpr AnyPtr() noexcept = default; + + template + constexpr AnyPtr(T *ptr) noexcept { + if (std::is_constant_evaluated()) { + m_wrapPtr = new Wrap(ptr); + } else { + m_wrapPtr = new(m_wrapData.data()) Wrap(ptr); + } + } + + constexpr AnyPtr(AnyPtr const&other) noexcept { + if (other) { + m_wrapPtr = other.m_wrapPtr->copyTo(m_wrapData); + } + } + + constexpr ~AnyPtr() noexcept { + if (std::is_constant_evaluated()) { + ox::safeDelete(m_wrapPtr); + } + } + + template + constexpr AnyPtr &operator=(T *ptr) noexcept { + if (std::is_constant_evaluated()) { + ox::safeDelete(m_wrapPtr); + m_wrapPtr = new Wrap(ptr); + } else { + m_wrapPtr = new(m_wrapData.data()) Wrap(ptr); + } + return *this; + } + + constexpr AnyPtr &operator=(AnyPtr const&ptr) noexcept { + if (this != &ptr) { + if (ptr) { + ox::safeDelete(m_wrapPtr); + m_wrapPtr = ptr.m_wrapPtr->copyTo(m_wrapData); + } else { + m_wrapPtr = nullptr; + } + } + return *this; + } + + constexpr operator bool() const noexcept { + return m_wrapPtr && *m_wrapPtr; + } + + template + [[nodiscard]] + constexpr T *get() const noexcept { +#ifdef OX_BARE_METAL + return static_cast*>(m_wrapPtr)->data; +#else + return dynamic_cast*>(m_wrapPtr)->data; +#endif + } +}; + +} \ No newline at end of file diff --git a/deps/ox/src/ox/std/array.hpp b/deps/ox/src/ox/std/array.hpp index b18efc2b..bef35d09 100644 --- a/deps/ox/src/ox/std/array.hpp +++ b/deps/ox/src/ox/std/array.hpp @@ -13,7 +13,6 @@ #include "initializerlist.hpp" #include "iterator.hpp" #include "math.hpp" -#include "memory.hpp" #include "new.hpp" #include "types.hpp" #include "utility.hpp" diff --git a/deps/ox/src/ox/std/basestringview.hpp b/deps/ox/src/ox/std/basestringview.hpp index e4ed55ce..b111f0e1 100644 --- a/deps/ox/src/ox/std/basestringview.hpp +++ b/deps/ox/src/ox/std/basestringview.hpp @@ -131,7 +131,7 @@ class BaseStringView { constexpr explicit BaseStringView(std::nullptr_t) noexcept {} - constexpr explicit BaseStringView(const char *str) noexcept: m_str(str), m_len(str ? ox_strlen(str) : 0) {} + constexpr explicit BaseStringView(const char *str) noexcept: m_str(str), m_len(str ? ox::strlen(str) : 0) {} constexpr explicit BaseStringView(const char *str, std::size_t len) noexcept: m_str(str), m_len(len) {} diff --git a/deps/ox/src/ox/std/bit.hpp b/deps/ox/src/ox/std/bit.hpp index d8be957f..f4b8d55d 100644 --- a/deps/ox/src/ox/std/bit.hpp +++ b/deps/ox/src/ox/std/bit.hpp @@ -34,7 +34,7 @@ namespace ox { template constexpr typename enable_if::type cbit_cast(From src) noexcept { To dst = {}; - ox_memcpy(&dst, &src, sizeof(src)); + ox::memcpy(&dst, &src, sizeof(src)); return dst; } diff --git a/deps/ox/src/ox/std/bstring.hpp b/deps/ox/src/ox/std/bstring.hpp index 1dd5ada5..d73585e7 100644 --- a/deps/ox/src/ox/std/bstring.hpp +++ b/deps/ox/src/ox/std/bstring.hpp @@ -109,7 +109,7 @@ constexpr BString::BString(const char *str) noexcept: m_buff{{0}} { template constexpr BString &BString::operator=(Integer_c auto i) noexcept { char str[65] = {}; - ox_itoa(i, str); + ox::itoa(i, str); return this->operator=(str); } @@ -119,7 +119,7 @@ constexpr BString &BString::operator=(ox::CRStringView str) noexcept if (cap() < strLen) { strLen = cap(); } - ox_memcpy(m_buff, str.data(), strLen); + ox::memcpy(m_buff, str.data(), strLen); // make sure last element is a null terminator m_buff[strLen] = 0; return *this; @@ -127,11 +127,11 @@ constexpr BString &BString::operator=(ox::CRStringView str) noexcept template constexpr BString &BString::operator=(const char *str) noexcept { - std::size_t strLen = ox_strlen(str) + 1; + std::size_t strLen = ox::strlen(str) + 1; if (cap() < strLen) { strLen = cap(); } - ox_memcpy(m_buff, str, strLen); + ox::memcpy(m_buff, str, strLen); // make sure last element is a null terminator m_buff[cap()] = 0; return *this; @@ -144,7 +144,7 @@ constexpr BString &BString::operator=(char *str) noexcept { template constexpr BString &BString::operator+=(const char *str) noexcept { - std::size_t strLen = ox_strlen(str) + 1; + std::size_t strLen = ox::strlen(str) + 1; oxIgnoreError(append(str, strLen)); return *this; } @@ -157,7 +157,7 @@ constexpr BString &BString::operator+=(char *str) noexcept { template constexpr BString &BString::operator+=(Integer_c auto i) noexcept { char str[65] = {}; - ox_itoa(i, str); + ox::itoa(i, str); return this->operator+=(str); } @@ -171,7 +171,7 @@ constexpr BString &BString::operator+=(StringView s) noexcept { template constexpr BString BString::operator+(const char *str) const noexcept { auto out = *this; - std::size_t strLen = ox_strlen(str) + 1; + std::size_t strLen = ox::strlen(str) + 1; oxIgnoreError(out.append(str, strLen)); return out; } @@ -184,7 +184,7 @@ constexpr BString BString::operator+(char *str) const noexcept { template constexpr BString BString::operator+(Integer_c auto i) const noexcept { char str[65] = {}; - ox_itoa(i, str); + ox::itoa(i, str); return this->operator+(str); } @@ -226,7 +226,7 @@ constexpr Error BString::append(const char *str, std::size_t strLen) no strLen = cap() - currentLen; err = OxError(1, "Insufficient space for full string"); } - ox_strncpy(m_buff + currentLen, str, strLen); + ox::strncpy(m_buff + currentLen, str, strLen); // make sure last element is a null terminator m_buff[currentLen + strLen] = 0; return err; diff --git a/deps/ox/src/ox/std/buffer.hpp b/deps/ox/src/ox/std/buffer.hpp index 2753c821..674a4a20 100644 --- a/deps/ox/src/ox/std/buffer.hpp +++ b/deps/ox/src/ox/std/buffer.hpp @@ -192,7 +192,7 @@ class BufferReader { if (m_it + sz > m_size) [[unlikely]] { return OxError(1, "Read failed: Buffer overrun"); } - ox_memcpy(v, &m_buff[m_it], sz); + ox::memcpy(v, &m_buff[m_it], sz); m_it += sz; return sz; } diff --git a/deps/ox/src/ox/std/cstrops.hpp b/deps/ox/src/ox/std/cstrops.hpp index d0d26ffe..4b5b02c1 100644 --- a/deps/ox/src/ox/std/cstrops.hpp +++ b/deps/ox/src/ox/std/cstrops.hpp @@ -11,8 +11,10 @@ #include "types.hpp" #include "typetraits.hpp" +namespace ox { + template -constexpr T1 ox_strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept { +constexpr T1 strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept { using T1Type = typename ox::remove_reference::type; std::size_t i = 0; while (i < maxLen && src[i]) { @@ -25,7 +27,7 @@ constexpr T1 ox_strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept { } [[nodiscard]] -constexpr auto ox_strnlen(const char *str1, std::size_t maxLen) noexcept { +constexpr auto strnlen(const char *str1, std::size_t maxLen) noexcept { std::size_t len = 0; for (; len < maxLen && str1[len]; len++); return len; @@ -33,7 +35,7 @@ constexpr auto ox_strnlen(const char *str1, std::size_t maxLen) noexcept { template [[nodiscard]] -constexpr auto ox_strlen(T const&str1) noexcept { +constexpr auto strlen(T const&str1) noexcept { std::size_t len = 0; for (; str1[len]; len++); return len; @@ -41,7 +43,7 @@ constexpr auto ox_strlen(T const&str1) noexcept { template [[nodiscard]] -constexpr int ox_strcmp(const T1 &str1, const T2 &str2) noexcept { +constexpr int strcmp(const T1 &str1, const T2 &str2) noexcept { auto retval = 0; auto i = 0u; while (str1[i] || str2[i]) { @@ -59,7 +61,7 @@ constexpr int ox_strcmp(const T1 &str1, const T2 &str2) noexcept { template [[nodiscard]] -constexpr int ox_strncmp(T1 const&str1, T2 const&str2, const std::size_t maxLen) noexcept { +constexpr int strncmp(T1 const&str1, T2 const&str2, const std::size_t maxLen) noexcept { auto retval = 0; std::size_t i = 0; while (i < maxLen && (str1[i] || str2[i])) { @@ -76,7 +78,7 @@ constexpr int ox_strncmp(T1 const&str1, T2 const&str2, const std::size_t maxLen) } [[nodiscard]] -constexpr const char *ox_strchr(const char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept { +constexpr const char *strchr(const char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept { for (std::size_t i = 0; i <= maxLen; i++) { if (str[i] == character) { return &str[i]; @@ -88,7 +90,7 @@ constexpr const char *ox_strchr(const char *str, int character, std::size_t maxL } [[nodiscard]] -constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept { +constexpr char *strchr(char *str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept { for (std::size_t i = 0; i < maxLen; i++) { if (str[i] == character) { return &str[i]; @@ -100,7 +102,7 @@ constexpr char *ox_strchr(char *str, int character, std::size_t maxLen = 0xFFFFF } [[nodiscard]] -constexpr int ox_lastIndexOf(const auto &str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept { +constexpr int lastIndexOf(const auto &str, int character, std::size_t maxLen = 0xFFFFFFFF) noexcept { int retval = -1; for (std::size_t i = 0; i < maxLen && str[i]; i++) { if (str[i] == character) { @@ -111,7 +113,7 @@ constexpr int ox_lastIndexOf(const auto &str, int character, std::size_t maxLen } template -constexpr T ox_itoa(Integer v, T str) noexcept { +constexpr T itoa(Integer v, T str) noexcept { if (v) { ox::ResizedInt_t mod = 1000000000000000000; ox::ResizedInt_t val = v; @@ -143,3 +145,5 @@ constexpr T ox_itoa(Integer v, T str) noexcept { } return str; } + +} diff --git a/deps/ox/src/ox/std/fmt.hpp b/deps/ox/src/ox/std/fmt.hpp index f1621bd1..aa13b0b4 100644 --- a/deps/ox/src/ox/std/fmt.hpp +++ b/deps/ox/src/ox/std/fmt.hpp @@ -81,7 +81,7 @@ class FmtArg { if constexpr(is_bool_v) { return v ? "true" : "false"; } else if constexpr(is_integer_v) { - return ox_itoa(v, dataStr); + return ox::itoa(v, dataStr); } else { return toStringView(v); } @@ -126,11 +126,11 @@ struct FmtSegment { unsigned length = 0; constexpr bool operator==(const FmtSegment &o) const noexcept { - return length == o.length && ox_strncmp(str, o.str, length) == 0; + return length == o.length && ox::strncmp(str, o.str, length) == 0; } constexpr bool operator!=(const FmtSegment &o) const noexcept { - return length != o.length || ox_strncmp(str, o.str, length) != 0; + return length != o.length || ox::strncmp(str, o.str, length) != 0; } }; diff --git a/deps/ox/src/ox/std/hashmap.hpp b/deps/ox/src/ox/std/hashmap.hpp index 868f5ae5..f1c05431 100644 --- a/deps/ox/src/ox/std/hashmap.hpp +++ b/deps/ox/src/ox/std/hashmap.hpp @@ -45,16 +45,16 @@ class HashMap { constexpr HashMap &operator=(HashMap &&other) noexcept; - constexpr T &operator[](MaybeSV_t const&key); + constexpr T &operator[](MaybeView_t const&key); - constexpr Result at(MaybeSV_t const&key) noexcept; + constexpr Result at(MaybeView_t const&key) noexcept; - constexpr Result at(MaybeSV_t const&key) const noexcept; + constexpr Result at(MaybeView_t const&key) const noexcept; - constexpr void erase(MaybeSV_t const&key); + constexpr void erase(MaybeView_t const&key); [[nodiscard]] - constexpr bool contains(MaybeSV_t const&key) const noexcept; + constexpr bool contains(MaybeView_t const&key) const noexcept; [[nodiscard]] constexpr std::size_t size() const noexcept; @@ -134,7 +134,7 @@ constexpr HashMap &HashMap::operator=(HashMap &&other) noexcep } template -constexpr T &HashMap::operator[](MaybeSV_t const&k) { +constexpr T &HashMap::operator[](MaybeView_t const&k) { auto &p = access(m_pairs, k); if (p == nullptr) { if (static_cast(m_pairs.size()) * 0.7 < @@ -149,7 +149,7 @@ constexpr T &HashMap::operator[](MaybeSV_t const&k) { } template -constexpr Result HashMap::at(MaybeSV_t const&k) noexcept { +constexpr Result HashMap::at(MaybeView_t const&k) noexcept { auto p = access(m_pairs, k); if (!p) { return {nullptr, OxError(1, "value not found for given key")}; @@ -158,7 +158,7 @@ constexpr Result HashMap::at(MaybeSV_t const&k) noexcept { } template -constexpr Result HashMap::at(MaybeSV_t const&k) const noexcept { +constexpr Result HashMap::at(MaybeView_t const&k) const noexcept { auto p = access(m_pairs, k); if (!p) { return {nullptr, OxError(1, "value not found for given key")}; @@ -167,7 +167,7 @@ constexpr Result HashMap::at(MaybeSV_t const&k) const noexcep } template -constexpr void HashMap::erase(MaybeSV_t const&k) { +constexpr void HashMap::erase(MaybeView_t const&k) { if (!contains(k)) { return; } @@ -185,7 +185,7 @@ constexpr void HashMap::erase(MaybeSV_t const&k) { } template -constexpr bool HashMap::contains(MaybeSV_t const&k) const noexcept { +constexpr bool HashMap::contains(MaybeView_t const&k) const noexcept { return access(m_pairs, k) != nullptr; } @@ -212,7 +212,7 @@ template constexpr void HashMap::expand() { Vector r; for (std::size_t i = 0; i < m_keys.size(); ++i) { - K k{m_keys[i]}; + auto const&k = m_keys[i]; access(r, k) = std::move(access(m_pairs, k)); } m_pairs = std::move(r); diff --git a/deps/ox/src/ox/std/maybeview.hpp b/deps/ox/src/ox/std/maybeview.hpp new file mode 100644 index 00000000..e9992391 --- /dev/null +++ b/deps/ox/src/ox/std/maybeview.hpp @@ -0,0 +1,26 @@ +/* + * Copyright 2015 - 2022 gary@drinkingtea.net + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "typetraits.hpp" + +namespace ox { + +// Maybe StringView. If T is a string type, MaybeType::type/MaybeView_t is a +// StringView. This avoids creating unnecessary Strings when taking a +// StringView or C string as a function argument. +template> +struct MaybeView { + using type = T; +}; + +template +using MaybeView_t = typename MaybeView::type; + +} diff --git a/deps/ox/src/ox/std/memops.cpp b/deps/ox/src/ox/std/memops.cpp index 16c71ca1..c76dbf11 100644 --- a/deps/ox/src/ox/std/memops.cpp +++ b/deps/ox/src/ox/std/memops.cpp @@ -6,6 +6,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +#include "defines.hpp" #include "types.hpp" #include "memops.hpp" @@ -16,15 +17,15 @@ extern "C" { void *ox_inhibit_loop_to_libcall memcpy(void *dest, const void *src, std::size_t size) { - return ox_memcpy(dest, src, size); + return ox::memcpy(dest, src, size); } void *ox_inhibit_loop_to_libcall memmove(void *dest, const void *src, std::size_t size) { - return ox_memcpy(dest, src, size); + return ox::memcpy(dest, src, size); } void *ox_inhibit_loop_to_libcall memset(void *ptr, int val, std::size_t size) { - return ox_memset(ptr, val, size); + return ox::memset(ptr, val, size); } @@ -50,6 +51,48 @@ int ox_inhibit_loop_to_libcall memcmp(const void *ptr1, const void *ptr2, std::s #endif -int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { - return memcmp(ptr1, ptr2, size); +namespace ox { + +void *memmove(void *dest, const void *src, std::size_t size) noexcept { + if constexpr(!ox::defines::UseStdLib) { + auto srcBuf = static_cast(src); + auto dstBuf = static_cast(dest); + for (std::size_t i = 0; i < size; ++i) { + dstBuf[i] = static_cast(srcBuf[i]); + } + return dest; + } else { + return ::memmove(dest, src, size); + } +} + +void *memset(void *ptr, int val, std::size_t size) noexcept { + if constexpr(!ox::defines::UseStdLib) { + auto buf = static_cast(ptr); + for (std::size_t i = 0; i < size; ++i) { + buf[i] = static_cast(val); + } + return ptr; + } else { + return ::memset(ptr, val, size); + } +} + +void *memcpy(void *dest, const void *src, std::size_t size) noexcept { + if constexpr(!ox::defines::UseStdLib) { + auto srcBuf = static_cast(src); + auto dstBuf = static_cast(dest); + for (std::size_t i = 0; i < size; ++i) { + dstBuf[i] = static_cast(srcBuf[i]); + } + return dest; + } else { + return ::memcpy(dest, src, size); + } +} + +int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { + return ::memcmp(ptr1, ptr2, size); +} + } diff --git a/deps/ox/src/ox/std/memops.hpp b/deps/ox/src/ox/std/memops.hpp index 56bd7d11..470eebe5 100644 --- a/deps/ox/src/ox/std/memops.hpp +++ b/deps/ox/src/ox/std/memops.hpp @@ -8,7 +8,6 @@ #pragma once -#include "defines.hpp" #include "types.hpp" #include "typetraits.hpp" @@ -28,63 +27,28 @@ int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept; } #endif -int ox_memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept; - -constexpr void *ox_memcpy(void *dest, const void *src, std::size_t size) noexcept { - if (std::is_constant_evaluated() || !ox::defines::UseStdLib) { - auto srcBuf = static_cast(src); - auto dstBuf = static_cast(dest); - for (std::size_t i = 0; i < size; ++i) { - dstBuf[i] = static_cast(srcBuf[i]); - } - return dest; - } else { - return memcpy(dest, src, size); - } -} - -constexpr void *ox_memmove(void *dest, const void *src, std::size_t size) noexcept { - if (std::is_constant_evaluated() || !ox::defines::UseStdLib) { - auto srcBuf = static_cast(src); - auto dstBuf = static_cast(dest); - for (std::size_t i = 0; i < size; ++i) { - dstBuf[i] = static_cast(srcBuf[i]); - } - return dest; - } else { - return memmove(dest, src, size); - } -} - -constexpr void *ox_memset(void *ptr, int val, std::size_t size) noexcept { - if (std::is_constant_evaluated() || !ox::defines::UseStdLib) { - auto buf = static_cast(ptr); - for (std::size_t i = 0; i < size; ++i) { - buf[i] = static_cast(val); - } - return ptr; - } else { - return memset(ptr, val, size); - } -} - namespace ox { -constexpr void *memmove(void *dest, const void *src, std::size_t size) { - return ox_memmove(dest, src, size); +template +constexpr T1 *listcpy(T1 *dest, T2 *src, std::size_t maxLen) noexcept { + using T1Type = typename ox::remove_reference::type; + std::size_t i = 0; + while (i < maxLen && src[i]) { + dest[i] = static_cast(src[i]); + ++i; + } + // set null terminator + dest[i] = 0; + return dest; } -constexpr void *memset(void *ptr, int val, std::size_t size) noexcept { - return ox_memset(ptr, val, size); -} +void *memmove(void *dest, const void *src, std::size_t size) noexcept; -constexpr void *memcpy(void *dest, const void *src, std::size_t size) noexcept { - return ox_memcpy(dest, src, size); -} +void *memset(void *ptr, int val, std::size_t size) noexcept; -inline int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept { - return ox_memcmp(ptr1, ptr2, size); -} +void *memcpy(void *dest, const void *src, std::size_t size) noexcept; + +int memcmp(const void *ptr1, const void *ptr2, std::size_t size) noexcept; template void *memsetElements(T *ptr, T val, std::size_t elements) noexcept { diff --git a/deps/ox/src/ox/std/span.hpp b/deps/ox/src/ox/std/span.hpp index 1d0af4fb..da9272f8 100644 --- a/deps/ox/src/ox/std/span.hpp +++ b/deps/ox/src/ox/std/span.hpp @@ -8,6 +8,7 @@ #pragma once +#include "array.hpp" #include "bit.hpp" #include "iterator.hpp" #include "vector.hpp" diff --git a/deps/ox/src/ox/std/std.hpp b/deps/ox/src/ox/std/std.hpp index c77eacce..d2baca98 100644 --- a/deps/ox/src/ox/std/std.hpp +++ b/deps/ox/src/ox/std/std.hpp @@ -8,6 +8,7 @@ #pragma once +#include "anyptr.hpp" #include "array.hpp" #include "assert.hpp" #include "bit.hpp" @@ -28,6 +29,7 @@ #include "ignore.hpp" #include "iterator.hpp" #include "math.hpp" +#include "maybeview.hpp" #include "memops.hpp" #include "memory.hpp" #include "new.hpp" diff --git a/deps/ox/src/ox/std/string.hpp b/deps/ox/src/ox/std/string.hpp index 772932de..af137802 100644 --- a/deps/ox/src/ox/std/string.hpp +++ b/deps/ox/src/ox/std/string.hpp @@ -15,6 +15,7 @@ #include "algorithm.hpp" #include "memops.hpp" #include "serialize.hpp" +#include "stringliteral.hpp" #include "stringview.hpp" #include "strops.hpp" #include "vector.hpp" @@ -32,12 +33,17 @@ class BasicString { constexpr explicit BasicString(std::size_t cap) noexcept; + template + constexpr BasicString(char const (&str)[Sz]) noexcept; + constexpr explicit BasicString(const char *str) noexcept; constexpr explicit BasicString(const char8_t *str) noexcept; constexpr BasicString(const char *str, std::size_t size) noexcept; + constexpr explicit BasicString(StringLiteral const&str) noexcept; + constexpr explicit BasicString(CRStringView str) noexcept; constexpr explicit BasicString(BasicString const&) noexcept; @@ -167,7 +173,7 @@ class BasicString { constexpr Error append(const char *str, std::size_t strLen) noexcept { auto currentLen = len(); m_buff.resize(m_buff.size() + strLen); - ox_memcpy(&m_buff[currentLen], str, strLen); + ox::listcpy(&m_buff[currentLen], str, strLen); // make sure last element is a null terminator m_buff[currentLen + strLen] = 0; // this can't fail, but it returns an Error to match BString::append @@ -270,10 +276,15 @@ constexpr BasicString::BasicString(const char8_t *str) noexce template constexpr BasicString::BasicString(const char *str, std::size_t size) noexcept { m_buff.resize(size + 1); - memcpy(m_buff.data(), str, size); + ox::listcpy(m_buff.data(), str, size); m_buff[size] = 0; } +template +constexpr BasicString::BasicString(StringLiteral const&str) noexcept: + BasicString(StringView{str.data(), str.bytes()}) { +} + template constexpr BasicString::BasicString(CRStringView str) noexcept { if (m_buff.empty()) { @@ -315,7 +326,7 @@ constexpr BasicString &BasicString::operat template constexpr BasicString &BasicString::operator=(int64_t i) noexcept { ox::Array str{}; - ox_itoa(i, str.data()); + ox::itoa(i, str.data()); set(str.data()); return *this; } @@ -323,7 +334,7 @@ constexpr BasicString &BasicString::operat template constexpr BasicString &BasicString::operator=(uint64_t i) noexcept { ox::Array str{}; - ox_itoa(i, str.data()); + ox::itoa(i, str.data()); set(str.data()); return *this; } @@ -352,7 +363,7 @@ constexpr BasicString &BasicString::operat template constexpr BasicString &BasicString::operator+=(const char *str) noexcept { - std::size_t strLen = ox_strlen(str); + std::size_t strLen = ox::strlen(str); oxIgnoreError(append(str, strLen)); return *this; } @@ -371,7 +382,7 @@ constexpr BasicString &BasicString::operat template constexpr BasicString &BasicString::operator+=(Integer_c auto i) noexcept { char str[65] = {}; - ox_itoa(i, str); + ox::itoa(i, str); return this->operator+=(str); } @@ -390,12 +401,12 @@ constexpr BasicString &BasicString::operat template constexpr BasicString BasicString::operator+(const char *str) const noexcept { - const std::size_t strLen = ox_strlen(str); + const std::size_t strLen = ox::strlen(str); const auto currentLen = len(); BasicString cpy(currentLen + strLen); cpy.m_buff.resize(m_buff.size() + strLen); - memcpy(&cpy.m_buff[0], m_buff.data(), currentLen); - memcpy(&cpy.m_buff[currentLen], str, strLen); + ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen); + ox::listcpy(&cpy.m_buff[currentLen], str, strLen); // make sure last element is a null terminator cpy.m_buff[currentLen + strLen] = 0; return cpy; @@ -415,7 +426,7 @@ constexpr BasicString BasicString::operato template constexpr BasicString BasicString::operator+(Integer_c auto i) const noexcept { char str[65] = {}; - ox_itoa(i, str); + ox::itoa(i, str); return *this + str; } @@ -425,8 +436,8 @@ constexpr BasicString BasicString::operato const auto currentLen = len(); BasicString cpy(currentLen + strLen); cpy.m_buff.resize(m_buff.size() + strLen); - memcpy(&cpy.m_buff[0], m_buff.data(), currentLen); - memcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1); + ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen); + ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1); return cpy; } @@ -436,8 +447,8 @@ constexpr BasicString BasicString::operato const auto currentLen = len(); BasicString cpy(currentLen + strLen); cpy.m_buff.resize(m_buff.size() + strLen); - memcpy(&cpy.m_buff[0], m_buff.data(), currentLen); - memcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1); + ox::listcpy(&cpy.m_buff[0], m_buff.data(), currentLen); + ox::listcpy(&cpy.m_buff[currentLen], src.data(), strLen + 1); return cpy; } @@ -470,22 +481,22 @@ constexpr bool BasicString::operator!=(OxString_c auto const& template constexpr bool BasicString::operator<(BasicString const&other) const noexcept { - return ox_strcmp(c_str(), other.c_str()) < 0; + return ox::strcmp(c_str(), other.c_str()) < 0; } template constexpr bool BasicString::operator>(BasicString const&other) const noexcept { - return ox_strcmp(c_str(), other.c_str()) > 0; + return ox::strcmp(c_str(), other.c_str()) > 0; } template constexpr bool BasicString::operator<=(BasicString const&other) const noexcept { - return ox_strcmp(c_str(), other.c_str()) < 1; + return ox::strcmp(c_str(), other.c_str()) < 1; } template constexpr bool BasicString::operator>=(BasicString const&other) const noexcept { - return ox_strcmp(c_str(), other.c_str()) > -1; + return ox::strcmp(c_str(), other.c_str()) > -1; } template @@ -509,7 +520,7 @@ constexpr BasicString BasicString::substr( const auto size = end - begin; BasicString out(size); const auto buff = out.data(); - memcpy(buff, src, size); + ox::listcpy(buff, src, size); buff[size] = 0; return out; } @@ -548,9 +559,9 @@ constexpr void BasicString::set(CRStringView str) noexcept { template constexpr void BasicString::set(const char8_t *str) noexcept { - std::size_t strBytes = ox_strlen(str) + 1; + std::size_t strBytes = ox::strlen(str) + 1; m_buff.resize(strBytes); - memcpy(m_buff.data(), str, strBytes); + ox::listcpy(m_buff.data(), str, strBytes); *m_buff.back().value = 0; } diff --git a/deps/ox/src/ox/std/stringview.hpp b/deps/ox/src/ox/std/stringview.hpp index 46ff5b46..06ca90fa 100644 --- a/deps/ox/src/ox/std/stringview.hpp +++ b/deps/ox/src/ox/std/stringview.hpp @@ -14,6 +14,7 @@ #include "basestringview.hpp" #include "cstrops.hpp" +#include "maybeview.hpp" #include "writer.hpp" namespace ox { @@ -63,7 +64,7 @@ constexpr auto operator==(CRStringView s1, CRStringView s2) noexcept { if (s2.len() != s1.len()) { return false; } - return ox_strncmp(s1.data(), s2.data(), s1.len()) == 0; + return ox::strncmp(s1.data(), s2.data(), s1.len()) == 0; } constexpr auto operator<=>(CRStringView s1, CRStringView s2) noexcept { @@ -97,24 +98,12 @@ constexpr auto toStdStringView(CRStringView sv) noexcept { #endif -// Maybe StringView. If T is a string type, MaybeType::type/MaybeSV_t is a -// StringView. This avoids creating unnecessary Strings when taking a -// StringView or C string as a function argument. -template> -struct MaybeSV { - using type = T; -}; template -struct MaybeSV { +struct MaybeView { using type = ox::StringView; }; -template -using MaybeSV_t = typename MaybeSV::type; - -} - -constexpr ox::Result ox_atoi(ox::CRStringView str) noexcept { +constexpr ox::Result atoi(ox::CRStringView str) noexcept { int total = 0; int multiplier = 1; for (auto i = static_cast(str.len()) - 1; i != -1; --i) { @@ -129,3 +118,6 @@ constexpr ox::Result ox_atoi(ox::CRStringView str) noexcept { return total; } + +} + diff --git a/deps/ox/src/ox/std/strops.cpp b/deps/ox/src/ox/std/strops.cpp index 532c3bfe..6396ddf4 100644 --- a/deps/ox/src/ox/std/strops.cpp +++ b/deps/ox/src/ox/std/strops.cpp @@ -8,26 +8,26 @@ #include "strops.hpp" -static_assert(ox_strcmp("asdf", "hijk") < 0, "asdf < hijk"); -static_assert(ox_strcmp("hijk", "asdf") > 0, "hijk > asdf"); -static_assert(ox_strcmp("resize", "read") > 0, "resize > read"); -static_assert(ox_strcmp("read", "resize") < 0, "read < resize"); -static_assert(ox_strcmp("resize", "resize") == 0, "resize == resize"); -static_assert(ox_strcmp("", "") == 0, "\"\" == \"\""); +static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk"); +static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf"); +static_assert(ox::strcmp("resize", "read") > 0, "resize > read"); +static_assert(ox::strcmp("read", "resize") < 0, "read < resize"); +static_assert(ox::strcmp("resize", "resize") == 0, "resize == resize"); +static_assert(ox::strcmp("", "") == 0, "\"\" == \"\""); static_assert([] { auto testStr = "asdf"; - return ox_strchr(testStr, 0, 4) == &testStr[4]; -}(), "ox_strchr 0"); + return ox::strchr(testStr, 0, 4) == &testStr[4]; +}(), "ox::strchr 0"); static_assert([] { int retval = 0; auto testStr = "aaaa"; - // test the const and non-const versions of ox_lastIndexOf - retval |= !(ox_lastIndexOf(const_cast(testStr), 'a', ox_strlen(testStr)) == 3); - retval |= !(ox_lastIndexOf(testStr, 'a', ox_strlen(testStr)) == 3); + // test the const and non-const versions of ox::lastIndexOf + retval |= !(ox::lastIndexOf(const_cast(testStr), 'a', ox::strlen(testStr)) == 3); + retval |= !(ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3); return retval == 0; -}(), "ox_lastIndexOf aaaa a"); +}(), "ox::lastIndexOf aaaa a"); #ifndef OX_USE_STDLIB diff --git a/deps/ox/src/ox/std/strops.hpp b/deps/ox/src/ox/std/strops.hpp index e3c943e9..e3f63f64 100644 --- a/deps/ox/src/ox/std/strops.hpp +++ b/deps/ox/src/ox/std/strops.hpp @@ -37,7 +37,7 @@ constexpr ox::StringView substr(Str const&str, std::size_t start, std::size_t en } template -constexpr ox::Error itoa(Integer v, ox::Writer_c auto &writer) noexcept { +constexpr ox::Error writeItoa(Integer v, ox::Writer_c auto &writer) noexcept { if (v) { ox::ResizedInt_t mod = 1000000000000000000; ox::ResizedInt_t val = v; @@ -71,13 +71,13 @@ constexpr ox::Error itoa(Integer v, ox::Writer_c auto &writer) noexcept { [[nodiscard]] constexpr bool beginsWith(CRStringView base, CRStringView beginning) noexcept { const auto beginningLen = ox::min(beginning.len(), base.len()); - return base.len() >= beginning.len() && ox_strncmp(base.data(), beginning, beginningLen) == 0; + return base.len() >= beginning.len() && ox::strncmp(base.data(), beginning, beginningLen) == 0; } [[nodiscard]] constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept { const auto endingLen = ending.len(); - return base.len() >= endingLen && ox_strcmp(base.data() + (base.len() - endingLen), ending) == 0; + return base.len() >= endingLen && ox::strcmp(base.data() + (base.len() - endingLen), ending) == 0; } [[nodiscard]] diff --git a/deps/ox/src/ox/std/test/tests.cpp b/deps/ox/src/ox/std/test/tests.cpp index b04ddf3e..14f8bdcb 100644 --- a/deps/ox/src/ox/std/test/tests.cpp +++ b/deps/ox/src/ox/std/test/tests.cpp @@ -30,13 +30,13 @@ static std::map tests = { []() { ox::Array buff; ox::CharBuffWriter bw(buff); - oxAssert(ox::itoa(5, bw), "ox::itoa returned Error"); + oxAssert(ox::writeItoa(5, bw), "ox::writeItoa returned Error"); oxExpect(ox::StringView(buff.data()), ox::StringView("5")); oxReturnError(bw.seekp(0)); - oxAssert(ox::itoa(50, bw), "ox::itoa returned Error"); + oxAssert(ox::writeItoa(50, bw), "ox::writeItoa returned Error"); oxExpect(ox::StringView(buff.data()), ox::StringView("50")); oxReturnError(bw.seekp(0)); - oxAssert(ox::itoa(500, bw), "ox::itoa returned Error"); + oxAssert(ox::writeItoa(500, bw), "ox::writeItoa returned Error"); oxExpect(ox::StringView(buff.data()), ox::StringView("500")); return ox::Error{}; } @@ -44,25 +44,25 @@ static std::map tests = { { "ABCDEFG != HIJKLMN", []() { - return OxError(ox_memcmp("ABCDEFG", "HIJKLMN", 7) >= 0); + return OxError(ox::memcmp("ABCDEFG", "HIJKLMN", 7) >= 0); } }, { "HIJKLMN != ABCDEFG", []() { - return OxError(ox_memcmp("HIJKLMN", "ABCDEFG", 7) <= 0); + return OxError(ox::memcmp("HIJKLMN", "ABCDEFG", 7) <= 0); } }, { "ABCDEFG == ABCDEFG", []() { - return OxError(ox_memcmp("ABCDEFG", "ABCDEFG", 7) != 0); + return OxError(ox::memcmp("ABCDEFG", "ABCDEFG", 7) != 0); } }, { "ABCDEFGHI == ABCDEFG", []() { - return OxError(ox_memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0); + return OxError(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0); } }, { diff --git a/deps/ox/src/ox/std/tracehook.cpp b/deps/ox/src/ox/std/tracehook.cpp index 7498954d..a0a0528d 100644 --- a/deps/ox/src/ox/std/tracehook.cpp +++ b/deps/ox/src/ox/std/tracehook.cpp @@ -42,7 +42,7 @@ enum LogChan { template static void log(ox::CRStringView str) { const auto sz = ox::min(0x100, str.bytes()); - ox_strncpy(REG_MGBA_DEBUG_STRING, str.data(), sz); + ox::strncpy(REG_MGBA_DEBUG_STRING, str.data(), sz); REG_MGBA_DEBUG_FLAGS = chan | 0x100; } @@ -69,30 +69,30 @@ void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line, std::cout << std::setw(53) << std::left << ch << "| "; std::cout << std::setw(65) << std::left << msg << '|'; std::cout << " " << file << ':' << line << "\n"; - } else if (ox_strcmp(ch, "debug") == 0 || ox_strcmp(ch, "info") == 0) { + } else if (ox::strcmp(ch, "debug") == 0 || ox::strcmp(ch, "info") == 0) { printf("%s\n", msg); fflush(stdout); - } else if (ox_strcmp(ch, "stdout") == 0) { + } else if (ox::strcmp(ch, "stdout") == 0) { printf("%s", msg); fflush(stdout); - } else if (ox_strcmp(ch, "stderr") == 0) { + } else if (ox::strcmp(ch, "stderr") == 0) { printf("%s", msg); fflush(stdout); - } else if (ox_strcmp(ch, "error") == 0) { + } else if (ox::strcmp(ch, "error") == 0) { //std::cerr << "\033[31;1;1mERROR:\033[0m (" << file << ':' << line << "): " << msg << '\n'; fprintf(stderr, "\033[31;1;1mERROR:\033[0m (%s:%d): %s\n", file, line, msg); fflush(stderr); } #else - if (ox_strcmp(ch, "info") == 0) { + if (ox::strcmp(ch, "info") == 0) { infoLog(msg); - } else if (ox_strcmp(ch, "debug") == 0) { + } else if (ox::strcmp(ch, "debug") == 0) { debugLog(msg); - } else if (ox_strcmp(ch, "stdout") == 0) { + } else if (ox::strcmp(ch, "stdout") == 0) { infoLog(msg); - } else if (ox_strcmp(ch, "stderr") == 0) { + } else if (ox::strcmp(ch, "stderr") == 0) { errorLog(msg); - } else if (ox_strcmp(ch, "error") == 0) { + } else if (ox::strcmp(ch, "error") == 0) { errorLog(msg); } #endif diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 364f6c86..56be6e13 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -269,12 +269,12 @@ class Vector: detail::VectorAllocator { } [[nodiscard]] - constexpr bool contains(MaybeSV_t const&) const noexcept(useNoexcept); + constexpr bool contains(MaybeView_t const&) const noexcept(useNoexcept); constexpr iterator insert( - std::size_t pos, std::size_t cnt, MaybeSV_t const&val) noexcept(useNoexcept); + std::size_t pos, std::size_t cnt, MaybeView_t const&val) noexcept(useNoexcept); - constexpr iterator insert(std::size_t pos, MaybeSV_t const&val) noexcept(useNoexcept); + constexpr iterator insert(std::size_t pos, MaybeView_t const&val) noexcept(useNoexcept); template constexpr iterator emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept); @@ -284,7 +284,7 @@ class Vector: detail::VectorAllocator { constexpr void push_back(T &&item) noexcept(useNoexcept); - constexpr void push_back(MaybeSV_t const&item) noexcept(useNoexcept); + constexpr void push_back(MaybeView_t const&item) noexcept(useNoexcept); constexpr void pop_back() noexcept(useNoexcept); @@ -522,7 +522,7 @@ constexpr void Vector::resize(std::size_t size) n } template -constexpr bool Vector::contains(MaybeSV_t const&v) const noexcept(useNoexcept) { +constexpr bool Vector::contains(MaybeView_t const&v) const noexcept(useNoexcept) { for (std::size_t i = 0; i < m_size; i++) { if (m_items[i] == v) { return true; @@ -534,7 +534,7 @@ constexpr bool Vector::contains(MaybeSV_t cons template constexpr typename Vector::template iterator Vector::insert( - std::size_t pos, std::size_t cnt, MaybeSV_t const&val) noexcept(useNoexcept) { + std::size_t pos, std::size_t cnt, MaybeView_t const&val) noexcept(useNoexcept) { if (m_size + cnt > m_cap) { reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt); if (pos < m_size) { @@ -562,7 +562,7 @@ Vector::insert( template constexpr typename Vector::template iterator -Vector::insert(std::size_t pos, MaybeSV_t const&val) noexcept(useNoexcept) { +Vector::insert(std::size_t pos, MaybeView_t const&val) noexcept(useNoexcept) { if (m_size == m_cap) { reserveInsert(m_cap ? m_cap * 2 : initialCap, pos); if (pos < m_size) { @@ -628,7 +628,7 @@ constexpr void Vector::push_back(T &&item) noexce } template -constexpr void Vector::push_back(MaybeSV_t const&item) noexcept(useNoexcept) { +constexpr void Vector::push_back(MaybeView_t const&item) noexcept(useNoexcept) { if (m_size == m_cap) { reserve(m_cap ? m_cap * 2 : initialCap); } diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp index baf95e27..76665047 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.cpp @@ -15,10 +15,11 @@ namespace nostalgia::core { -PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path): +PaletteEditorImGui::PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path): Editor(path), - m_ctx(ctx.tctx), - m_pal(*keel::readObj(keelCtx(m_ctx), ox::FileAddress(itemPath())).unwrapThrow()) { + m_sctx(sctx), + m_tctx(sctx.tctx), + m_pal(*keel::readObj(keelCtx(m_tctx), ox::FileAddress(itemPath())).unwrapThrow()) { undoStack()->changeTriggered.connect(this, &PaletteEditorImGui::handleCommand); } @@ -27,12 +28,12 @@ void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) { return; } if (key >= turbine::Key::Num_1 && key <= turbine::Key::Num_9) { - if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { + if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) { m_page = ox::min( static_cast(key - turbine::Key::Num_1), m_pal.pages.size() - 1); } } else if (key == turbine::Key::Num_0) { - if (turbine::buttonDown(m_ctx, turbine::Key::Mod_Alt)) { + if (turbine::buttonDown(m_tctx, turbine::Key::Mod_Alt)) { m_selectedColorRow = ox::min( static_cast(key - turbine::Key::Num_1 + 9), m_pal.pages.size() - 1); @@ -41,7 +42,7 @@ void PaletteEditorImGui::keyStateChanged(turbine::Key key, bool down) { } -void PaletteEditorImGui::draw(turbine::Context&) noexcept { +void PaletteEditorImGui::draw(studio::StudioContext&) noexcept { auto const paneSize = ImGui::GetContentRegionAvail(); { ImGui::BeginChild("Pages", ImVec2(250, paneSize.y), true); @@ -57,8 +58,7 @@ void PaletteEditorImGui::draw(turbine::Context&) noexcept { } ox::Error PaletteEditorImGui::saveItem() noexcept { - const auto sctx = applicationData(m_ctx); - return sctx->project->writeObj(itemPath(), m_pal); + return m_sctx.project->writeObj(itemPath(), m_pal); } void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept { @@ -70,7 +70,7 @@ void PaletteEditorImGui::drawColumn(ox::CStringView txt) noexcept { void PaletteEditorImGui::drawColumn(uint64_t i) noexcept { ox::Array numStr; - ox_itoa(i, numStr.data()); + ox::itoa(i, numStr.data()); drawColumn(numStr.data()); } diff --git a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp index a683bdc0..d8d5982f 100644 --- a/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor-imgui.hpp @@ -14,17 +14,18 @@ namespace nostalgia::core { class PaletteEditorImGui: public studio::Editor { private: - turbine::Context &m_ctx; + studio::StudioContext &m_sctx; + turbine::Context &m_tctx; Palette m_pal; size_t m_selectedColorRow = 0; size_t m_page = 0; public: - PaletteEditorImGui(studio::StudioContext &ctx, ox::CRStringView path); + PaletteEditorImGui(studio::StudioContext &sctx, ox::CRStringView path); void keyStateChanged(turbine::Key key, bool down) override; - void draw(turbine::Context&) noexcept final; + void draw(studio::StudioContext&) noexcept final; protected: ox::Error saveItem() noexcept final; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.cpp index 96a0bc25..f7ca3611 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.cpp @@ -24,7 +24,7 @@ core::DeleteTilesCommand::DeleteTilesCommand( auto dst = m_deletedPixels.data(); auto src = p.data() + m_deletePos; const auto sz = m_deleteSz * sizeof(decltype(p[0])); - ox_memcpy(dst, src, sz); + ox::memcpy(dst, src, sz); } } @@ -35,8 +35,8 @@ void core::DeleteTilesCommand::redo() noexcept { const auto src = p.data() + srcPos; const auto dst1 = p.data() + m_deletePos; const auto dst2 = p.data() + (p.size() - m_deleteSz); - ox_memmove(dst1, src, p.size() - srcPos); - ox_memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0]))); + ox::memmove(dst1, src, p.size() - srcPos); + ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0]))); } void DeleteTilesCommand::undo() noexcept { @@ -46,8 +46,8 @@ void DeleteTilesCommand::undo() noexcept { const auto dst1 = p.data() + m_deletePos + m_deleteSz; const auto dst2 = src; const auto sz = p.size() - m_deletePos - m_deleteSz; - ox_memmove(dst1, src, sz); - ox_memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); + ox::memmove(dst1, src, sz); + ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); } int DeleteTilesCommand::commandId() const noexcept { diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.cpp index e8e11c18..3ef9618a 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.cpp @@ -24,7 +24,7 @@ core::InsertTilesCommand::InsertTilesCommand( auto dst = m_deletedPixels.data(); auto src = p.data() + p.size() - m_insertCnt; const auto sz = m_insertCnt * sizeof(decltype(p[0])); - ox_memcpy(dst, src, sz); + ox::memcpy(dst, src, sz); } } @@ -34,8 +34,8 @@ void InsertTilesCommand::redo() noexcept { auto dstPos = m_insertPos + m_insertCnt; const auto dst = p.data() + dstPos; const auto src = p.data() + m_insertPos; - ox_memmove(dst, src, p.size() - dstPos); - ox_memset(src, 0, m_insertCnt * sizeof(decltype(p[0]))); + ox::memmove(dst, src, p.size() - dstPos); + ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0]))); } void InsertTilesCommand::undo() noexcept { @@ -46,8 +46,8 @@ void InsertTilesCommand::undo() noexcept { const auto dst1 = p.data() + m_insertPos; const auto dst2 = p.data() + p.size() - m_insertCnt; const auto sz = p.size() - srcIdx; - ox_memmove(dst1, src, sz); - ox_memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); + ox::memmove(dst1, src, sz); + ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); } int InsertTilesCommand::commandId() const noexcept { diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp index 9d2f4ee2..5dc4d83f 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -78,7 +78,7 @@ static ox::Error toPngFile( TileSheetEditorImGui::TileSheetEditorImGui(studio::StudioContext &sctx, ox::CRStringView path): Editor(path), m_sctx(sctx), - m_tctx(sctx.tctx), + m_tctx(m_sctx.tctx), m_view(m_sctx, path, *undoStack()), m_model(m_view.model()) { oxIgnoreError(setPaletteSelection()); @@ -157,7 +157,7 @@ void TileSheetEditorImGui::keyStateChanged(turbine::Key key, bool down) { } } -void TileSheetEditorImGui::draw(turbine::Context&) noexcept { +void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept { auto const paneSize = ImGui::GetContentRegionAvail(); auto const tileSheetParentSize = ImVec2(paneSize.x - m_palViewWidth, paneSize.y); auto const fbSize = ox::Vec2(tileSheetParentSize.x - 16, tileSheetParentSize.y - 16); @@ -237,7 +237,7 @@ void TileSheetEditorImGui::draw(turbine::Context&) noexcept { } ImGui::EndChild(); m_subsheetEditor.draw(m_tctx); - m_exportMenu.draw(m_tctx); + m_exportMenu.draw(m_sctx); } void TileSheetEditorImGui::drawSubsheetSelector( @@ -411,12 +411,12 @@ void TileSheetEditorImGui::drawPaletteSelector() noexcept { if (pages > 1) { ImGui::Indent(20); ox::Array numStr; - ox_itoa(m_model.palettePage() + 1, numStr.data()); + ox::itoa(m_model.palettePage() + 1, numStr.data()); ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - comboWidthSub); if (ImGui::BeginCombo("Page", numStr.data(), 0)) { for (auto n = 0u; n < pages; ++n) { auto const selected = (m_model.palettePage() == n); - ox_itoa(n + 1, numStr.data()); + ox::itoa(n + 1, numStr.data()); if (ImGui::Selectable(numStr.data(), selected) && m_model.palettePage() != n) { m_model.setPalettePage(n); } @@ -482,7 +482,7 @@ ox::Error TileSheetEditorImGui::markUnsavedChanges(studio::UndoCommand const*) n return {}; } -void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &ctx) noexcept { +void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &sctx) noexcept { constexpr auto popupName = "Edit Subsheet"; if (!m_show) { return; @@ -491,7 +491,7 @@ void TileSheetEditorImGui::SubSheetEditor::draw(turbine::Context &ctx) noexcept auto constexpr popupWidth = 235.f; auto const popupHeight = modSize ? 130.f : 85.f; auto const popupSz = ImVec2(popupWidth, popupHeight); - if (ig::BeginPopup(ctx, popupName, m_show, popupSz)) { + if (ig::BeginPopup(sctx, popupName, m_show, popupSz)) { ImGui::InputText("Name", m_name.data(), m_name.cap()); if (modSize) { ImGui::InputInt("Columns", &m_cols); @@ -508,7 +508,7 @@ void TileSheetEditorImGui::SubSheetEditor::close() noexcept { m_show = false; } -void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &ctx) noexcept { +void TileSheetEditorImGui::ExportMenu::draw(studio::StudioContext &sctx) noexcept { constexpr auto popupName = "Export Tile Sheet"; if (!m_show) { return; @@ -516,7 +516,7 @@ void TileSheetEditorImGui::ExportMenu::draw(turbine::Context &ctx) noexcept { constexpr auto popupWidth = 235.f; constexpr auto popupHeight = 85.f; constexpr auto popupSz = ImVec2(popupWidth, popupHeight); - if (ig::BeginPopup(ctx, popupName, m_show, popupSz)) { + if (ig::BeginPopup(sctx.tctx, popupName, m_show, popupSz)) { ImGui::InputInt("Scale", &m_scale); m_scale = ox::clamp(m_scale, 1, 50); if (ig::PopupControlsOkCancel(popupWidth, m_show) == ig::PopupResponse::OK) { diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp index 529bba9a..6a545873 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditor-imgui.hpp @@ -40,7 +40,7 @@ class TileSheetEditorImGui: public studio::Editor { m_cols = cols; m_rows = rows; } - void draw(turbine::Context &ctx) noexcept; + void draw(turbine::Context &sctx) noexcept; void close() noexcept; [[nodiscard]] inline bool isOpen() const noexcept { return m_show; } @@ -55,7 +55,7 @@ class TileSheetEditorImGui: public studio::Editor { m_show = true; m_scale = 5; } - void draw(turbine::Context &ctx) noexcept; + void draw(studio::StudioContext &sctx) noexcept; void close() noexcept; [[nodiscard]] inline bool isOpen() const noexcept { return m_show; } @@ -88,7 +88,7 @@ class TileSheetEditorImGui: public studio::Editor { void keyStateChanged(turbine::Key key, bool down) override; - void draw(turbine::Context&) noexcept override; + void draw(studio::StudioContext&) noexcept override; void drawSubsheetSelector(TileSheet::SubSheet&, TileSheet::SubSheetIdx &path); diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index b3013cde..d5348252 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -43,11 +43,11 @@ static void normalizeSubsheets(TileSheet::SubSheet &ss) noexcept { TileSheetEditorModel::TileSheetEditorModel(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack): m_sctx(sctx), - m_ctx(m_sctx.tctx), + m_tctx(m_sctx.tctx), m_path(path), - m_img(*readObj(keelCtx(m_ctx), m_path).unwrapThrow()), + m_img(*readObj(keelCtx(m_tctx), m_path).unwrapThrow()), // ignore failure to load palette - m_pal(readObj(keelCtx(m_ctx), m_img.defaultPalette).value), + m_pal(readObj(keelCtx(m_tctx), m_img.defaultPalette).value), m_undoStack(undoStack) { normalizeSubsheets(m_img.subsheet); m_pal.updated.connect(this, &TileSheetEditorModel::markUpdated); @@ -71,7 +71,7 @@ void TileSheetEditorModel::cut() { } const auto pt1 = m_selectionOrigin == ox::Point(-1, -1) ? ox::Point(0, 0) : m_selectionOrigin; const auto pt2 = ox::Point(s.columns * TileWidth, s.rows * TileHeight); - turbine::setClipboardObject(m_ctx, std::move(cb)); + turbine::setClipboardObject(m_tctx, std::move(cb)); pushCommand(ox::make(CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); } @@ -88,11 +88,11 @@ void TileSheetEditorModel::copy() { cb->addPixel(pt, c); } } - turbine::setClipboardObject(m_ctx, std::move(cb)); + turbine::setClipboardObject(m_tctx, std::move(cb)); } void TileSheetEditorModel::paste() { - auto [cb, err] = turbine::getClipboardObject(m_ctx); + auto [cb, err] = turbine::getClipboardObject(m_tctx); if (err) { oxLogError(err); oxErrf("Could not read clipboard: {}", toStr(err)); @@ -112,7 +112,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept { constexpr ox::StringView uuidPrefix = "uuid://"; if (ox::beginsWith(path, uuidPrefix)) { auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes()); - auto out = keelCtx(m_ctx).uuidToPath.at(uuid); + auto out = keelCtx(m_tctx).uuidToPath.at(uuid); if (out.error) { return {}; } @@ -123,7 +123,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept { } ox::Error TileSheetEditorModel::setPalette(ox::StringView path) noexcept { - oxRequire(uuid, keelCtx(m_ctx).pathToUuid.at(path)); + oxRequire(uuid, keelCtx(m_tctx).pathToUuid.at(path)); pushCommand(ox::make(activeSubSheetIdx(), m_img, uuid->toString())); return {}; } @@ -240,7 +240,7 @@ ox::Error TileSheetEditorModel::markUpdatedCmdId(studio::UndoCommand const*cmd) m_updated = true; const auto cmdId = cmd->commandId(); if (static_cast(cmdId) == CommandId::PaletteChange) { - oxReturnError(readObj(keelCtx(m_ctx), m_img.defaultPalette).moveTo(m_pal)); + oxReturnError(readObj(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal)); m_palettePage = ox::min(m_pal->pages.size(), 0); paletteChanged.emit(); } diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp index fcee5a9e..f4fe90e5 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditormodel.hpp @@ -25,7 +25,7 @@ class TileSheetEditorModel: public ox::SignalHandler { private: static Palette const s_defaultPalette; studio::StudioContext &m_sctx; - turbine::Context &m_ctx; + turbine::Context &m_tctx; ox::String m_path; TileSheet m_img; TileSheet::SubSheetIdx m_activeSubsSheetIdx; diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp index a42c6cc6..666ce143 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.cpp @@ -11,8 +11,8 @@ namespace nostalgia::core { -TileSheetEditorView::TileSheetEditorView(studio::StudioContext &ctx, ox::StringView path, studio::UndoStack &undoStack): - m_model(ctx, path, undoStack), +TileSheetEditorView::TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack): + m_model(sctx, path, undoStack), m_pixelsDrawer(m_model) { glBindVertexArray(0); // build shaders diff --git a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp index 0e9f8a9e..d421237d 100644 --- a/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp +++ b/src/nostalgia/modules/core/src/studio/tilesheeteditor/tilesheeteditorview.hpp @@ -50,7 +50,7 @@ class TileSheetEditorView: public ox::SignalHandler { std::size_t m_palIdx = 0; public: - TileSheetEditorView(studio::StudioContext &ctx, ox::StringView path, studio::UndoStack &undoStack); + TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack); ~TileSheetEditorView() override = default; diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp index 83dd413d..beef45fb 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.cpp @@ -18,7 +18,7 @@ SceneEditorImGui::SceneEditorImGui(studio::StudioContext &ctx, ox::StringView pa setRequiresConstantRefresh(false); } -void SceneEditorImGui::draw(turbine::Context&) noexcept { +void SceneEditorImGui::draw(studio::StudioContext&) noexcept { auto const paneSize = ImGui::GetContentRegionAvail(); m_view.draw(ox::Size{static_cast(paneSize.x), static_cast(paneSize.y)}); auto &fb = m_view.framebuffer(); diff --git a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp index 0508f424..24bc0b65 100644 --- a/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp +++ b/src/nostalgia/modules/scene/src/studio/sceneeditor-imgui.hpp @@ -23,7 +23,7 @@ class SceneEditorImGui: public studio::Editor { public: SceneEditorImGui(studio::StudioContext &ctx, ox::StringView path); - void draw(turbine::Context&) noexcept final; + void draw(studio::StudioContext&) noexcept final; void onActivated() noexcept override; diff --git a/src/olympic/keel/src/media.cpp b/src/olympic/keel/src/media.cpp index 4bf4b029..03a7e718 100644 --- a/src/olympic/keel/src/media.cpp +++ b/src/olympic/keel/src/media.cpp @@ -134,12 +134,12 @@ ox::Result loadRom(ox::CRStringView) noexcept { // media section constexpr auto headerP2 = "R_______________"; constexpr auto headerP1 = "KEEL_MEDIA_HEADE"; - constexpr auto headerP1Len = ox_strlen(headerP2); - constexpr auto headerP2Len = ox_strlen(headerP1); + constexpr auto headerP1Len = ox::strlen(headerP2); + constexpr auto headerP2Len = ox::strlen(headerP1); constexpr auto headerLen = headerP1Len + headerP2Len; for (auto current = MEM_ROM; current < reinterpret_cast(0x0a000000); current += headerLen) { - if (ox_memcmp(current, headerP1, headerP1Len) == 0 && - ox_memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) { + if (ox::memcmp(current, headerP1, headerP1Len) == 0 && + ox::memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) { return current + headerLen; } } diff --git a/src/olympic/studio/applib/src/aboutpopup.cpp b/src/olympic/studio/applib/src/aboutpopup.cpp index ebd93ddc..6bbd2c7e 100644 --- a/src/olympic/studio/applib/src/aboutpopup.cpp +++ b/src/olympic/studio/applib/src/aboutpopup.cpp @@ -29,7 +29,7 @@ bool AboutPopup::isOpen() const noexcept { return m_stage == Stage::Open; } -void AboutPopup::draw(turbine::Context &ctx) noexcept { +void AboutPopup::draw(studio::StudioContext &sctx) noexcept { switch (m_stage) { case Stage::Closed: break; @@ -41,7 +41,7 @@ void AboutPopup::draw(turbine::Context &ctx) noexcept { constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize; ImGui::SetNextWindowSize(ImVec2(215, 90)); - studio::ig::centerNextWindow(ctx); + studio::ig::centerNextWindow(sctx.tctx); auto open = true; if (ImGui::BeginPopupModal("About", &open, modalFlags)) { ImGui::Text("%s", m_text.c_str()); diff --git a/src/olympic/studio/applib/src/aboutpopup.hpp b/src/olympic/studio/applib/src/aboutpopup.hpp index 155bef66..39e8c407 100644 --- a/src/olympic/studio/applib/src/aboutpopup.hpp +++ b/src/olympic/studio/applib/src/aboutpopup.hpp @@ -35,7 +35,7 @@ class AboutPopup: public studio::Popup { [[nodiscard]] bool isOpen() const noexcept override; - void draw(turbine::Context &ctx) noexcept override; + void draw(studio::StudioContext &sctx) noexcept override; }; diff --git a/src/olympic/studio/applib/src/clawviewer.cpp b/src/olympic/studio/applib/src/clawviewer.cpp index 58df6d6e..861a04b0 100644 --- a/src/olympic/studio/applib/src/clawviewer.cpp +++ b/src/olympic/studio/applib/src/clawviewer.cpp @@ -13,7 +13,7 @@ ClawEditor::ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept: m_obj(std::move(obj)) { } -void ClawEditor::draw(turbine::Context&) noexcept { +void ClawEditor::draw(studio::StudioContext&) noexcept { ImGui::BeginChild("PaletteEditor"); static constexpr auto flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody; if (ImGui::BeginTable("ObjTree", 3, flags)) { diff --git a/src/olympic/studio/applib/src/clawviewer.hpp b/src/olympic/studio/applib/src/clawviewer.hpp index ed6697e9..5441ac30 100644 --- a/src/olympic/studio/applib/src/clawviewer.hpp +++ b/src/olympic/studio/applib/src/clawviewer.hpp @@ -18,7 +18,7 @@ class ClawEditor: public studio::Editor { public: ClawEditor(ox::CRStringView path, ox::ModelObject obj) noexcept; - void draw(turbine::Context&) noexcept final; + void draw(studio::StudioContext&) noexcept final; private: static void drawRow(ox::ModelValue const&value) noexcept; diff --git a/src/olympic/studio/applib/src/newmenu.cpp b/src/olympic/studio/applib/src/newmenu.cpp index e5786cac..7fea9923 100644 --- a/src/olympic/studio/applib/src/newmenu.cpp +++ b/src/olympic/studio/applib/src/newmenu.cpp @@ -33,7 +33,7 @@ bool NewMenu::isOpen() const noexcept { return m_open; } -void NewMenu::draw(turbine::Context &ctx) noexcept { +void NewMenu::draw(studio::StudioContext &sctx) noexcept { switch (m_stage) { case Stage::Opening: ImGui::OpenPopup(title().c_str()); @@ -41,10 +41,10 @@ void NewMenu::draw(turbine::Context &ctx) noexcept { m_open = true; [[fallthrough]]; case Stage::NewItemType: - drawNewItemType(ctx); + drawNewItemType(sctx); break; case Stage::NewItemName: - drawNewItemName(ctx); + drawNewItemName(sctx); break; case Stage::Closed: m_open = false; @@ -61,8 +61,8 @@ void NewMenu::addItemMaker(ox::UniquePtr &&im) noexcept { }); } -void NewMenu::drawNewItemType(turbine::Context &ctx) noexcept { - drawWindow(ctx, &m_open, [this] { +void NewMenu::drawNewItemType(studio::StudioContext &sctx) noexcept { + drawWindow(sctx.tctx, &m_open, [this] { auto items = ox_malloca(m_types.size() * sizeof(char const*), char const*, nullptr); for (auto i = 0u; auto const&im : m_types) { items.get()[i] = im->typeName.c_str(); @@ -73,13 +73,13 @@ void NewMenu::drawNewItemType(turbine::Context &ctx) noexcept { }); } -void NewMenu::drawNewItemName(turbine::Context &ctx) noexcept { - drawWindow(ctx, &m_open, [this, &ctx] { +void NewMenu::drawNewItemName(studio::StudioContext &sctx) noexcept { + drawWindow(sctx.tctx, &m_open, [this, &sctx] { auto const typeIdx = static_cast(m_selectedType); if (typeIdx < m_types.size()) { ImGui::InputText("Name", m_itemName.data(), m_itemName.cap()); } - drawLastPageButtons(ctx); + drawLastPageButtons(sctx); }); } @@ -97,7 +97,7 @@ void NewMenu::drawFirstPageButtons() noexcept { } } -void NewMenu::drawLastPageButtons(turbine::Context &ctx) noexcept { +void NewMenu::drawLastPageButtons(studio::StudioContext &sctx) noexcept { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 138); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); if (ImGui::Button("Back")) { @@ -105,7 +105,7 @@ void NewMenu::drawLastPageButtons(turbine::Context &ctx) noexcept { } ImGui::SameLine(); if (ImGui::Button("Finish")) { - finish(ctx); + finish(sctx); } ImGui::SameLine(); if (ImGui::Button("Quit")) { @@ -114,17 +114,16 @@ void NewMenu::drawLastPageButtons(turbine::Context &ctx) noexcept { } } -void NewMenu::finish(turbine::Context &ctx) noexcept { +void NewMenu::finish(studio::StudioContext &sctx) noexcept { if (m_itemName.len() == 0) { return; } - auto const sctx = turbine::applicationData(ctx); auto const&typeMaker = *m_types[static_cast(m_selectedType)]; - if (sctx->project->exists(typeMaker.itemPath(m_itemName))) { + if (sctx.project->exists(typeMaker.itemPath(m_itemName))) { oxLogError(OxError(1, "New file error: File already exists")); return; } - auto const [path, err] = typeMaker.write(ctx, m_itemName); + auto const [path, err] = typeMaker.write(sctx, m_itemName); if (err) { oxLogError(err); return; diff --git a/src/olympic/studio/applib/src/newmenu.hpp b/src/olympic/studio/applib/src/newmenu.hpp index cf2ef516..2852ddc9 100644 --- a/src/olympic/studio/applib/src/newmenu.hpp +++ b/src/olympic/studio/applib/src/newmenu.hpp @@ -43,7 +43,7 @@ class NewMenu: public studio::Popup { [[nodiscard]] bool isOpen() const noexcept override; - void draw(turbine::Context &ctx) noexcept override; + void draw(studio::StudioContext &sctx) noexcept override; template void addItemType(ox::String name, ox::String parentDir, ox::String fileExt, T itemTempl, ox::ClawFormat pFmt = ox::ClawFormat::Metal) noexcept; @@ -54,15 +54,15 @@ class NewMenu: public studio::Popup { void addItemMaker(ox::UniquePtr &&im) noexcept; private: - void drawNewItemType(turbine::Context &ctx) noexcept; + void drawNewItemType(studio::StudioContext &sctx) noexcept; - void drawNewItemName(turbine::Context &ctx) noexcept; + void drawNewItemName(studio::StudioContext &sctx) noexcept; void drawFirstPageButtons() noexcept; - void drawLastPageButtons(turbine::Context &ctx) noexcept; + void drawLastPageButtons(studio::StudioContext &sctx) noexcept; - void finish(turbine::Context &ctx) noexcept; + void finish(studio::StudioContext &sctx) noexcept; }; diff --git a/src/olympic/studio/applib/src/newproject.cpp b/src/olympic/studio/applib/src/newproject.cpp index 647dd25c..284810ad 100644 --- a/src/olympic/studio/applib/src/newproject.cpp +++ b/src/olympic/studio/applib/src/newproject.cpp @@ -32,7 +32,7 @@ bool NewProject::isOpen() const noexcept { return m_open; } -void NewProject::draw(turbine::Context &ctx) noexcept { +void NewProject::draw(studio::StudioContext &ctx) noexcept { switch (m_stage) { case Stage::Opening: ImGui::OpenPopup(title().c_str()); @@ -48,14 +48,14 @@ void NewProject::draw(turbine::Context &ctx) noexcept { } } -void NewProject::drawNewProjectName(turbine::Context &ctx) noexcept { - drawWindow(ctx, &m_open, [this, &ctx] { +void NewProject::drawNewProjectName(studio::StudioContext &sctx) noexcept { + drawWindow(sctx.tctx, &m_open, [this, &sctx] { ImGui::InputText("Name", m_projectName.data(), m_projectName.cap()); ImGui::Text("Path: %s", m_projectPath.c_str()); if (ImGui::Button("Browse")) { oxLogError(studio::chooseDirectory().moveTo(m_projectPath)); } - drawLastPageButtons(ctx); + drawLastPageButtons(sctx); }); } @@ -73,7 +73,7 @@ void NewProject::drawFirstPageButtons() noexcept { } } -void NewProject::drawLastPageButtons(turbine::Context&) noexcept { +void NewProject::drawLastPageButtons(studio::StudioContext&) noexcept { ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 95); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetContentRegionAvail().y - 20); if (ImGui::Button("Finish")) { diff --git a/src/olympic/studio/applib/src/newproject.hpp b/src/olympic/studio/applib/src/newproject.hpp index bd08776f..6aad38e0 100644 --- a/src/olympic/studio/applib/src/newproject.hpp +++ b/src/olympic/studio/applib/src/newproject.hpp @@ -42,14 +42,14 @@ class NewProject: public studio::Popup { [[nodiscard]] bool isOpen() const noexcept override; - void draw(turbine::Context &ctx) noexcept override; + void draw(studio::StudioContext &ctx) noexcept override; private: - void drawNewProjectName(turbine::Context &ctx) noexcept; + void drawNewProjectName(studio::StudioContext &ctx) noexcept; void drawFirstPageButtons() noexcept; - void drawLastPageButtons(turbine::Context &ctx) noexcept; + void drawLastPageButtons(studio::StudioContext &ctx) noexcept; void finish() noexcept; diff --git a/src/olympic/studio/applib/src/projectexplorer.cpp b/src/olympic/studio/applib/src/projectexplorer.cpp index 3cc779e5..8961c4c0 100644 --- a/src/olympic/studio/applib/src/projectexplorer.cpp +++ b/src/olympic/studio/applib/src/projectexplorer.cpp @@ -37,12 +37,12 @@ static ox::Result> buildProjectTreeModel( ProjectExplorer::ProjectExplorer(turbine::Context &ctx) noexcept: m_ctx(ctx) { } -void ProjectExplorer::draw(turbine::Context &ctx) noexcept { +void ProjectExplorer::draw(studio::StudioContext &ctx) noexcept { auto const viewport = ImGui::GetContentRegionAvail(); ImGui::BeginChild("ProjectExplorer", ImVec2(300, viewport.y), true); ImGui::SetNextItemOpen(true); if (m_treeModel) { - m_treeModel->draw(ctx); + m_treeModel->draw(ctx.tctx); } ImGui::EndChild(); } diff --git a/src/olympic/studio/applib/src/projectexplorer.hpp b/src/olympic/studio/applib/src/projectexplorer.hpp index 50051f69..b7c15a45 100644 --- a/src/olympic/studio/applib/src/projectexplorer.hpp +++ b/src/olympic/studio/applib/src/projectexplorer.hpp @@ -19,7 +19,7 @@ class ProjectExplorer: public studio::Widget { public: explicit ProjectExplorer(turbine::Context &ctx) noexcept; - void draw(turbine::Context &ctx) noexcept override; + void draw(studio::StudioContext &ctx) noexcept override; void setModel(ox::UPtr &&model) noexcept; diff --git a/src/olympic/studio/applib/src/studioapp.cpp b/src/olympic/studio/applib/src/studioapp.cpp index 790e9944..d4b86789 100644 --- a/src/olympic/studio/applib/src/studioapp.cpp +++ b/src/olympic/studio/applib/src/studioapp.cpp @@ -159,15 +159,15 @@ void StudioUI::draw() noexcept { ImGui::Begin("MainWindow##Studio", nullptr, windowFlags); { if (m_showProjectExplorer) { - m_projectExplorer.draw(m_ctx); + m_projectExplorer.draw(m_sctx); ImGui::SameLine(); } drawTabBar(); for (auto &w: m_widgets) { - w->draw(m_ctx); + w->draw(m_sctx); } for (auto p: m_popups) { - p->draw(m_ctx); + p->draw(m_sctx); } } ImGui::End(); @@ -261,7 +261,7 @@ void StudioUI::drawTabs() noexcept { m_activeEditor->onActivated(); turbine::setConstantRefresh(m_ctx, m_activeEditor->requiresConstantRefresh()); } - e->draw(m_ctx); + e->draw(m_sctx); m_activeEditorOnLastDraw = e.get(); ImGui::EndTabItem(); } diff --git a/src/olympic/studio/modlib/include/studio/itemmaker.hpp b/src/olympic/studio/modlib/include/studio/itemmaker.hpp index 2102f3d0..ee095a79 100644 --- a/src/olympic/studio/modlib/include/studio/itemmaker.hpp +++ b/src/olympic/studio/modlib/include/studio/itemmaker.hpp @@ -18,7 +18,10 @@ class ItemMaker { ox::String const typeName; ox::String const parentDir; ox::String const fileExt; - constexpr explicit ItemMaker(ox::StringView pName, ox::StringView pParentDir, ox::CRStringView pFileExt) noexcept: + constexpr explicit ItemMaker( + ox::StringView pName, + ox::StringView pParentDir, + ox::StringView pFileExt) noexcept: typeName(pName), parentDir(pParentDir), fileExt(pFileExt) { @@ -36,7 +39,8 @@ class ItemMaker { * @param pName * @return path of file or error in Result */ - virtual ox::Result write(turbine::Context &ctx, ox::CRStringView pName) const noexcept = 0; + virtual ox::Result write( + studio::StudioContext &ctx, ox::CRStringView pName) const noexcept = 0; }; template @@ -60,7 +64,7 @@ class ItemMakerT: public ItemMaker { T pItem, ox::ClawFormat pFmt) noexcept: ItemMaker(pDisplayName, pParentDir, fileExt), - m_item(pItem), + m_item(std::move(pItem)), m_fmt(pFmt) { } constexpr ItemMakerT( @@ -73,11 +77,10 @@ class ItemMakerT: public ItemMaker { m_item(std::move(pItem)), m_fmt(pFmt) { } - ox::Result write(turbine::Context &ctx, ox::CRStringView pName) const noexcept override { + ox::Result write(studio::StudioContext &sctx, ox::CRStringView pName) const noexcept override { auto const path = itemPath(pName); - auto const sctx = turbine::applicationData(ctx); - keel::createUuidMapping(keelCtx(ctx), path, ox::UUID::generate().unwrap()); - oxReturnError(sctx->project->writeObj(path, m_item, m_fmt)); + keel::createUuidMapping(keelCtx(sctx.tctx), path, ox::UUID::generate().unwrap()); + oxReturnError(sctx.project->writeObj(path, m_item, m_fmt)); return path; } }; diff --git a/src/olympic/studio/modlib/include/studio/popup.hpp b/src/olympic/studio/modlib/include/studio/popup.hpp index d9a7aff9..1fb0891c 100644 --- a/src/olympic/studio/modlib/include/studio/popup.hpp +++ b/src/olympic/studio/modlib/include/studio/popup.hpp @@ -32,7 +32,7 @@ class Popup { [[nodiscard]] virtual bool isOpen() const noexcept = 0; - virtual void draw(turbine::Context &ctx) noexcept = 0; + virtual void draw(studio::StudioContext &ctx) noexcept = 0; protected: constexpr void setSize(ox::Size sz) noexcept { diff --git a/src/olympic/studio/modlib/include/studio/widget.hpp b/src/olympic/studio/modlib/include/studio/widget.hpp index 54365bd1..0b08ddfd 100644 --- a/src/olympic/studio/modlib/include/studio/widget.hpp +++ b/src/olympic/studio/modlib/include/studio/widget.hpp @@ -8,12 +8,14 @@ #include +#include "context.hpp" + namespace studio { class Widget: public ox::SignalHandler { public: ~Widget() noexcept override = default; - virtual void draw(turbine::Context&) noexcept = 0; + virtual void draw(studio::StudioContext&) noexcept = 0; }; } diff --git a/src/olympic/studio/modlib/src/filedialog_nfd.cpp b/src/olympic/studio/modlib/src/filedialog_nfd.cpp index 61de8bef..dfdcd92a 100644 --- a/src/olympic/studio/modlib/src/filedialog_nfd.cpp +++ b/src/olympic/studio/modlib/src/filedialog_nfd.cpp @@ -13,9 +13,9 @@ namespace studio { FDFilterItem::FDFilterItem(ox::CRStringView pName, ox::CRStringView pSpec) noexcept { name.resize(pName.len() + 1); - ox_strncpy(name.data(), pName.data(), pName.len()); + ox::strncpy(name.data(), pName.data(), pName.len()); spec.resize(pSpec.len() + 1); - ox_strncpy(spec.data(), pSpec.data(), pSpec.len()); + ox::strncpy(spec.data(), pSpec.data(), pSpec.len()); } static ox::Result toResult(nfdresult_t r, NFD::UniquePathN const&path) noexcept { diff --git a/src/olympic/turbine/include/turbine/context.hpp b/src/olympic/turbine/include/turbine/context.hpp index 45cc5d0d..2108f082 100644 --- a/src/olympic/turbine/include/turbine/context.hpp +++ b/src/olympic/turbine/include/turbine/context.hpp @@ -37,82 +37,25 @@ inline ox::FileSystem *rom(Context &ctx) noexcept { return keelCtx(ctx).rom.get(); } -struct WrapBase { - virtual ~WrapBase() = default; - virtual WrapBase *copyTo(ox::Span s) noexcept = 0; - virtual operator bool() const noexcept = 0; -}; - -template -struct Wrap: public WrapBase { - T *data{}; - Wrap(T *pData) noexcept: data(pData) { - } - WrapBase *copyTo(ox::Span s) noexcept override { - oxAssert(s.size() >= sizeof(Wrap), "too small buffer"); - return new(s.data()) Wrap{data}; - } - operator bool() const noexcept override { - return data != nullptr; - } -}; - -class WrapPtr { - private: - WrapBase *m_wrapPtr{}; - ox::Array)> m_wrapData; - public: - template - inline WrapPtr &operator=(T *ptr) noexcept { - m_wrapPtr = new(m_wrapData.data()) Wrap(ptr); - return *this; - } - inline WrapPtr &operator=(WrapBase &ptr) noexcept { - if (ptr) { - m_wrapPtr = ptr.copyTo(m_wrapData); - } else { - m_wrapPtr = nullptr; - } - return *this; - } - inline operator bool() const noexcept { - return m_wrapPtr && *m_wrapPtr; - } - [[nodiscard]] - inline WrapBase *getWrapBase() const noexcept { - return m_wrapPtr; - } -}; - -void setApplicationDataRaw(Context &ctx, WrapBase &applicationData) noexcept; +void setApplicationDataRaw(Context &ctx, ox::AnyPtr const&applicationData) noexcept; template void setApplicationData(Context &ctx, T *applicationData) noexcept { - Wrap w(applicationData); - setApplicationDataRaw(ctx, w); + setApplicationDataRaw(ctx, applicationData); } [[nodiscard]] -WrapBase *applicationDataRaw(Context &ctx) noexcept; +ox::AnyPtr const&applicationDataRaw(Context &ctx) noexcept; template [[nodiscard]] T *applicationData(Context &ctx) noexcept { - auto const raw = applicationDataRaw(ctx); - if (!raw) [[unlikely]] { - return nullptr; - } -#ifdef OX_BARE_METAL - auto const out = static_cast*>(raw); -#else - auto const out = dynamic_cast*>(raw); -#endif - oxAssert(out, "Cast failed - wrong type"); - return out->data; + return applicationDataRaw(ctx).get(); } void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept; +[[nodiscard]] KeyEventHandler keyEventHandler(Context &ctx) noexcept; } diff --git a/src/olympic/turbine/src/gba/context.cpp b/src/olympic/turbine/src/gba/context.cpp index 5b5f1330..37a4c710 100644 --- a/src/olympic/turbine/src/gba/context.cpp +++ b/src/olympic/turbine/src/gba/context.cpp @@ -18,12 +18,12 @@ keel::Context &keelCtx(Context &ctx) noexcept { return ctx.keelCtx; } -void setApplicationDataRaw(Context &ctx, WrapBase &applicationData) noexcept { +void setApplicationDataRaw(Context &ctx, ox::AnyPtr const&applicationData) noexcept { ctx.applicationData = applicationData; } -WrapBase *applicationDataRaw(Context &ctx) noexcept { - return ctx.applicationData.getWrapBase(); +ox::AnyPtr const&applicationDataRaw(Context &ctx) noexcept { + return ctx.applicationData; } } diff --git a/src/olympic/turbine/src/gba/context.hpp b/src/olympic/turbine/src/gba/context.hpp index 02b05209..36d0fc10 100644 --- a/src/olympic/turbine/src/gba/context.hpp +++ b/src/olympic/turbine/src/gba/context.hpp @@ -17,7 +17,7 @@ class Context { UpdateHandler updateHandler = [](Context&) -> int {return 0;}; keel::Context keelCtx; KeyEventHandler keyEventHandler = nullptr; - WrapPtr applicationData; + ox::AnyPtr applicationData; // GBA impl data ///////////////////////////////////////////////////////// bool running = true; diff --git a/src/olympic/turbine/src/gba/turbine.cpp b/src/olympic/turbine/src/gba/turbine.cpp index 2d1fe7d6..d67e9d4a 100644 --- a/src/olympic/turbine/src/gba/turbine.cpp +++ b/src/olympic/turbine/src/gba/turbine.cpp @@ -43,8 +43,8 @@ static ox::Result findPreloadSection() noexcept { // media section constexpr auto headerP2 = "DER_____________"; constexpr auto headerP1 = "KEEL_PRELOAD_HEA"; - constexpr auto headerP1Len = ox_strlen(headerP2); - constexpr auto headerP2Len = ox_strlen(headerP1); + constexpr auto headerP1Len = ox::strlen(headerP2); + constexpr auto headerP2Len = ox::strlen(headerP1); constexpr auto headerLen = headerP1Len + headerP2Len; for (auto current = MEM_ROM; current < reinterpret_cast(0x0a000000); current += headerLen) { if (memcmp(current, headerP1, headerP1Len) == 0 && diff --git a/src/olympic/turbine/src/glfw/clipboard.cpp b/src/olympic/turbine/src/glfw/clipboard.cpp index b2efdf1f..e23d3ce7 100644 --- a/src/olympic/turbine/src/glfw/clipboard.cpp +++ b/src/olympic/turbine/src/glfw/clipboard.cpp @@ -18,7 +18,7 @@ ox::String getClipboardText(Context &ctx) noexcept { void setClipboardText(Context &ctx, ox::CRStringView text) noexcept { auto cstr = ox_malloca(text.bytes() + 1, char); - ox_strncpy(cstr.get(), text.data(), text.bytes()); + ox::strncpy(cstr.get(), text.data(), text.bytes()); glfwSetClipboardString(ctx.window, cstr.get()); } diff --git a/src/olympic/turbine/src/glfw/context.cpp b/src/olympic/turbine/src/glfw/context.cpp index 30db3183..ed83f007 100644 --- a/src/olympic/turbine/src/glfw/context.cpp +++ b/src/olympic/turbine/src/glfw/context.cpp @@ -20,12 +20,12 @@ keel::Context &keelCtx(Context &ctx) noexcept { return ctx.keelCtx; } -void setApplicationDataRaw(Context &ctx, WrapBase &applicationData) noexcept { +void setApplicationDataRaw(Context &ctx, ox::AnyPtr const&applicationData) noexcept { ctx.applicationData = applicationData; } -WrapBase *applicationDataRaw(Context &ctx) noexcept { - return ctx.applicationData.getWrapBase(); +ox::AnyPtr const&applicationDataRaw(Context &ctx) noexcept { + return ctx.applicationData; } } diff --git a/src/olympic/turbine/src/glfw/context.hpp b/src/olympic/turbine/src/glfw/context.hpp index 21d420ec..6a08a7db 100644 --- a/src/olympic/turbine/src/glfw/context.hpp +++ b/src/olympic/turbine/src/glfw/context.hpp @@ -16,7 +16,7 @@ class Context { UpdateHandler updateHandler = [](Context&) -> int {return 0;}; keel::Context keelCtx; KeyEventHandler keyEventHandler = nullptr; - WrapPtr applicationData; + ox::AnyPtr applicationData; // GLFW impl data //////////////////////////////////////////////////////// int uninterruptedRefreshes = 3; diff --git a/src/olympic/turbine/src/glfw/gfx.cpp b/src/olympic/turbine/src/glfw/gfx.cpp index b4d7b0ae..c6e531f6 100644 --- a/src/olympic/turbine/src/glfw/gfx.cpp +++ b/src/olympic/turbine/src/glfw/gfx.cpp @@ -221,7 +221,7 @@ ox::Error initGfx(Context &ctx) noexcept { void setWindowTitle(Context &ctx, ox::CRStringView title) noexcept { auto cstr = ox_malloca(title.bytes() + 1, char); - ox_strncpy(cstr.get(), title.data(), title.bytes()); + ox::strncpy(cstr.get(), title.data(), title.bytes()); glfwSetWindowTitle(ctx.window, cstr.get()); }