Merge commit 'c0baf7efca0e4c3a86a018ad2564d9df7b07c133'
All checks were successful
Build / build (push) Successful in 2m22s
All checks were successful
Build / build (push) Successful in 2m22s
This commit is contained in:
commit
d7f309750e
2
deps/ox/src/ox/clargs/clargs.cpp
vendored
2
deps/ox/src/ox/clargs/clargs.cpp
vendored
@ -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;
|
||||
|
10
deps/ox/src/ox/claw/read.cpp
vendored
10
deps/ox/src/ox/claw/read.cpp
vendored
@ -13,7 +13,7 @@
|
||||
namespace ox {
|
||||
|
||||
Result<ClawHeader> 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<ClawHeader> 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<ClawHeader> 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<ClawHeader> 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<ClawHeader> readClawHeader(const ox::Buffer &buff) noexcept {
|
||||
Result<Buffer> 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;
|
||||
}
|
||||
|
||||
|
2
deps/ox/src/ox/claw/write.hpp
vendored
2
deps/ox/src/ox/claw/write.hpp
vendored
@ -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 {};
|
||||
|
@ -279,7 +279,7 @@ Error FileStoreTemplate<size_t>::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<size_t>::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<size_t>::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<size_t>::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();
|
||||
}
|
||||
|
2
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
2
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
@ -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<InodeId_t>(MaxFileNameLength)));
|
||||
ox::strncpy(d->name, name, ox::min(bufferSize, static_cast<InodeId_t>(MaxFileNameLength)));
|
||||
return OxError(0);
|
||||
}
|
||||
return OxError(1);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
48
deps/ox/src/ox/fs/filesystem/pathiterator.cpp
vendored
48
deps/ox/src/ox/fs/filesystem/pathiterator.cpp
vendored
@ -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<std::size_t>(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<size_t>(ox_strlen(&m_path[idx]));
|
||||
std::size_t fileNameSize = static_cast<size_t>(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<size_t>(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<size_t>(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<std::size_t> 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<std::size_t>(substr - m_path);
|
||||
size = end - start;
|
||||
@ -168,16 +168,16 @@ Result<std::size_t> 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<std::size_t>(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<std::size_t>(substr - m_path);
|
||||
size = end - start;
|
||||
|
12
deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp
vendored
12
deps/ox/src/ox/fs/ptrarith/nodebuffer.hpp
vendored
@ -173,15 +173,15 @@ class OX_PACKED NodeBuffer {
|
||||
template<typename size_t, typename Item>
|
||||
NodeBuffer<size_t, Item>::NodeBuffer(std::size_t size) noexcept {
|
||||
m_header.size = static_cast<size_t>(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<typename size_t, typename Item>
|
||||
NodeBuffer<size_t, Item>::NodeBuffer(const NodeBuffer &other, std::size_t size) noexcept {
|
||||
oxTracef("ox.ptrarith.NodeBuffer.copy", "other.m_header.firstItem: {}", other.m_header.firstItem.get());
|
||||
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<typename size_t, typename Item>
|
||||
@ -291,7 +291,7 @@ Result<typename NodeBuffer<size_t, Item>::ItemPtr> NodeBuffer<size_t, Item>::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<size_t, Item>::setSize(std::size_t size) noexcept {
|
||||
} else {
|
||||
m_header.size = static_cast<size_t>(size);
|
||||
auto data = reinterpret_cast<uint8_t*>(this) + end;
|
||||
ox_memset(data, 0, size - end);
|
||||
ox::memset(data, 0, size - end);
|
||||
return OxError(0);
|
||||
}
|
||||
}
|
||||
@ -405,7 +405,7 @@ Error NodeBuffer<size_t, Item>::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);
|
||||
|
32
deps/ox/src/ox/fs/test/tests.cpp
vendored
32
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -61,9 +61,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto const path = ox::String("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||
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<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto const path = ox::String("/usr/share/");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||
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<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto const path = ox::String("/");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "\0") == 0, "PathIterator shows wrong next");
|
||||
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<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto const path = ox::String("usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||
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<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto const path = ox::String("usr/share/");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.next(buff, path.len()) == 0 && ox_strcmp(buff, "usr") == 0, "PathIterator shows wrong next");
|
||||
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<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto const path = ox::String("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.dirPath(buff, path.len()) == 0 && ox_strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
|
||||
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<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
|
||||
auto const path = ox::String("/usr/share/charset.gbag");
|
||||
ox::PathIterator it(path.c_str(), path.len());
|
||||
auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
|
||||
oxAssert(it.fileName(buff, path.len()) == 0 && ox_strcmp(buff, "charset.gbag") == 0, "PathIterator shows incorrect file name");
|
||||
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<ox::StringView, std::function<ox::Error(ox::StringView)>> 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<ox::StringView, std::function<ox::Error(ox::StringView)>> 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<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
|
||||
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
|
||||
ox::FileStore32 fileStore(list, buffLen);
|
||||
|
10
deps/ox/src/ox/logconn/circularbuff.hpp
vendored
10
deps/ox/src/ox/logconn/circularbuff.hpp
vendored
@ -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;
|
||||
}
|
||||
|
10
deps/ox/src/ox/mc/intops.hpp
vendored
10
deps/ox/src/ox/mc/intops.hpp
vendored
@ -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<uint64_t>(leVal.raw() | (negBit << (valBits - 1))) << bytes |
|
||||
static_cast<uint64_t>(bytesIndicator);
|
||||
ox_memcpy(out.data, &intermediate, sizeof(intermediate));
|
||||
ox::memcpy(out.data, &intermediate, sizeof(intermediate));
|
||||
}
|
||||
out.length = bytes;
|
||||
}
|
||||
@ -160,7 +160,7 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
|
||||
ox::Array<uint32_t, 2> 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<std::size_t>(Bits<I>, 32); ++bit) {
|
||||
d[0] |= 1 << bit;
|
||||
@ -175,7 +175,7 @@ constexpr Result<I> 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;
|
||||
}
|
||||
}
|
||||
|
2
deps/ox/src/ox/mc/write.hpp
vendored
2
deps/ox/src/ox/mc/write.hpp
vendored
@ -214,7 +214,7 @@ template<Writer_c Writer>
|
||||
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t) noexcept {
|
||||
bool fieldSet = false;
|
||||
if (!m_unionIdx.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<const char*>(strLenBuff.data), strLenBuff.length));
|
||||
|
12
deps/ox/src/ox/model/modelvalue.hpp
vendored
12
deps/ox/src/ox/model/modelvalue.hpp
vendored
@ -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<String>());
|
||||
@ -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<String>());
|
||||
@ -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;
|
||||
|
12
deps/ox/src/ox/oc/read.cpp
vendored
12
deps/ox/src/ox/oc/read.cpp
vendored
@ -15,7 +15,7 @@ namespace ox {
|
||||
|
||||
OrganicClawReader::OrganicClawReader(const uint8_t *buff, std::size_t buffSize) {
|
||||
auto json = reinterpret_cast<const char*>(buff);
|
||||
auto jsonLen = ox_strnlen(json, buffSize);
|
||||
auto jsonLen = ox::strnlen(json, buffSize);
|
||||
Json::CharReaderBuilder parserBuilder;
|
||||
auto parser = std::unique_ptr<Json::CharReader>(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<std::size_t>(strSize));
|
||||
ox::memcpy(data, begin, static_cast<std::size_t>(strSize));
|
||||
data[strSize] = 0;
|
||||
}
|
||||
} else {
|
||||
@ -224,7 +224,7 @@ Error OrganicClawReader::fieldCString(const char *key, char **val) noexcept {
|
||||
const auto strSize = static_cast<std::size_t>(end - begin);
|
||||
safeDelete(*val);
|
||||
*val = new char[strSize + 1];
|
||||
ox_memcpy(data, begin, static_cast<std::size_t>(strSize));
|
||||
ox::memcpy(data, begin, static_cast<std::size_t>(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<std::size_t>(strSize));
|
||||
data[strSize] = 0;
|
||||
ox::memcpy(data, begin, static_cast<std::size_t>(strSize));
|
||||
data[strSize] = nullptr;
|
||||
} else {
|
||||
err = OxError(1, "Type mismatch");
|
||||
}
|
||||
|
2
deps/ox/src/ox/oc/read.hpp
vendored
2
deps/ox/src/ox/oc/read.hpp
vendored
@ -274,7 +274,7 @@ Result<T> readOC(const char *json, std::size_t jsonLen) noexcept {
|
||||
|
||||
template<typename T>
|
||||
Result<T> readOC(const char *json) noexcept {
|
||||
return readOC<T>(json, ox_strlen(json));
|
||||
return readOC<T>(json, ox::strlen(json));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
2
deps/ox/src/ox/oc/write.cpp
vendored
2
deps/ox/src/ox/oc/write.cpp
vendored
@ -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<const char**>(val), static_cast<int>(ox_strlen(val)));
|
||||
return fieldCString(key, const_cast<const char**>(val), static_cast<int>(ox::strlen(val)));
|
||||
}
|
||||
|
||||
Error OrganicClawWriter::field(const char *key, const UUID *uuid) noexcept {
|
||||
|
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
@ -106,6 +106,7 @@ install(
|
||||
ignore.hpp
|
||||
iterator.hpp
|
||||
math.hpp
|
||||
maybeview.hpp
|
||||
memops.hpp
|
||||
memory.hpp
|
||||
new.hpp
|
||||
|
102
deps/ox/src/ox/std/anyptr.hpp
vendored
Normal file
102
deps/ox/src/ox/std/anyptr.hpp
vendored
Normal file
@ -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<char> s) noexcept = 0;
|
||||
virtual constexpr operator bool() const noexcept = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Wrap: public WrapBase {
|
||||
T *data{};
|
||||
constexpr Wrap(T *pData) noexcept: data(pData) {
|
||||
}
|
||||
constexpr WrapBase *copyTo(ox::Span<char> 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<char, sizeof(Wrap<void*>)> m_wrapData;
|
||||
|
||||
public:
|
||||
constexpr AnyPtr() noexcept = default;
|
||||
|
||||
template<typename T>
|
||||
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<typename T>
|
||||
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<typename T>
|
||||
[[nodiscard]]
|
||||
constexpr T *get() const noexcept {
|
||||
#ifdef OX_BARE_METAL
|
||||
return static_cast<Wrap<T>*>(m_wrapPtr)->data;
|
||||
#else
|
||||
return dynamic_cast<Wrap<T>*>(m_wrapPtr)->data;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
}
|
1
deps/ox/src/ox/std/array.hpp
vendored
1
deps/ox/src/ox/std/array.hpp
vendored
@ -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"
|
||||
|
2
deps/ox/src/ox/std/basestringview.hpp
vendored
2
deps/ox/src/ox/std/basestringview.hpp
vendored
@ -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) {}
|
||||
|
||||
|
2
deps/ox/src/ox/std/bit.hpp
vendored
2
deps/ox/src/ox/std/bit.hpp
vendored
@ -34,7 +34,7 @@ namespace ox {
|
||||
template<typename To, typename From>
|
||||
constexpr typename enable_if<sizeof(To) == sizeof(From), To>::type cbit_cast(From src) noexcept {
|
||||
To dst = {};
|
||||
ox_memcpy(&dst, &src, sizeof(src));
|
||||
ox::memcpy(&dst, &src, sizeof(src));
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
18
deps/ox/src/ox/std/bstring.hpp
vendored
18
deps/ox/src/ox/std/bstring.hpp
vendored
@ -109,7 +109,7 @@ constexpr BString<size>::BString(const char *str) noexcept: m_buff{{0}} {
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> &BString<size>::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<size> &BString<size>::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<size> &BString<size>::operator=(ox::CRStringView str) noexcept
|
||||
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> &BString<size>::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<size> &BString<size>::operator=(char *str) noexcept {
|
||||
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> &BString<size>::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<size> &BString<size>::operator+=(char *str) noexcept {
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> &BString<size>::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<size> &BString<size>::operator+=(StringView s) noexcept {
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> BString<size>::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<size> BString<size>::operator+(char *str) const noexcept {
|
||||
template<std::size_t size>
|
||||
constexpr BString<size> BString<size>::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<buffLen>::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;
|
||||
|
2
deps/ox/src/ox/std/buffer.hpp
vendored
2
deps/ox/src/ox/std/buffer.hpp
vendored
@ -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;
|
||||
}
|
||||
|
22
deps/ox/src/ox/std/cstrops.hpp
vendored
22
deps/ox/src/ox/std/cstrops.hpp
vendored
@ -11,8 +11,10 @@
|
||||
#include "types.hpp"
|
||||
#include "typetraits.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
template<typename T1, typename T2>
|
||||
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<decltype(dest[0])>::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<typename T>
|
||||
[[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<typename T1, typename T2>
|
||||
[[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<typename T1, typename T2>
|
||||
[[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<typename Integer, typename T>
|
||||
constexpr T ox_itoa(Integer v, T str) noexcept {
|
||||
constexpr T itoa(Integer v, T str) noexcept {
|
||||
if (v) {
|
||||
ox::ResizedInt_t<Integer, 64> mod = 1000000000000000000;
|
||||
ox::ResizedInt_t<Integer, 64> val = v;
|
||||
@ -143,3 +145,5 @@ constexpr T ox_itoa(Integer v, T str) noexcept {
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
|
6
deps/ox/src/ox/std/fmt.hpp
vendored
6
deps/ox/src/ox/std/fmt.hpp
vendored
@ -81,7 +81,7 @@ class FmtArg {
|
||||
if constexpr(is_bool_v<T>) {
|
||||
return v ? "true" : "false";
|
||||
} else if constexpr(is_integer_v<T>) {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
22
deps/ox/src/ox/std/hashmap.hpp
vendored
22
deps/ox/src/ox/std/hashmap.hpp
vendored
@ -45,16 +45,16 @@ class HashMap {
|
||||
|
||||
constexpr HashMap &operator=(HashMap &&other) noexcept;
|
||||
|
||||
constexpr T &operator[](MaybeSV_t<K> const&key);
|
||||
constexpr T &operator[](MaybeView_t<K> const&key);
|
||||
|
||||
constexpr Result<T*> at(MaybeSV_t<K> const&key) noexcept;
|
||||
constexpr Result<T*> at(MaybeView_t<K> const&key) noexcept;
|
||||
|
||||
constexpr Result<const T*> at(MaybeSV_t<K> const&key) const noexcept;
|
||||
constexpr Result<const T*> at(MaybeView_t<K> const&key) const noexcept;
|
||||
|
||||
constexpr void erase(MaybeSV_t<K> const&key);
|
||||
constexpr void erase(MaybeView_t<K> const&key);
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool contains(MaybeSV_t<K> const&key) const noexcept;
|
||||
constexpr bool contains(MaybeView_t<K> const&key) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t size() const noexcept;
|
||||
@ -134,7 +134,7 @@ constexpr HashMap<K, T> &HashMap<K, T>::operator=(HashMap<K, T> &&other) noexcep
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr T &HashMap<K, T>::operator[](MaybeSV_t<K> const&k) {
|
||||
constexpr T &HashMap<K, T>::operator[](MaybeView_t<K> const&k) {
|
||||
auto &p = access(m_pairs, k);
|
||||
if (p == nullptr) {
|
||||
if (static_cast<double>(m_pairs.size()) * 0.7 <
|
||||
@ -149,7 +149,7 @@ constexpr T &HashMap<K, T>::operator[](MaybeSV_t<K> const&k) {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr Result<T*> HashMap<K, T>::at(MaybeSV_t<K> const&k) noexcept {
|
||||
constexpr Result<T*> HashMap<K, T>::at(MaybeView_t<K> 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<T*> HashMap<K, T>::at(MaybeSV_t<K> const&k) noexcept {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr Result<const T*> HashMap<K, T>::at(MaybeSV_t<K> const&k) const noexcept {
|
||||
constexpr Result<const T*> HashMap<K, T>::at(MaybeView_t<K> 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<const T*> HashMap<K, T>::at(MaybeSV_t<K> const&k) const noexcep
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr void HashMap<K, T>::erase(MaybeSV_t<K> const&k) {
|
||||
constexpr void HashMap<K, T>::erase(MaybeView_t<K> const&k) {
|
||||
if (!contains(k)) {
|
||||
return;
|
||||
}
|
||||
@ -185,7 +185,7 @@ constexpr void HashMap<K, T>::erase(MaybeSV_t<K> const&k) {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr bool HashMap<K, T>::contains(MaybeSV_t<K> const&k) const noexcept {
|
||||
constexpr bool HashMap<K, T>::contains(MaybeView_t<K> const&k) const noexcept {
|
||||
return access(m_pairs, k) != nullptr;
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ template<typename K, typename T>
|
||||
constexpr void HashMap<K, T>::expand() {
|
||||
Vector<Pair*> r;
|
||||
for (std::size_t i = 0; i < m_keys.size(); ++i) {
|
||||
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);
|
||||
|
26
deps/ox/src/ox/std/maybeview.hpp
vendored
Normal file
26
deps/ox/src/ox/std/maybeview.hpp
vendored
Normal file
@ -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<typename T, bool isStr = isOxString_v<T>>
|
||||
struct MaybeView {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using MaybeView_t = typename MaybeView<T>::type;
|
||||
|
||||
}
|
53
deps/ox/src/ox/std/memops.cpp
vendored
53
deps/ox/src/ox/std/memops.cpp
vendored
@ -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<const char*>(src);
|
||||
auto dstBuf = static_cast<char*>(dest);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
dstBuf[i] = static_cast<char>(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<uint8_t*>(ptr);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
buf[i] = static_cast<uint8_t>(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<const char*>(src);
|
||||
auto dstBuf = static_cast<char*>(dest);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
dstBuf[i] = static_cast<char>(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);
|
||||
}
|
||||
|
||||
}
|
||||
|
68
deps/ox/src/ox/std/memops.hpp
vendored
68
deps/ox/src/ox/std/memops.hpp
vendored
@ -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<const char*>(src);
|
||||
auto dstBuf = static_cast<char*>(dest);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
dstBuf[i] = static_cast<char>(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<const char *>(src);
|
||||
auto dstBuf = static_cast<char *>(dest);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
dstBuf[i] = static_cast<char>(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<uint8_t*>(ptr);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
buf[i] = static_cast<uint8_t>(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<typename T1, typename T2>
|
||||
constexpr T1 *listcpy(T1 *dest, T2 *src, std::size_t maxLen) noexcept {
|
||||
using T1Type = typename ox::remove_reference<decltype(dest[0])>::type;
|
||||
std::size_t i = 0;
|
||||
while (i < maxLen && src[i]) {
|
||||
dest[i] = static_cast<T1Type>(src[i]);
|
||||
++i;
|
||||
}
|
||||
// set null terminator
|
||||
dest[i] = 0;
|
||||
return dest;
|
||||
}
|
||||
|
||||
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<typename T>
|
||||
void *memsetElements(T *ptr, T val, std::size_t elements) noexcept {
|
||||
|
1
deps/ox/src/ox/std/span.hpp
vendored
1
deps/ox/src/ox/std/span.hpp
vendored
@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "array.hpp"
|
||||
#include "bit.hpp"
|
||||
#include "iterator.hpp"
|
||||
#include "vector.hpp"
|
||||
|
2
deps/ox/src/ox/std/std.hpp
vendored
2
deps/ox/src/ox/std/std.hpp
vendored
@ -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"
|
||||
|
53
deps/ox/src/ox/std/string.hpp
vendored
53
deps/ox/src/ox/std/string.hpp
vendored
@ -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<size_t Sz>
|
||||
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<SmallStringSize_v>::BasicString(const char8_t *str) noexce
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::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<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(StringLiteral const&str) noexcept:
|
||||
BasicString(StringView{str.data(), str.bytes()}) {
|
||||
}
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v>::BasicString(CRStringView str) noexcept {
|
||||
if (m_buff.empty()) {
|
||||
@ -315,7 +326,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(int64_t i) noexcept {
|
||||
ox::Array<char, 65> str{};
|
||||
ox_itoa(i, str.data());
|
||||
ox::itoa(i, str.data());
|
||||
set(str.data());
|
||||
return *this;
|
||||
}
|
||||
@ -323,7 +334,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(uint64_t i) noexcept {
|
||||
ox::Array<char, 65> str{};
|
||||
ox_itoa(i, str.data());
|
||||
ox::itoa(i, str.data());
|
||||
set(str.data());
|
||||
return *this;
|
||||
}
|
||||
@ -352,7 +363,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::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<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::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<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::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<SmallStringSize_v> 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<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::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<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
const auto currentLen = len();
|
||||
BasicString<SmallStringSize_v> 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<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
|
||||
const auto currentLen = len();
|
||||
BasicString<SmallStringSize_v> 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<SmallStringSize_v>::operator!=(OxString_c auto const&
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::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<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::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<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::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<std::size_t SmallStringSize_v>
|
||||
constexpr bool BasicString<SmallStringSize_v>::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<std::size_t SmallStringSize_v>
|
||||
@ -509,7 +520,7 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::substr(
|
||||
const auto size = end - begin;
|
||||
BasicString<SmallStringSize_v> 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<SmallStringSize_v>::set(CRStringView str) noexcept {
|
||||
|
||||
template<std::size_t SmallStringSize_v>
|
||||
constexpr void BasicString<SmallStringSize_v>::set(const char8_t *str) noexcept {
|
||||
std::size_t strBytes = ox_strlen(str) + 1;
|
||||
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;
|
||||
}
|
||||
|
||||
|
22
deps/ox/src/ox/std/stringview.hpp
vendored
22
deps/ox/src/ox/std/stringview.hpp
vendored
@ -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<typename T, bool isStr = isOxString_v<T>>
|
||||
struct MaybeSV {
|
||||
using type = T;
|
||||
};
|
||||
template<typename T>
|
||||
struct MaybeSV<T, true> {
|
||||
struct MaybeView<T, true> {
|
||||
using type = ox::StringView;
|
||||
};
|
||||
template<typename T>
|
||||
using MaybeSV_t = typename MaybeSV<T>::type;
|
||||
|
||||
|
||||
}
|
||||
|
||||
constexpr ox::Result<int> ox_atoi(ox::CRStringView str) noexcept {
|
||||
constexpr ox::Result<int> atoi(ox::CRStringView str) noexcept {
|
||||
int total = 0;
|
||||
int multiplier = 1;
|
||||
for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) {
|
||||
@ -129,3 +118,6 @@ constexpr ox::Result<int> ox_atoi(ox::CRStringView str) noexcept {
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
24
deps/ox/src/ox/std/strops.cpp
vendored
24
deps/ox/src/ox/std/strops.cpp
vendored
@ -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<char*>(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<char*>(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
|
||||
|
||||
|
6
deps/ox/src/ox/std/strops.hpp
vendored
6
deps/ox/src/ox/std/strops.hpp
vendored
@ -37,7 +37,7 @@ constexpr ox::StringView substr(Str const&str, std::size_t start, std::size_t en
|
||||
}
|
||||
|
||||
template<typename Integer>
|
||||
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<Integer, 64> mod = 1000000000000000000;
|
||||
ox::ResizedInt_t<Integer, 64> 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]]
|
||||
|
14
deps/ox/src/ox/std/test/tests.cpp
vendored
14
deps/ox/src/ox/std/test/tests.cpp
vendored
@ -30,13 +30,13 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
[]() {
|
||||
ox::Array<char, 10> 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<ox::StringView, ox::Error(*)()> 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);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
20
deps/ox/src/ox/std/tracehook.cpp
vendored
20
deps/ox/src/ox/std/tracehook.cpp
vendored
@ -42,7 +42,7 @@ enum LogChan {
|
||||
template<LogChan chan>
|
||||
static void log(ox::CRStringView str) {
|
||||
const auto sz = ox::min<std::size_t>(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
|
||||
|
16
deps/ox/src/ox/std/vector.hpp
vendored
16
deps/ox/src/ox/std/vector.hpp
vendored
@ -269,12 +269,12 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool contains(MaybeSV_t<T> const&) const noexcept(useNoexcept);
|
||||
constexpr bool contains(MaybeView_t<T> const&) const noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(
|
||||
std::size_t pos, std::size_t cnt, MaybeSV_t<T> const&val) noexcept(useNoexcept);
|
||||
std::size_t pos, std::size_t cnt, MaybeView_t<T> const&val) noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, MaybeSV_t<T> const&val) noexcept(useNoexcept);
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, MaybeView_t<T> const&val) noexcept(useNoexcept);
|
||||
|
||||
template<typename... Args>
|
||||
constexpr iterator<T&, T*, false> emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept);
|
||||
@ -284,7 +284,7 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
|
||||
constexpr void push_back(T &&item) noexcept(useNoexcept);
|
||||
|
||||
constexpr void push_back(MaybeSV_t<T> const&item) noexcept(useNoexcept);
|
||||
constexpr void push_back(MaybeView_t<T> const&item) noexcept(useNoexcept);
|
||||
|
||||
constexpr void pop_back() noexcept(useNoexcept);
|
||||
|
||||
@ -522,7 +522,7 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::resize(std::size_t size) n
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeSV_t<T> const&v) const noexcept(useNoexcept) {
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeView_t<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<T, SmallVectorSize, Allocator>::contains(MaybeSV_t<T> cons
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
std::size_t pos, std::size_t cnt, MaybeSV_t<T> const&val) noexcept(useNoexcept) {
|
||||
std::size_t pos, std::size_t cnt, MaybeView_t<T> const&val) noexcept(useNoexcept) {
|
||||
if (m_size + cnt > m_cap) {
|
||||
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
|
||||
if (pos < m_size) {
|
||||
@ -562,7 +562,7 @@ Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, MaybeSV_t<T> const&val) noexcept(useNoexcept) {
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, MaybeView_t<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<T, SmallVectorSize, Allocator>::push_back(T &&item) noexce
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(MaybeSV_t<T> const&item) noexcept(useNoexcept) {
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(MaybeView_t<T> const&item) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserve(m_cap ? m_cap * 2 : initialCap);
|
||||
}
|
||||
|
@ -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<Palette>(keelCtx(m_ctx), ox::FileAddress(itemPath())).unwrapThrow()) {
|
||||
m_sctx(sctx),
|
||||
m_tctx(sctx.tctx),
|
||||
m_pal(*keel::readObj<Palette>(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<std::size_t>(
|
||||
static_cast<uint32_t>(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<std::size_t>(
|
||||
static_cast<uint32_t>(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<studio::StudioContext>(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<char, 10> numStr;
|
||||
ox_itoa(i, numStr.data());
|
||||
ox::itoa(i, numStr.data());
|
||||
drawColumn(numStr.data());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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<char, 10> 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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<TileSheet>(keelCtx(m_ctx), m_path).unwrapThrow()),
|
||||
m_img(*readObj<TileSheet>(keelCtx(m_tctx), m_path).unwrapThrow()),
|
||||
// ignore failure to load palette
|
||||
m_pal(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).value),
|
||||
m_pal(readObj<Palette>(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<CutPasteCommand>(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<TileSheetClipboard>(m_ctx);
|
||||
auto [cb, err] = turbine::getClipboardObject<TileSheetClipboard>(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<PaletteChangeCommand>(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<CommandId>(cmdId) == CommandId::PaletteChange) {
|
||||
oxReturnError(readObj<Palette>(keelCtx(m_ctx), m_img.defaultPalette).moveTo(m_pal));
|
||||
oxReturnError(readObj<Palette>(keelCtx(m_tctx), m_img.defaultPalette).moveTo(m_pal));
|
||||
m_palettePage = ox::min<size_t>(m_pal->pages.size(), 0);
|
||||
paletteChanged.emit();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<int>(paneSize.x), static_cast<int>(paneSize.y)});
|
||||
auto &fb = m_view.framebuffer();
|
||||
|
@ -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;
|
||||
|
||||
|
@ -134,12 +134,12 @@ ox::Result<char*> 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<char*>(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;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -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<studio::ItemMaker> &&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<std::size_t>(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<studio::StudioContext>(ctx);
|
||||
auto const&typeMaker = *m_types[static_cast<std::size_t>(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;
|
||||
|
@ -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<typename T>
|
||||
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<studio::ItemMaker> &&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;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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")) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -37,12 +37,12 @@ static ox::Result<ox::UniquePtr<ProjectTreeModel>> 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();
|
||||
}
|
||||
|
@ -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<ProjectTreeModel> &&model) noexcept;
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<ox::String> write(turbine::Context &ctx, ox::CRStringView pName) const noexcept = 0;
|
||||
virtual ox::Result<ox::String> write(
|
||||
studio::StudioContext &ctx, ox::CRStringView pName) const noexcept = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -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<ox::String> write(turbine::Context &ctx, ox::CRStringView pName) const noexcept override {
|
||||
ox::Result<ox::String> write(studio::StudioContext &sctx, ox::CRStringView pName) const noexcept override {
|
||||
auto const path = itemPath(pName);
|
||||
auto const sctx = turbine::applicationData<studio::StudioContext>(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;
|
||||
}
|
||||
};
|
||||
|
@ -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 {
|
||||
|
@ -8,12 +8,14 @@
|
||||
|
||||
#include <turbine/context.hpp>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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<ox::String> toResult(nfdresult_t r, NFD::UniquePathN const&path) noexcept {
|
||||
|
@ -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<char> s) noexcept = 0;
|
||||
virtual operator bool() const noexcept = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Wrap: public WrapBase {
|
||||
T *data{};
|
||||
Wrap(T *pData) noexcept: data(pData) {
|
||||
}
|
||||
WrapBase *copyTo(ox::Span<char> 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<char, sizeof(Wrap<void*>)> m_wrapData;
|
||||
public:
|
||||
template<typename T>
|
||||
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<typename T>
|
||||
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<typename T>
|
||||
[[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<Wrap<T>*>(raw);
|
||||
#else
|
||||
auto const out = dynamic_cast<Wrap<T>*>(raw);
|
||||
#endif
|
||||
oxAssert(out, "Cast failed - wrong type");
|
||||
return out->data;
|
||||
return applicationDataRaw(ctx).get<T>();
|
||||
}
|
||||
|
||||
void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
KeyEventHandler keyEventHandler(Context &ctx) noexcept;
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -43,8 +43,8 @@ static ox::Result<std::size_t> 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<char*>(0x0a000000); current += headerLen) {
|
||||
if (memcmp(current, headerP1, headerP1Len) == 0 &&
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user