Compare commits
18 Commits
5e1698a321
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 110d4a2e6a | |||
| e29a50d0dc | |||
| 93d16cafb2 | |||
| 54d7c706eb | |||
| c9cb186462 | |||
| f204d01a3d | |||
| 62337bd29e | |||
| 7b24b33849 | |||
| 86c2c26d8d | |||
| f8b2700ea7 | |||
| 7848cbbbff | |||
| 96c5223e44 | |||
| d19b848427 | |||
| c812051ec0 | |||
| 3c07eb2df7 | |||
| ca851e1059 | |||
| 11e75cb6ca | |||
| 8c4add57e4 |
6
deps/ox/src/ox/claw/read.cpp
vendored
6
deps/ox/src/ox/claw/read.cpp
vendored
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept {
|
||||
Result<StringView> readClawTypeId(BufferView const buff) noexcept {
|
||||
auto buffRaw = buff.data();
|
||||
auto buffLen = buff.size();
|
||||
size_t outSz{};
|
||||
@@ -43,7 +43,7 @@ ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept {
|
||||
return {{buff.data() + fmtSz, outSz - fmtSz - 1}};
|
||||
}
|
||||
|
||||
Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
|
||||
Result<ClawHeader> readClawHeader(BufferView const buff) noexcept {
|
||||
auto buffRaw = buff.data();
|
||||
auto buffLen = buff.size();
|
||||
const auto s1End = ox::strchr(buffRaw, ';', buffLen);
|
||||
@@ -87,7 +87,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
|
||||
return hdr;
|
||||
}
|
||||
|
||||
Result<BufferView> stripClawHeader(ox::BufferView buff) noexcept {
|
||||
Result<BufferView> stripClawHeader(BufferView const buff) noexcept {
|
||||
OX_REQUIRE(header, readClawHeader(buff));
|
||||
return {{header.data, header.dataSize}};
|
||||
}
|
||||
|
||||
4
deps/ox/src/ox/event/signal.hpp
vendored
4
deps/ox/src/ox/event/signal.hpp
vendored
@@ -122,7 +122,7 @@ class Signal {
|
||||
}
|
||||
};
|
||||
|
||||
mutable Vector<UniquePtr<BaseSlot>> m_slots;
|
||||
mutable Vector<UPtr<BaseSlot>> m_slots;
|
||||
|
||||
public:
|
||||
~Signal() noexcept;
|
||||
@@ -303,7 +303,7 @@ class Signal<Error(Args...)> {
|
||||
}
|
||||
};
|
||||
|
||||
mutable Vector<UniquePtr<BaseSlot>> m_slots;
|
||||
mutable Vector<UPtr<BaseSlot>> m_slots;
|
||||
|
||||
public:
|
||||
~Signal() noexcept;
|
||||
|
||||
2
deps/ox/src/ox/fs/tool.cpp
vendored
2
deps/ox/src/ox/fs/tool.cpp
vendored
@@ -34,7 +34,7 @@ static ox::Result<Buff> loadFsBuff(const char *path) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
static ox::Result<ox::UniquePtr<ox::FileSystem>> loadFs(const char *path) noexcept {
|
||||
static ox::Result<ox::UPtr<ox::FileSystem>> loadFs(const char *path) noexcept {
|
||||
OX_REQUIRE(buff, loadFsBuff(path));
|
||||
return {ox::make_unique<ox::FileSystem32>(buff.data, buff.size)};
|
||||
}
|
||||
|
||||
2
deps/ox/src/ox/model/descwrite.hpp
vendored
2
deps/ox/src/ox/model/descwrite.hpp
vendored
@@ -51,7 +51,7 @@ constexpr auto buildSubscriptStack(const T**, SubscriptStack *s) noexcept {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr auto buildSubscriptStack(const UniquePtr<T>*, SubscriptStack *s) noexcept {
|
||||
constexpr auto buildSubscriptStack(const UPtr<T>*, SubscriptStack *s) noexcept {
|
||||
s->push_back({.subscriptType = Subscript::SubscriptType::Ptr});
|
||||
}
|
||||
|
||||
|
||||
10
deps/ox/src/ox/model/modelvalue.cpp
vendored
10
deps/ox/src/ox/model/modelvalue.cpp
vendored
@@ -6,19 +6,21 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <ox/std/hashmap.hpp>
|
||||
|
||||
#include "modelvalue.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
static_assert([]() -> ox::Error {
|
||||
ox::ModelValue v;
|
||||
static_assert([]() -> Error {
|
||||
ModelValue v;
|
||||
OX_RETURN_ERROR(v.setType<int32_t>());
|
||||
if (v.type() != ModelValue::Type::SignedInteger32) {
|
||||
return ox::Error(1, "type is wrong");
|
||||
return Error(1, "type is wrong");
|
||||
}
|
||||
//oxReturnError(v.set<int32_t>(5));
|
||||
return {};
|
||||
}() == ox::Error{});
|
||||
}() == Error{});
|
||||
|
||||
// a dummy function to prevent linker errors in a library that has no other symbols
|
||||
void modelDummyFunc() noexcept {}
|
||||
|
||||
14
deps/ox/src/ox/model/modelvalue.hpp
vendored
14
deps/ox/src/ox/model/modelvalue.hpp
vendored
@@ -519,7 +519,7 @@ class ModelObject {
|
||||
protected:
|
||||
OX_MODEL_FRIEND(ModelObject);
|
||||
friend ModelValue;
|
||||
Vector<UniquePtr<Field>> m_fieldsOrder;
|
||||
Vector<UPtr<Field>> m_fieldsOrder;
|
||||
HashMap<String, ModelValue*> m_fields;
|
||||
const DescriptorType *m_type = nullptr;
|
||||
|
||||
@@ -692,7 +692,7 @@ class ModelUnion {
|
||||
};
|
||||
friend constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept;
|
||||
friend ModelValue;
|
||||
Vector<UniquePtr<Field>> m_fieldsOrder;
|
||||
Vector<UPtr<Field>> m_fieldsOrder;
|
||||
HashMap<String, Field*> m_fields;
|
||||
const DescriptorType *m_type = nullptr;
|
||||
int m_unionIdx = -1;
|
||||
@@ -718,14 +718,14 @@ class ModelUnion {
|
||||
m_unionIdx = other.m_unionIdx;
|
||||
}
|
||||
|
||||
static constexpr Result<UniquePtr<ModelUnion>> make(const DescriptorType *type) noexcept {
|
||||
UniquePtr<ModelUnion> out(new ModelUnion);
|
||||
static constexpr Result<UPtr<ModelUnion>> make(const DescriptorType *type) noexcept {
|
||||
UPtr<ModelUnion> out(new ModelUnion);
|
||||
OX_RETURN_ERROR(out->setType(type));
|
||||
return out;
|
||||
}
|
||||
|
||||
static constexpr Result<UniquePtr<ModelUnion>> make(const ModelUnion &other) noexcept {
|
||||
return UniquePtr<ModelUnion>(new ModelUnion(other));
|
||||
static constexpr Result<UPtr<ModelUnion>> make(const ModelUnion &other) noexcept {
|
||||
return UPtr<ModelUnion>(new ModelUnion(other));
|
||||
}
|
||||
|
||||
constexpr ox::Result<ModelValue*> at(StringView const&k) noexcept {
|
||||
@@ -1174,7 +1174,7 @@ template<typename T>
|
||||
constexpr Error ModelValue::set(const T &v) noexcept {
|
||||
constexpr auto type = getType<T>();
|
||||
if (m_type != type) [[unlikely]] {
|
||||
return ox::Error(1, "type mismatch");
|
||||
return Error(1, "type mismatch");
|
||||
}
|
||||
auto &value = getValue<type>(*this);
|
||||
if constexpr(type == Type::Vector || type == Type::Object ||
|
||||
|
||||
2
deps/ox/src/ox/model/types.hpp
vendored
2
deps/ox/src/ox/model/types.hpp
vendored
@@ -161,7 +161,7 @@ template<typename T>
|
||||
constexpr bool isSmartPtr_v = false;
|
||||
|
||||
template<typename T>
|
||||
constexpr bool isSmartPtr_v<::ox::UniquePtr<T>> = true;
|
||||
constexpr bool isSmartPtr_v<::ox::UPtr<T>> = true;
|
||||
|
||||
#if __has_include(<array>)
|
||||
template<typename T>
|
||||
|
||||
10
deps/ox/src/ox/model/typestore.hpp
vendored
10
deps/ox/src/ox/model/typestore.hpp
vendored
@@ -21,7 +21,7 @@ namespace ox {
|
||||
|
||||
class TypeStore {
|
||||
private:
|
||||
HashMap<String, UniquePtr<DescriptorType>> m_cache;
|
||||
HashMap<String, UPtr<DescriptorType>> m_cache;
|
||||
|
||||
public:
|
||||
constexpr TypeStore() noexcept = default;
|
||||
@@ -86,12 +86,12 @@ class TypeStore {
|
||||
return getLoad(typeName, typeVersion);
|
||||
}
|
||||
|
||||
constexpr void set(const auto &typeId, UniquePtr<DescriptorType> dt) noexcept {
|
||||
constexpr void set(const auto &typeId, UPtr<DescriptorType> dt) noexcept {
|
||||
m_cache[typeId] = std::move(dt);
|
||||
}
|
||||
|
||||
constexpr void set(const auto &typeId, DescriptorType *dt) noexcept {
|
||||
m_cache[typeId] = UniquePtr<DescriptorType>(dt);
|
||||
m_cache[typeId] = UPtr<DescriptorType>(dt);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@@ -105,11 +105,11 @@ class TypeStore {
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual Result<UniquePtr<DescriptorType>> loadDescriptor(ox::StringView) noexcept {
|
||||
virtual Result<UPtr<DescriptorType>> loadDescriptor(ox::StringView) noexcept {
|
||||
return ox::Error(1);
|
||||
}
|
||||
|
||||
Result<UniquePtr<DescriptorType>> loadDescriptor(ox::StringViewCR name, int version,
|
||||
Result<UPtr<DescriptorType>> loadDescriptor(ox::StringViewCR name, int version,
|
||||
const ox::TypeParamPack &typeParams) noexcept {
|
||||
const auto typeId = buildTypeId(name, version, typeParams);
|
||||
return loadDescriptor(typeId);
|
||||
|
||||
2
deps/ox/src/ox/oc/read.hpp
vendored
2
deps/ox/src/ox/oc/read.hpp
vendored
@@ -282,7 +282,7 @@ Error readOC(BufferView const buff, auto &val) noexcept {
|
||||
try {
|
||||
Json::Value doc;
|
||||
Json::CharReaderBuilder parserBuilder;
|
||||
auto parser = UniquePtr<Json::CharReader>(parserBuilder.newCharReader());
|
||||
auto parser = UPtr<Json::CharReader>(parserBuilder.newCharReader());
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
if (!parser->parse(buff.data(), buff.data() + buff.size(), &doc, nullptr)) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
|
||||
6
deps/ox/src/ox/preloader/preloader.hpp
vendored
6
deps/ox/src/ox/preloader/preloader.hpp
vendored
@@ -74,7 +74,7 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>, OpType::Reflect> {
|
||||
const Preloader &operator=(const Preloader &src) = delete;
|
||||
const Preloader &operator=(Preloader &&src) = delete;
|
||||
|
||||
constexpr static ox::Result<ox::UniquePtr<Preloader>> make(ox::ios_base::seekdir anchor = ox::ios_base::cur,
|
||||
constexpr static ox::Result<ox::UPtr<Preloader>> make(ox::ios_base::seekdir anchor = ox::ios_base::cur,
|
||||
std::size_t sz = 0) noexcept;
|
||||
|
||||
template<typename T>
|
||||
@@ -141,9 +141,9 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>, OpType::Reflect> {
|
||||
};
|
||||
|
||||
template<typename PlatSpec>
|
||||
constexpr ox::Result<ox::UniquePtr<Preloader<PlatSpec>>>
|
||||
constexpr ox::Result<ox::UPtr<Preloader<PlatSpec>>>
|
||||
Preloader<PlatSpec>::make(ox::ios_base::seekdir anchor, std::size_t sz) noexcept {
|
||||
auto p = ox::UniquePtr<Preloader>(new Preloader);
|
||||
auto p = ox::UPtr<Preloader>(new Preloader);
|
||||
if (const auto err = p->m_writer.seekp(0, anchor)) {
|
||||
return {std::move(p), err};
|
||||
}
|
||||
|
||||
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
1
deps/ox/src/ox/std/CMakeLists.txt
vendored
@@ -33,6 +33,7 @@ add_library(
|
||||
concepts.cpp
|
||||
fmt.cpp
|
||||
heapmgr.cpp
|
||||
istreamreader.cpp
|
||||
math.cpp
|
||||
memops.cpp
|
||||
random.cpp
|
||||
|
||||
96
deps/ox/src/ox/std/anyptr.hpp
vendored
96
deps/ox/src/ox/std/anyptr.hpp
vendored
@@ -22,7 +22,7 @@ class AnyPtrT {
|
||||
private:
|
||||
struct WrapBase {
|
||||
virtual constexpr ~WrapBase() = default;
|
||||
virtual constexpr WrapBase *copyTo(ox::Span<char> s) noexcept = 0;
|
||||
virtual constexpr WrapBase *copyTo(Span<char> s) const noexcept = 0;
|
||||
virtual constexpr operator bool() const noexcept = 0;
|
||||
virtual void free() noexcept = 0;
|
||||
};
|
||||
@@ -32,7 +32,7 @@ class AnyPtrT {
|
||||
T *data{};
|
||||
explicit constexpr Wrap(T *pData) noexcept: data(pData) {
|
||||
}
|
||||
constexpr WrapBase *copyTo(ox::Span<char> s) noexcept override {
|
||||
constexpr WrapBase *copyTo(Span<char> s) const noexcept override {
|
||||
oxAssert(s.size() >= sizeof(Wrap), "too small buffer");
|
||||
if (std::is_constant_evaluated()) {
|
||||
return new Wrap(data);
|
||||
@@ -49,8 +49,10 @@ class AnyPtrT {
|
||||
}
|
||||
};
|
||||
|
||||
union {
|
||||
WrapBase *m_wrapPtr{};
|
||||
ox::Array<char, sizeof(Wrap<void*>)> m_wrapData;
|
||||
AllocAlias<Wrap<void*>> m_wrapData;
|
||||
} m_data;
|
||||
|
||||
public:
|
||||
constexpr AnyPtrT() noexcept = default;
|
||||
@@ -58,25 +60,25 @@ class AnyPtrT {
|
||||
template<typename T>
|
||||
constexpr AnyPtrT(T *ptr) noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
m_wrapPtr = new Wrap<T>(ptr);
|
||||
setWrapPtr(new Wrap<T>(ptr));
|
||||
} else {
|
||||
m_wrapPtr = new(m_wrapData.data()) Wrap<T>(ptr);
|
||||
new(m_data.m_wrapData.data()) Wrap<T>(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr AnyPtrT(AnyPtrT const&other) noexcept requires(!unique) {
|
||||
constexpr AnyPtrT(AnyPtrT const &other) noexcept requires(!unique) {
|
||||
if (other) {
|
||||
m_wrapPtr = other.m_wrapPtr->copyTo(m_wrapData);
|
||||
setWrapPtr(other.getWrapPtr()->copyTo(m_data.m_wrapData.buff));
|
||||
}
|
||||
}
|
||||
|
||||
constexpr AnyPtrT(AnyPtrT &&other) noexcept {
|
||||
if (other) {
|
||||
m_wrapPtr = other.m_wrapPtr->copyTo(m_wrapData);
|
||||
setWrapPtr(other.getWrapPtr()->copyTo(m_data.m_wrapData.buff));
|
||||
if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
ox::safeDelete(m_data.m_wrapPtr);
|
||||
}
|
||||
other.m_wrapPtr = {};
|
||||
m_data.m_wrapData = {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +87,7 @@ class AnyPtrT {
|
||||
free();
|
||||
}
|
||||
if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
ox::safeDelete(m_data.m_wrapPtr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,25 +96,31 @@ class AnyPtrT {
|
||||
if constexpr(unique) {
|
||||
free();
|
||||
} else if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
ox::safeDelete(m_data.m_wrapPtr);
|
||||
}
|
||||
if (std::is_constant_evaluated()) {
|
||||
m_wrapPtr = new Wrap(ptr);
|
||||
setWrapPtr(new Wrap(ptr));
|
||||
} else {
|
||||
m_wrapPtr = new(m_wrapData.data()) Wrap(ptr);
|
||||
new(m_data.m_wrapData.data()) Wrap(ptr);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr AnyPtrT &operator=(AnyPtrT const&ptr) noexcept requires(!unique) {
|
||||
constexpr AnyPtrT &operator=(AnyPtrT const &ptr) noexcept requires(!unique) {
|
||||
if (this != &ptr) {
|
||||
if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
ox::safeDelete(m_data.m_wrapPtr);
|
||||
}
|
||||
if (std::is_constant_evaluated()) {
|
||||
if (ptr) {
|
||||
m_wrapPtr = ptr.m_wrapPtr->copyTo(m_wrapData);
|
||||
ptr.getWrapPtr()->copyTo(m_data.m_wrapData.buff);
|
||||
}
|
||||
} else {
|
||||
m_wrapPtr = nullptr;
|
||||
if (ptr) {
|
||||
setWrapPtr(ptr.getWrapPtr()->copyTo(m_data.m_wrapData.buff));
|
||||
} else {
|
||||
setWrapPtr(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
@@ -123,43 +131,65 @@ class AnyPtrT {
|
||||
if constexpr(unique) {
|
||||
free();
|
||||
} else if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
ox::safeDelete(m_data.m_wrapPtr);
|
||||
}
|
||||
if (ptr) {
|
||||
m_wrapPtr = ptr.m_wrapPtr->copyTo(m_wrapData);
|
||||
setWrapPtr(ptr.getWrapPtr()->copyTo(m_data.m_wrapData.buff));
|
||||
if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(ptr.m_wrapPtr);
|
||||
ptr.m_wrapPtr = nullptr;
|
||||
ox::safeDelete(ptr.m_data.m_wrapPtr);
|
||||
setWrapPtr(nullptr);
|
||||
}
|
||||
} else {
|
||||
m_wrapPtr = nullptr;
|
||||
m_data = {};
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr operator bool() const noexcept {
|
||||
return m_wrapPtr && *m_wrapPtr;
|
||||
return getWrapPtr() && *getWrapPtr();
|
||||
}
|
||||
|
||||
constexpr void free() noexcept {
|
||||
if (m_wrapPtr) {
|
||||
m_wrapPtr->free();
|
||||
if (auto p = getWrapPtr()) {
|
||||
p->free();
|
||||
}
|
||||
if (std::is_constant_evaluated()) {
|
||||
ox::safeDelete(m_wrapPtr);
|
||||
ox::safeDelete(m_data.m_wrapPtr);
|
||||
}
|
||||
m_wrapPtr = nullptr;
|
||||
m_data.m_wrapData = {};
|
||||
}
|
||||
|
||||
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
|
||||
if constexpr(defines::HasRTTI) {
|
||||
return dynamic_cast<Wrap<T> const*>(getWrapPtr())->data;
|
||||
}
|
||||
return static_cast<Wrap<T> const*>(getWrapPtr())->data;
|
||||
}
|
||||
|
||||
private:
|
||||
constexpr void setWrapPtr(WrapBase *ptr) noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
m_data.m_wrapPtr = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr WrapBase *getWrapPtr() noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
return m_data.m_wrapPtr;
|
||||
} else {
|
||||
return std::launder(reinterpret_cast<WrapBase*>(m_data.m_wrapData.data()));
|
||||
}
|
||||
}
|
||||
|
||||
constexpr WrapBase const *getWrapPtr() const noexcept {
|
||||
if (std::is_constant_evaluated()) {
|
||||
return m_data.m_wrapPtr;
|
||||
} else {
|
||||
return std::launder(reinterpret_cast<WrapBase const*>(m_data.m_wrapData.data()));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
4
deps/ox/src/ox/std/assert.hpp
vendored
4
deps/ox/src/ox/std/assert.hpp
vendored
@@ -8,10 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(OX_USE_STDLIB)
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
#include "def.hpp"
|
||||
#include "defines.hpp"
|
||||
#include "error.hpp"
|
||||
|
||||
6
deps/ox/src/ox/std/defines.hpp
vendored
6
deps/ox/src/ox/std/defines.hpp
vendored
@@ -53,6 +53,12 @@ constexpr auto NDebug = true;
|
||||
constexpr auto NDebug = false;
|
||||
#endif
|
||||
|
||||
#if defined(OX_BARE_METAL)
|
||||
constexpr auto HasRTTI = false;
|
||||
#else
|
||||
constexpr auto HasRTTI = true;
|
||||
#endif
|
||||
|
||||
#if defined(__BIG_ENDIAN__)
|
||||
constexpr auto BigEndian = true;
|
||||
constexpr auto LittleEndian = false;
|
||||
|
||||
38
deps/ox/src/ox/std/error.hpp
vendored
38
deps/ox/src/ox/std/error.hpp
vendored
@@ -37,7 +37,7 @@ using ErrorCode = uint16_t;
|
||||
|
||||
struct [[nodiscard]] Error {
|
||||
std::source_location src;
|
||||
ox::CString msg = nullptr;
|
||||
CString msg = nullptr;
|
||||
ErrorCode errCode = 0;
|
||||
|
||||
constexpr Error() noexcept = default;
|
||||
@@ -51,7 +51,7 @@ struct [[nodiscard]] Error {
|
||||
|
||||
explicit constexpr Error(
|
||||
ErrorCode const errCode,
|
||||
ox::CString msg,
|
||||
CString const msg,
|
||||
std::source_location const &src = std::source_location::current()) noexcept:
|
||||
src{src},
|
||||
msg{msg},
|
||||
@@ -62,6 +62,20 @@ struct [[nodiscard]] Error {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
constexpr void throwException() const;
|
||||
|
||||
constexpr Error reoriginate(
|
||||
ErrorCode const pErrCode,
|
||||
CString const pMsg = nullptr,
|
||||
std::source_location const &pSrc = std::source_location::current()) const noexcept {
|
||||
return Error{pErrCode, pMsg, pSrc};
|
||||
}
|
||||
|
||||
constexpr Error reoriginate(
|
||||
std::source_location const &pSrc = std::source_location::current()) const noexcept {
|
||||
return Error{errCode, msg, pSrc};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
@@ -77,7 +91,7 @@ constexpr auto toStr(Error const &err) noexcept {
|
||||
|
||||
struct Exception: public std::exception {
|
||||
std::source_location src;
|
||||
ox::CString msg = nullptr;
|
||||
CString msg = nullptr;
|
||||
ErrorCode errCode = 0;
|
||||
|
||||
explicit Exception(
|
||||
@@ -88,7 +102,7 @@ struct Exception: public std::exception {
|
||||
|
||||
explicit Exception(
|
||||
ErrorCode const errCode,
|
||||
ox::CString msg,
|
||||
CString msg,
|
||||
std::source_location const &src = std::source_location::current()) noexcept:
|
||||
src{src},
|
||||
msg{msg},
|
||||
@@ -109,16 +123,24 @@ struct Exception: public std::exception {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
constexpr void Error::throwException() const {
|
||||
if (errCode) [[unlikely]] {
|
||||
throw Exception{*this};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[[noreturn]]
|
||||
void panic(
|
||||
Error const &err,
|
||||
char const *panicMsg,
|
||||
CString panicMsg,
|
||||
std::source_location const &src = std::source_location::current()) noexcept;
|
||||
|
||||
template<typename T>
|
||||
struct [[nodiscard]] Result {
|
||||
|
||||
using type = typename remove_reference<T>::type;
|
||||
using type = remove_reference_t<T>;
|
||||
|
||||
T value;
|
||||
Error error;
|
||||
@@ -209,7 +231,7 @@ struct [[nodiscard]] Result {
|
||||
[[nodiscard]]
|
||||
constexpr T &unwrapThrow() & {
|
||||
if (error) {
|
||||
throw ox::Exception(error);
|
||||
throw Exception(error);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -217,7 +239,7 @@ struct [[nodiscard]] Result {
|
||||
[[nodiscard]]
|
||||
constexpr T &&unwrapThrow() && {
|
||||
if (error) {
|
||||
throw ox::Exception(error);
|
||||
throw Exception(error);
|
||||
}
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
15
deps/ox/src/ox/std/hashmap.hpp
vendored
15
deps/ox/src/ox/std/hashmap.hpp
vendored
@@ -106,9 +106,12 @@ constexpr bool HashMap<K, T>::operator==(HashMap const &other) const {
|
||||
if (m_keys != other.m_keys) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < m_keys.size(); ++i) {
|
||||
auto &k = m_keys[i];
|
||||
if (at(k) != other.at(k)) {
|
||||
for (auto &k : m_keys) {
|
||||
auto const a = at(k).value;
|
||||
auto const b = other.at(k).value;
|
||||
if (
|
||||
a != b && // handle one being null and other not
|
||||
(a && b && *a != *b)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -196,7 +199,7 @@ constexpr std::size_t HashMap<K, T>::size() const noexcept {
|
||||
}
|
||||
|
||||
template<typename K, typename T>
|
||||
constexpr Vector<K> const&HashMap<K, T>::keys() const noexcept {
|
||||
constexpr Vector<K> const &HashMap<K, T>::keys() const noexcept {
|
||||
return m_keys;
|
||||
}
|
||||
|
||||
@@ -205,8 +208,8 @@ constexpr Vector<T> HashMap<K, T>::values() const noexcept {
|
||||
Vector<T> out;
|
||||
out.reserve(m_keys.size());
|
||||
for (auto const &p : m_pairs) {
|
||||
if (out) {
|
||||
out.emplace_back(p->value);
|
||||
if (p) {
|
||||
out.emplace_back(*p->value);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
||||
77
deps/ox/src/ox/std/istreamreader.cpp
vendored
Normal file
77
deps/ox/src/ox/std/istreamreader.cpp
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2015 - 2025 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/.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
#include <istream>
|
||||
|
||||
#include "array.hpp"
|
||||
#include "reader.hpp"
|
||||
#include "istreamreader.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::ios_base::seekdir sdMap(ox::ios_base::seekdir in) noexcept {
|
||||
switch (in) {
|
||||
case ox::ios_base::beg:
|
||||
return std::ios_base::beg;
|
||||
case ox::ios_base::end:
|
||||
return std::ios_base::end;
|
||||
case ox::ios_base::cur:
|
||||
return std::ios_base::cur;
|
||||
}
|
||||
return std::ios_base::beg;
|
||||
}
|
||||
|
||||
Result<char> StreamReader::peek() const noexcept {
|
||||
try {
|
||||
if (m_strm.eof()) {
|
||||
return Error{1, "EOF"};
|
||||
}
|
||||
char c{};
|
||||
m_strm.get(c);
|
||||
if (m_strm.unget()) [[unlikely]] {
|
||||
return ox::Error{1, "Unable to unget character"};
|
||||
}
|
||||
return static_cast<char>(c);
|
||||
} catch (std::exception const&) {
|
||||
return ox::Error(1, "peek failed");
|
||||
}
|
||||
}
|
||||
|
||||
Result<size_t> StreamReader::read(char *v, size_t cnt) noexcept {
|
||||
return static_cast<size_t>(m_strm.read(v, static_cast<std::streamsize>(cnt)).gcount());
|
||||
}
|
||||
|
||||
Error StreamReader::seekg(size_t p) noexcept {
|
||||
try {
|
||||
m_strm.seekg(static_cast<long long int>(p), std::ios_base::cur);
|
||||
} catch (std::exception const&) {
|
||||
return ox::Error(1, "seekg failed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Error StreamReader::seekg(int64_t p, ios_base::seekdir sd) noexcept {
|
||||
try {
|
||||
m_strm.seekg(p, sdMap(sd));
|
||||
} catch (std::exception const&) {
|
||||
return ox::Error(1, "seekg failed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<size_t> StreamReader::tellg() noexcept {
|
||||
const auto sz = m_strm.tellg();
|
||||
return {static_cast<size_t>(sz), ox::Error(sz == -1)};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
33
deps/ox/src/ox/std/istreamreader.hpp
vendored
Normal file
33
deps/ox/src/ox/std/istreamreader.hpp
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2015 - 2025 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
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
#include <istream>
|
||||
#endif
|
||||
|
||||
#include "reader.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
class StreamReader: public Reader_v {
|
||||
private:
|
||||
std::istream &m_strm;
|
||||
public:
|
||||
constexpr explicit StreamReader(std::istream &stream) noexcept: m_strm(stream) {}
|
||||
Result<char> peek() const noexcept override;
|
||||
Result<size_t> read(char *v, size_t cnt) noexcept override;
|
||||
Error seekg(size_t p) noexcept override;
|
||||
Error seekg(int64_t p, ios_base::seekdir sd) noexcept override;
|
||||
Result<size_t> tellg() noexcept override;
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
43
deps/ox/src/ox/std/memory.hpp
vendored
43
deps/ox/src/ox/std/memory.hpp
vendored
@@ -179,26 +179,26 @@ constexpr bool operator!=(std::nullptr_t, const SharedPtr<T> &p2) noexcept {
|
||||
|
||||
|
||||
template<typename T, typename Deleter = DefaultDelete>
|
||||
class UniquePtr {
|
||||
class UPtr {
|
||||
|
||||
private:
|
||||
T *m_t = nullptr;
|
||||
|
||||
public:
|
||||
using value_type = T;
|
||||
explicit constexpr UniquePtr(T *t = nullptr) noexcept: m_t(t) {
|
||||
explicit constexpr UPtr(T *t = nullptr) noexcept: m_t(t) {
|
||||
}
|
||||
|
||||
constexpr UniquePtr(UniquePtr&) = delete;
|
||||
constexpr UPtr(UPtr&) = delete;
|
||||
|
||||
constexpr UniquePtr(const UniquePtr&) = delete;
|
||||
constexpr UPtr(const UPtr&) = delete;
|
||||
|
||||
template<typename U, typename UDeleter>
|
||||
constexpr UniquePtr(UniquePtr<U, UDeleter> &&other) noexcept {
|
||||
constexpr UPtr(UPtr<U, UDeleter> &&other) noexcept {
|
||||
m_t = other.release();
|
||||
}
|
||||
|
||||
constexpr ~UniquePtr() {
|
||||
constexpr ~UPtr() {
|
||||
Deleter()(m_t);
|
||||
}
|
||||
|
||||
@@ -213,24 +213,24 @@ class UniquePtr {
|
||||
return m_t;
|
||||
}
|
||||
|
||||
constexpr void reset(UniquePtr &&other = UniquePtr()) {
|
||||
constexpr void reset(UPtr &&other = UPtr()) {
|
||||
auto t = m_t;
|
||||
m_t = other.release();
|
||||
Deleter()(t);
|
||||
}
|
||||
|
||||
constexpr UniquePtr &operator=(UniquePtr const&other) = delete;
|
||||
constexpr UPtr &operator=(UPtr const&other) = delete;
|
||||
|
||||
template<typename U, typename UDeleter>
|
||||
constexpr UniquePtr &operator=(UniquePtr<U, UDeleter> const&other) = delete;
|
||||
constexpr UPtr &operator=(UPtr<U, UDeleter> const&other) = delete;
|
||||
|
||||
constexpr UniquePtr &operator=(UniquePtr<T> &&other) noexcept {
|
||||
constexpr UPtr &operator=(UPtr<T> &&other) noexcept {
|
||||
reset(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U, typename UDeleter>
|
||||
constexpr UniquePtr &operator=(UniquePtr<U, UDeleter> &&other) noexcept {
|
||||
constexpr UPtr &operator=(UPtr<U, UDeleter> &&other) noexcept {
|
||||
reset(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
@@ -249,37 +249,34 @@ class UniquePtr {
|
||||
|
||||
};
|
||||
|
||||
template<typename T, typename Deleter = DefaultDelete>
|
||||
using UPtr = UniquePtr<T, Deleter>;
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator==(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexcept {
|
||||
constexpr bool operator==(const UPtr<T> &p1, const UPtr<T> &p2) noexcept {
|
||||
return p1.get() == p2.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator==(const UniquePtr<T> &p1, std::nullptr_t) noexcept {
|
||||
constexpr bool operator==(const UPtr<T> &p1, std::nullptr_t) noexcept {
|
||||
return p1.get() == nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator==(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
|
||||
constexpr bool operator==(std::nullptr_t, const UPtr<T> &p2) noexcept {
|
||||
return p2.get() == nullptr;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator!=(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexcept {
|
||||
constexpr bool operator!=(const UPtr<T> &p1, const UPtr<T> &p2) noexcept {
|
||||
return p1.get() != p2.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator!=(const UniquePtr<T> &p1, std::nullptr_t) noexcept {
|
||||
constexpr bool operator!=(const UPtr<T> &p1, std::nullptr_t) noexcept {
|
||||
return !p1.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr bool operator!=(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
|
||||
constexpr bool operator!=(std::nullptr_t, const UPtr<T> &p2) noexcept {
|
||||
return !p2.get();
|
||||
}
|
||||
|
||||
@@ -287,14 +284,14 @@ constexpr bool operator!=(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
|
||||
template<typename T, typename U = T, typename ...Args>
|
||||
[[nodiscard]]
|
||||
constexpr auto make_unique(Args&&... args) {
|
||||
return UniquePtr<U>(new T(ox::forward<Args>(args)...));
|
||||
return UPtr<U>(new T(ox::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename T, typename U = T, typename ...Args>
|
||||
[[nodiscard]]
|
||||
constexpr Result<UniquePtr<U>> make_unique_catch(Args&&... args) noexcept {
|
||||
constexpr Result<UPtr<U>> make_unique_catch(Args&&... args) noexcept {
|
||||
try {
|
||||
return UniquePtr<U>(new T(ox::forward<Args>(args)...));
|
||||
return UPtr<U>(new T(ox::forward<Args>(args)...));
|
||||
} catch (ox::Exception const&ex) {
|
||||
return ex.toError();
|
||||
}
|
||||
|
||||
69
deps/ox/src/ox/std/reader.cpp
vendored
69
deps/ox/src/ox/std/reader.cpp
vendored
@@ -5,72 +5,3 @@
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
#include <istream>
|
||||
|
||||
#include "array.hpp"
|
||||
#include "reader.hpp"
|
||||
|
||||
namespace ox {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::ios_base::seekdir sdMap(ox::ios_base::seekdir in) noexcept {
|
||||
switch (in) {
|
||||
case ox::ios_base::beg:
|
||||
return std::ios_base::beg;
|
||||
case ox::ios_base::end:
|
||||
return std::ios_base::end;
|
||||
case ox::ios_base::cur:
|
||||
return std::ios_base::cur;
|
||||
}
|
||||
return std::ios_base::beg;
|
||||
}
|
||||
|
||||
ox::Result<char> StreamReader::peek() const noexcept {
|
||||
try {
|
||||
if (m_strm.eof()) {
|
||||
return Error{1, "EOF"};
|
||||
}
|
||||
char c{};
|
||||
m_strm.get(c);
|
||||
if (m_strm.unget()) [[unlikely]] {
|
||||
return ox::Error{1, "Unable to unget character"};
|
||||
}
|
||||
return static_cast<char>(c);
|
||||
} catch (std::exception const&) {
|
||||
return ox::Error(1, "peek failed");
|
||||
}
|
||||
}
|
||||
|
||||
ox::Result<std::size_t> StreamReader::read(char *v, std::size_t cnt) noexcept {
|
||||
return static_cast<size_t>(m_strm.read(v, static_cast<std::streamsize>(cnt)).gcount());
|
||||
}
|
||||
|
||||
ox::Error StreamReader::seekg(std::size_t p) noexcept {
|
||||
try {
|
||||
m_strm.seekg(static_cast<long long int>(p), std::ios_base::cur);
|
||||
} catch (std::exception const&) {
|
||||
return ox::Error(1, "seekg failed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StreamReader::seekg(int64_t p, ios_base::seekdir sd) noexcept {
|
||||
try {
|
||||
m_strm.seekg(p, sdMap(sd));
|
||||
} catch (std::exception const&) {
|
||||
return ox::Error(1, "seekg failed");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Result<std::size_t> StreamReader::tellg() noexcept {
|
||||
const auto sz = m_strm.tellg();
|
||||
return {static_cast<std::size_t>(sz), ox::Error(sz == -1)};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
18
deps/ox/src/ox/std/reader.hpp
vendored
18
deps/ox/src/ox/std/reader.hpp
vendored
@@ -8,10 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
#include <istream>
|
||||
#endif
|
||||
|
||||
#include "concepts.hpp"
|
||||
#include "error.hpp"
|
||||
#include "types.hpp"
|
||||
@@ -63,18 +59,4 @@ class ReaderT: public Reader_v {
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef OX_USE_STDLIB
|
||||
class StreamReader: public Reader_v {
|
||||
private:
|
||||
std::istream &m_strm;
|
||||
public:
|
||||
constexpr explicit StreamReader(std::istream &stream) noexcept: m_strm(stream) {}
|
||||
ox::Result<char> peek() const noexcept override;
|
||||
ox::Result<std::size_t> read(char *v, std::size_t cnt) noexcept override;
|
||||
ox::Error seekg(std::size_t p) noexcept override;
|
||||
ox::Error seekg(int64_t p, ios_base::seekdir sd) noexcept override;
|
||||
ox::Result<std::size_t> tellg() noexcept override;
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
4
deps/ox/src/ox/std/strops.cpp
vendored
4
deps/ox/src/ox/std/strops.cpp
vendored
@@ -20,13 +20,17 @@ static_assert(ox::strcmp("", "") == 0, "\"\" == \"\"");
|
||||
|
||||
static_assert([] {
|
||||
auto constexpr testStr = ox::Span{"asdf"};
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
return ox::strchr(testStr.data(), 0, 4) == &testStr[4];
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}(), "ox::strchr 0");
|
||||
|
||||
static_assert([] {
|
||||
auto constexpr testStr = "aaaa";
|
||||
// test the const and non-const versions of ox::lastIndexOf
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
return ox::lastIndexOf(testStr, 'a', ox::strlen(testStr)) == 3;
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}(), "ox::lastIndexOf aaaa a");
|
||||
|
||||
#ifndef OX_USE_STDLIB
|
||||
|
||||
19
deps/ox/src/ox/std/typetraits.hpp
vendored
19
deps/ox/src/ox/std/typetraits.hpp
vendored
@@ -309,6 +309,25 @@ template<class T>
|
||||
constexpr bool is_move_constructible_v = detail::is_move_constructible<T>(0);
|
||||
|
||||
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
T const &declvalCopy();
|
||||
|
||||
template<typename T, typename = decltype(T(declvalCopy<T>()))>
|
||||
constexpr bool is_copy_constructible(int) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr bool is_copy_constructible(bool) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
constexpr bool is_copy_constructible_v = detail::is_copy_constructible<T>(0);
|
||||
|
||||
|
||||
// is String?
|
||||
|
||||
template<std::size_t SmallStringSize>
|
||||
|
||||
283
deps/ox/src/ox/std/vector.hpp
vendored
283
deps/ox/src/ox/std/vector.hpp
vendored
@@ -26,7 +26,7 @@ namespace ox {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T, typename Allocator, std::size_t Size = 1>
|
||||
template<typename T, typename Allocator, size_t Size = 1>
|
||||
struct VectorAllocator {
|
||||
static_assert(sizeof(AllocAlias<T>) == sizeof(T));
|
||||
static_assert(alignof(AllocAlias<T>) == alignof(T));
|
||||
@@ -37,7 +37,7 @@ struct VectorAllocator {
|
||||
constexpr VectorAllocator(VectorAllocator const&) noexcept = default;
|
||||
constexpr VectorAllocator(VectorAllocator&&) noexcept = default;
|
||||
|
||||
constexpr void allocate(T **items, std::size_t const cap) noexcept {
|
||||
constexpr void allocate(T **items, size_t const cap) noexcept {
|
||||
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
|
||||
if (std::is_constant_evaluated() || cap > Size) {
|
||||
*items = Allocator{}.allocate(cap);
|
||||
@@ -49,8 +49,8 @@ struct VectorAllocator {
|
||||
constexpr void moveConstructItemsFrom(
|
||||
T **items,
|
||||
VectorAllocator *src,
|
||||
std::size_t const count,
|
||||
std::size_t const cap) noexcept {
|
||||
size_t const count,
|
||||
size_t const cap) noexcept {
|
||||
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
|
||||
// try removing it later
|
||||
if (!std::is_constant_evaluated()) {
|
||||
@@ -68,7 +68,7 @@ struct VectorAllocator {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void deallocate(T *const items, std::size_t const cap) noexcept {
|
||||
constexpr void deallocate(T *const items, size_t const cap) noexcept {
|
||||
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
|
||||
if (std::is_constant_evaluated()) {
|
||||
if (items) {
|
||||
@@ -90,7 +90,7 @@ struct VectorAllocator<T, Allocator, 0> {
|
||||
constexpr VectorAllocator(VectorAllocator const&) noexcept = default;
|
||||
constexpr VectorAllocator(VectorAllocator&&) noexcept = default;
|
||||
|
||||
constexpr void allocate(T **items, std::size_t const cap) noexcept {
|
||||
constexpr void allocate(T **items, size_t const cap) noexcept {
|
||||
*items = Allocator{}.allocate(cap);
|
||||
}
|
||||
|
||||
@@ -98,15 +98,15 @@ struct VectorAllocator<T, Allocator, 0> {
|
||||
constexpr void moveConstructItemsFrom(
|
||||
T**,
|
||||
VectorAllocator*,
|
||||
std::size_t const,
|
||||
std::size_t const) noexcept {
|
||||
size_t const,
|
||||
size_t const) noexcept {
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
constexpr void moveItemsFrom(T**, VectorAllocator*, std::size_t const, std::size_t const) noexcept {
|
||||
constexpr void moveItemsFrom(T**, VectorAllocator*, size_t const, size_t const) noexcept {
|
||||
}
|
||||
|
||||
constexpr void deallocate(T *const items, std::size_t const cap) noexcept {
|
||||
constexpr void deallocate(T *const items, size_t const cap) noexcept {
|
||||
if (items) {
|
||||
Allocator{}.deallocate(items, cap);
|
||||
}
|
||||
@@ -116,12 +116,12 @@ struct VectorAllocator<T, Allocator, 0> {
|
||||
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize = 0, typename Allocator = std::allocator<T>>
|
||||
template<typename T, size_t SmallVectorSize = 0, typename Allocator = std::allocator<T>>
|
||||
class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
|
||||
public:
|
||||
using value_type = T;
|
||||
using size_type = std::size_t;
|
||||
using size_type = size_t;
|
||||
|
||||
template<typename RefType = T&, typename PtrType = T*, bool reverse = false>
|
||||
using iterator = SpanIterator<T, RefType, PtrType, reverse>;
|
||||
@@ -129,18 +129,18 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
private:
|
||||
static constexpr auto initialCap = SmallVectorSize > 0 ? SmallVectorSize : 50;
|
||||
static constexpr auto useNoexcept = ox::is_integral_v<T> || ox::is_pointer_v<T>;
|
||||
std::size_t m_size = 0;
|
||||
std::size_t m_cap = 0;
|
||||
size_t m_size = 0;
|
||||
size_t m_cap = 0;
|
||||
T *m_items = nullptr;
|
||||
|
||||
public:
|
||||
constexpr Vector() noexcept = default;
|
||||
|
||||
explicit constexpr Vector(std::size_t size) noexcept;
|
||||
explicit constexpr Vector(size_t size) noexcept;
|
||||
|
||||
constexpr Vector(std::initializer_list<T> list) noexcept;
|
||||
|
||||
constexpr Vector(const Vector &other) noexcept(useNoexcept);
|
||||
constexpr Vector(Vector const &other) noexcept(useNoexcept);
|
||||
|
||||
constexpr Vector(Vector &&other) noexcept;
|
||||
|
||||
@@ -155,23 +155,23 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*> begin() const noexcept {
|
||||
return iterator<const T&, const T*>(m_items, 0, m_size);
|
||||
constexpr iterator<T const&, T const*> begin() const noexcept {
|
||||
return iterator<T const&, T const*>(m_items, 0, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*> end() const noexcept {
|
||||
return iterator<const T&, const T*>(m_items, m_size, m_size);
|
||||
constexpr iterator<T const&, T const*> end() const noexcept {
|
||||
return iterator<T const&, T const*>(m_items, m_size, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*> cbegin() const noexcept {
|
||||
return iterator<const T&, const T*>(m_items, 0, m_size);
|
||||
constexpr iterator<T const&, T const*> cbegin() const noexcept {
|
||||
return iterator<T const&, T const*>(m_items, 0, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*> cend() const noexcept {
|
||||
return iterator<const T&, const T*>(m_items, m_size, m_size);
|
||||
constexpr iterator<T const&, T const*> cend() const noexcept {
|
||||
return iterator<T const&, T const*>(m_items, m_size, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
@@ -185,36 +185,36 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*, true> crbegin() const noexcept {
|
||||
return iterator<const T&, const T*, true>(m_items, m_size - 1, m_size);
|
||||
constexpr iterator<T const&, T const*, true> crbegin() const noexcept {
|
||||
return iterator<T const&, T const*, true>(m_items, m_size - 1, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*, true> crend() const noexcept {
|
||||
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
||||
constexpr iterator<T const&, T const*, true> crend() const noexcept {
|
||||
return iterator<T const&, T const*, true>(m_items, MaxValue<size_type>, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*, true> rbegin() const noexcept {
|
||||
return iterator<const T&, const T*, true>(m_items, m_size - 1, m_size);
|
||||
constexpr iterator<T const&, T const*, true> rbegin() const noexcept {
|
||||
return iterator<T const&, T const*, true>(m_items, m_size - 1, m_size);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr iterator<const T&, const T*, true> rend() const noexcept {
|
||||
return iterator<const T&, const T*, true>(m_items, MaxValue<size_type>, m_size);
|
||||
constexpr iterator<T const&, T const*, true> rend() const noexcept {
|
||||
return iterator<T const&, T const*, true>(m_items, MaxValue<size_type>, m_size);
|
||||
}
|
||||
|
||||
constexpr bool operator==(const Vector &other) const noexcept(useNoexcept);
|
||||
constexpr bool operator==(Vector const &other) const noexcept(useNoexcept);
|
||||
|
||||
constexpr Vector &operator=(const Vector &other) noexcept(useNoexcept);
|
||||
constexpr Vector &operator=(Vector const &other) noexcept(useNoexcept);
|
||||
|
||||
constexpr Vector &operator=(Vector &&other) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T &operator[](std::size_t i) noexcept;
|
||||
constexpr T &operator[](size_t i) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const T &operator[](std::size_t i) const noexcept;
|
||||
constexpr T const &operator[](size_t i) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Result<T*> at(size_t i) noexcept;
|
||||
@@ -226,28 +226,28 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
constexpr Result<T*> front() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Result<const T*> front() const noexcept;
|
||||
constexpr Result<T const*> front() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Result<T*> back() noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr Result<const T*> back() const noexcept;
|
||||
constexpr Result<T const*> back() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t capacity() const noexcept;
|
||||
constexpr size_t capacity() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::size_t size() const noexcept;
|
||||
constexpr size_t size() const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool empty() const noexcept;
|
||||
|
||||
constexpr void clear() noexcept(useNoexcept);
|
||||
|
||||
constexpr void resize(std::size_t size) noexcept(useNoexcept);
|
||||
constexpr void resize(size_t size) noexcept(useNoexcept);
|
||||
|
||||
constexpr void reserveResize(std::size_t size) noexcept(useNoexcept);
|
||||
constexpr void reserveResize(size_t size) noexcept(useNoexcept);
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr T *data() noexcept {
|
||||
@@ -255,7 +255,7 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const T *data() const noexcept {
|
||||
constexpr T const *data() const noexcept {
|
||||
return m_items;
|
||||
}
|
||||
|
||||
@@ -263,12 +263,12 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
constexpr bool contains(MaybeView_t<T> const&) const noexcept;
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(
|
||||
std::size_t pos, std::size_t cnt, T const &val) noexcept(useNoexcept);
|
||||
size_t pos, size_t cnt, T const &val) noexcept(useNoexcept);
|
||||
|
||||
constexpr iterator<T&, T*, false> insert(std::size_t pos, T val) noexcept(useNoexcept);
|
||||
constexpr iterator<T&, T*, false> insert(size_t pos, T val) noexcept(useNoexcept);
|
||||
|
||||
template<typename... Args>
|
||||
constexpr iterator<T&, T*, false> emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept);
|
||||
constexpr iterator<T&, T*, false> emplace(size_t pos, Args&&... args) noexcept(useNoexcept);
|
||||
|
||||
template<typename... Args>
|
||||
constexpr T &emplace_back(Args&&... args) noexcept(useNoexcept);
|
||||
@@ -284,14 +284,14 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
* @param pos iterator at the point to remove
|
||||
* @return Error if index is out of bounds
|
||||
*/
|
||||
constexpr Result<iterator<T&, T*, false>> erase(const iterator<> &pos) noexcept(useNoexcept);
|
||||
constexpr Result<iterator<T&, T*, false>> erase(iterator<> const &pos) noexcept(useNoexcept);
|
||||
|
||||
/**
|
||||
* Removes an item from the Vector.
|
||||
* @param pos position of item to remove
|
||||
* @return Error if index is out of bounds
|
||||
*/
|
||||
constexpr Result<iterator<T&, T*, false>> erase(std::size_t pos) noexcept(useNoexcept);
|
||||
constexpr Result<iterator<T&, T*, false>> erase(size_t pos) noexcept(useNoexcept);
|
||||
|
||||
/**
|
||||
* Moves the last item in the Vector to position pos and decrements the
|
||||
@@ -299,59 +299,62 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
|
||||
* @param pos position of item to remove
|
||||
* @return Error if index is out of bounds
|
||||
*/
|
||||
constexpr Error unordered_erase(std::size_t pos) noexcept(useNoexcept);
|
||||
constexpr Error unordered_erase(size_t pos) noexcept(useNoexcept);
|
||||
|
||||
constexpr Error remove(MaybeView_t<T> const &val);
|
||||
|
||||
constexpr void reserve(std::size_t cap) noexcept(useNoexcept);
|
||||
constexpr void reserve(size_t cap) noexcept(useNoexcept);
|
||||
|
||||
constexpr void shrink_to_fit() noexcept(useNoexcept);
|
||||
|
||||
private:
|
||||
constexpr void reserveInsert(
|
||||
std::size_t cap, std::size_t pos, std::size_t offset = 1) noexcept(useNoexcept);
|
||||
size_t cap, size_t pos, size_t offset = 1) noexcept(useNoexcept);
|
||||
|
||||
};
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator, typename RefType, bool reverse>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator, typename RefType, bool reverse>
|
||||
using VectorIt = typename Vector<T, SmallVectorSize, Allocator>::template iterator<RefType, reverse>;
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator, typename RefType, bool reverse>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator, typename RefType, bool reverse>
|
||||
constexpr VectorIt<T, SmallVectorSize, Allocator, RefType, reverse> operator+(
|
||||
std::size_t n,
|
||||
const VectorIt<T, SmallVectorSize, Allocator, RefType, reverse> &a) {
|
||||
size_t n,
|
||||
VectorIt<T, SmallVectorSize, Allocator, RefType, reverse> const &a) {
|
||||
return a + n;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator>::Vector(std::size_t size) noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator>::Vector(size_t const size) noexcept {
|
||||
m_size = size;
|
||||
m_cap = m_size;
|
||||
this->allocate(&m_items, m_cap);
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
std::construct_at(&m_items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator>::Vector(std::initializer_list<T> list) noexcept {
|
||||
reserve(list.size());
|
||||
for (auto &item : list) {
|
||||
emplace_back(std::move(item));
|
||||
m_size = list.size();
|
||||
m_cap = m_size;
|
||||
this->allocate(&m_items, m_cap);
|
||||
for (size_t i{}; auto &item : list) {
|
||||
std::construct_at(&m_items[i], std::move(item));
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator>::Vector(const Vector &other) noexcept(useNoexcept) {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator>::Vector(Vector const &other) noexcept(useNoexcept) {
|
||||
m_size = other.m_size;
|
||||
m_cap = other.m_cap;
|
||||
this->allocate(&m_items, other.m_cap);
|
||||
for (std::size_t i = 0; i < m_size; ++i) {
|
||||
for (size_t i = 0; i < m_size; ++i) {
|
||||
std::construct_at(&m_items[i], other.m_items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator>::Vector(Vector &&other) noexcept {
|
||||
m_size = other.m_size;
|
||||
m_cap = other.m_cap;
|
||||
@@ -362,20 +365,20 @@ constexpr Vector<T, SmallVectorSize, Allocator>::Vector(Vector &&other) noexcept
|
||||
other.m_items = nullptr;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator>::~Vector() {
|
||||
clear();
|
||||
this->deallocate(m_items, m_cap);
|
||||
m_items = nullptr;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::operator==(
|
||||
const Vector &other) const noexcept(useNoexcept) {
|
||||
Vector const &other) const noexcept(useNoexcept) {
|
||||
if (m_size != other.m_size) {
|
||||
return false;
|
||||
}
|
||||
for (std::size_t i = 0; i < m_size; i++) {
|
||||
for (size_t i = 0; i < m_size; i++) {
|
||||
if (!(m_items[i] == other.m_items[i])) {
|
||||
return false;
|
||||
}
|
||||
@@ -383,9 +386,9 @@ constexpr bool Vector<T, SmallVectorSize, Allocator>::operator==(
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator> &Vector<T, SmallVectorSize, Allocator>::operator=(
|
||||
const Vector &other) noexcept(useNoexcept) {
|
||||
Vector const &other) noexcept(useNoexcept) {
|
||||
if (this != &other) {
|
||||
clear();
|
||||
this->deallocate(m_items, m_cap);
|
||||
@@ -393,14 +396,14 @@ constexpr Vector<T, SmallVectorSize, Allocator> &Vector<T, SmallVectorSize, Allo
|
||||
m_size = other.m_size;
|
||||
m_cap = other.m_cap;
|
||||
this->allocate(&m_items, other.m_cap);
|
||||
for (std::size_t i = 0; i < m_size; i++) {
|
||||
for (size_t i = 0; i < m_size; i++) {
|
||||
std::construct_at(&m_items[i], other.m_items[i]);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Vector<T, SmallVectorSize, Allocator> &Vector<T, SmallVectorSize, Allocator>::operator=(
|
||||
Vector &&other) noexcept {
|
||||
if (this != &other) {
|
||||
@@ -417,35 +420,35 @@ constexpr Vector<T, SmallVectorSize, Allocator> &Vector<T, SmallVectorSize, Allo
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr T &Vector<T, SmallVectorSize, Allocator>::operator[](std::size_t i) noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr T &Vector<T, SmallVectorSize, Allocator>::operator[](size_t const i) noexcept {
|
||||
boundsCheck(i, size(), "Vector access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr const T &Vector<T, SmallVectorSize, Allocator>::operator[](std::size_t i) const noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr T const &Vector<T, SmallVectorSize, Allocator>::operator[](size_t const i) const noexcept {
|
||||
boundsCheck(i, size(), "Vector access overflow");
|
||||
return m_items[i];
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::at(size_t const i) noexcept {
|
||||
if (i < size()) [[likely]] {
|
||||
return &operator[](i);
|
||||
}
|
||||
return ox::Error(1, "Vector: Invalid index");
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T const*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) const noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T const*> Vector<T, SmallVectorSize, Allocator>::at(size_t const i) const noexcept {
|
||||
if (i < size()) [[likely]] {
|
||||
return &operator[](i);
|
||||
}
|
||||
return ox::Error(1, "Vector: Invalid index");
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept {
|
||||
if (!m_size) {
|
||||
return {nullptr, ox::Error(1)};
|
||||
@@ -453,15 +456,15 @@ constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept {
|
||||
return &m_items[0];
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<const T*> Vector<T, SmallVectorSize, Allocator>::front() const noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T const*> Vector<T, SmallVectorSize, Allocator>::front() const noexcept {
|
||||
if (!m_size) {
|
||||
return {nullptr, ox::Error(1)};
|
||||
}
|
||||
return &m_items[0];
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::back() noexcept {
|
||||
if (!m_size) {
|
||||
return {nullptr, ox::Error(1)};
|
||||
@@ -469,65 +472,65 @@ constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::back() noexcept {
|
||||
return &m_items[m_size - 1];
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<const T*> Vector<T, SmallVectorSize, Allocator>::back() const noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<T const*> Vector<T, SmallVectorSize, Allocator>::back() const noexcept {
|
||||
if (!m_size) {
|
||||
return {nullptr, ox::Error(1)};
|
||||
}
|
||||
return &m_items[m_size - 1];
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr std::size_t Vector<T, SmallVectorSize, Allocator>::capacity() const noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr size_t Vector<T, SmallVectorSize, Allocator>::capacity() const noexcept {
|
||||
return m_cap;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr std::size_t Vector<T, SmallVectorSize, Allocator>::size() const noexcept {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr size_t Vector<T, SmallVectorSize, Allocator>::size() const noexcept {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::empty() const noexcept {
|
||||
return !m_size;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::clear() noexcept(useNoexcept) {
|
||||
if constexpr(is_class<T>()) {
|
||||
for (std::size_t i = 0; i < m_size; ++i) {
|
||||
for (size_t i = 0; i < m_size; ++i) {
|
||||
m_items[i].~T();
|
||||
}
|
||||
}
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::resize(std::size_t size) noexcept(useNoexcept) {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::resize(size_t const size) noexcept(useNoexcept) {
|
||||
if (m_cap < size) {
|
||||
reserve(size * 2);
|
||||
}
|
||||
if (m_size < size) {
|
||||
for (std::size_t i = m_size; i < size; i++) {
|
||||
for (size_t i = m_size; i < size; i++) {
|
||||
std::construct_at(&m_items[i]);
|
||||
}
|
||||
} else {
|
||||
for (std::size_t i = size; i < m_size; i++) {
|
||||
for (size_t i = size; i < m_size; i++) {
|
||||
m_items[i].~T();
|
||||
}
|
||||
}
|
||||
m_size = size;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::reserveResize(std::size_t const size) noexcept(useNoexcept) {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::reserveResize(size_t const size) noexcept(useNoexcept) {
|
||||
reserve(size);
|
||||
resize(size);
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeView_t<T> const &v) const noexcept {
|
||||
for (std::size_t i = 0; i < m_size; ++i) {
|
||||
for (size_t i = 0; i < m_size; ++i) {
|
||||
if (m_items[i] == v) {
|
||||
return true;
|
||||
}
|
||||
@@ -535,10 +538,10 @@ constexpr bool Vector<T, SmallVectorSize, Allocator>::contains(MaybeView_t<T> co
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, 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, T const &val) noexcept(useNoexcept) {
|
||||
size_t const pos, size_t const cnt, T const &val) noexcept(useNoexcept) {
|
||||
if (m_size + cnt > m_cap) {
|
||||
reserveInsert(m_cap ? m_size + cnt : initialCap, pos, cnt);
|
||||
}
|
||||
@@ -558,9 +561,9 @@ Vector<T, SmallVectorSize, Allocator>::insert(
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, 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, T val) noexcept(useNoexcept) {
|
||||
Vector<T, SmallVectorSize, Allocator>::insert(size_t pos, T val) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
|
||||
}
|
||||
@@ -576,10 +579,10 @@ Vector<T, SmallVectorSize, Allocator>::insert(std::size_t pos, T val) noexcept(u
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
template<typename... Args>
|
||||
constexpr typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>
|
||||
Vector<T, SmallVectorSize, Allocator>::emplace(std::size_t pos, Args&&... args) noexcept(useNoexcept) {
|
||||
Vector<T, SmallVectorSize, Allocator>::emplace(size_t pos, Args&&... args) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserveInsert(m_cap ? m_cap * 2 : initialCap, pos);
|
||||
if (pos < m_size) {
|
||||
@@ -599,7 +602,7 @@ Vector<T, SmallVectorSize, Allocator>::emplace(std::size_t pos, Args&&... args)
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
template<typename... Args>
|
||||
constexpr T &Vector<T, SmallVectorSize, Allocator>::emplace_back(Args&&... args) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
@@ -610,7 +613,7 @@ constexpr T &Vector<T, SmallVectorSize, Allocator>::emplace_back(Args&&... args)
|
||||
return *out;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(T const &item) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserve(m_cap ? m_cap * 2 : initialCap);
|
||||
@@ -619,7 +622,7 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(T const &item) n
|
||||
++m_size;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(T &&item) noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
reserve(m_cap ? m_cap * 2 : initialCap);
|
||||
@@ -628,21 +631,21 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::push_back(T &&item) noexce
|
||||
++m_size;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::pop_back() noexcept(useNoexcept) {
|
||||
--m_size;
|
||||
m_items[m_size].~T();
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>>
|
||||
Vector<T, SmallVectorSize, Allocator>::erase(const iterator<> &pos) noexcept(useNoexcept) {
|
||||
Vector<T, SmallVectorSize, Allocator>::erase(iterator<> const &pos) noexcept(useNoexcept) {
|
||||
return erase(pos.offset());
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Result<typename Vector<T, SmallVectorSize, Allocator>::template iterator<T&, T*, false>>
|
||||
Vector<T, SmallVectorSize, Allocator>::erase(std::size_t pos) noexcept(useNoexcept) {
|
||||
Vector<T, SmallVectorSize, Allocator>::erase(size_t pos) noexcept(useNoexcept) {
|
||||
if (pos >= m_size) {
|
||||
return ox::Error(1, "Vector::erase failed: pos is greater than Vector size");
|
||||
}
|
||||
@@ -654,8 +657,8 @@ Vector<T, SmallVectorSize, Allocator>::erase(std::size_t pos) noexcept(useNoexce
|
||||
return begin() + pos;
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Error Vector<T, SmallVectorSize, Allocator>::unordered_erase(std::size_t pos)
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr Error Vector<T, SmallVectorSize, Allocator>::unordered_erase(size_t pos)
|
||||
noexcept(useNoexcept) {
|
||||
if (pos >= m_size) {
|
||||
return ox::Error(1);
|
||||
@@ -666,7 +669,7 @@ constexpr Error Vector<T, SmallVectorSize, Allocator>::unordered_erase(std::size
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr ox::Error Vector<T, SmallVectorSize, Allocator>::remove(MaybeView_t<T> const &val) {
|
||||
for (size_t i{}; auto const &v : *this) {
|
||||
if (v == val) {
|
||||
@@ -677,18 +680,18 @@ constexpr ox::Error Vector<T, SmallVectorSize, Allocator>::remove(MaybeView_t<T>
|
||||
return ox::Error{1, "element not found"};
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::reserve(std::size_t cap) noexcept(useNoexcept) {
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::reserve(size_t cap) noexcept(useNoexcept) {
|
||||
if (cap <= m_cap) {
|
||||
return;
|
||||
}
|
||||
const auto oldItems = m_items;
|
||||
const auto oldCap = m_cap;
|
||||
auto const oldItems = m_items;
|
||||
auto const oldCap = m_cap;
|
||||
m_cap = cap;
|
||||
this->allocate(&m_items, cap);
|
||||
if (oldItems) { // move over old items
|
||||
const auto itRange = ox::min(cap, m_size);
|
||||
for (std::size_t i = 0; i < itRange; ++i) {
|
||||
auto const itRange = ox::min(cap, m_size);
|
||||
for (size_t i = 0; i < itRange; ++i) {
|
||||
std::construct_at(&m_items[i], std::move(oldItems[i]));
|
||||
oldItems[i].~T();
|
||||
}
|
||||
@@ -696,17 +699,17 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::reserve(std::size_t cap) n
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::shrink_to_fit() noexcept(useNoexcept) {
|
||||
if (m_size == m_cap) {
|
||||
return;
|
||||
}
|
||||
const auto oldItems = m_items;
|
||||
const auto oldCap = m_cap;
|
||||
auto const oldItems = m_items;
|
||||
auto const oldCap = m_cap;
|
||||
m_cap = m_size;
|
||||
this->allocate(&m_items, m_size);
|
||||
if (oldItems) { // move over old items
|
||||
for (std::size_t i = 0; i < m_size; ++i) {
|
||||
for (size_t i = 0; i < m_size; ++i) {
|
||||
std::construct_at(&m_items[i], std::move(oldItems[i]));
|
||||
oldItems[i].~T();
|
||||
}
|
||||
@@ -714,26 +717,26 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::shrink_to_fit() noexcept(u
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, std::size_t SmallVectorSize, typename Allocator>
|
||||
template<typename T, size_t SmallVectorSize, typename Allocator>
|
||||
constexpr void Vector<T, SmallVectorSize, Allocator>::reserveInsert(
|
||||
std::size_t cap,
|
||||
std::size_t pos,
|
||||
std::size_t offset) noexcept(useNoexcept) {
|
||||
size_t cap,
|
||||
size_t pos,
|
||||
size_t offset) noexcept(useNoexcept) {
|
||||
if (cap <= m_cap) {
|
||||
return;
|
||||
}
|
||||
const auto oldItems = m_items;
|
||||
const auto oldCap = m_cap;
|
||||
auto const oldItems = m_items;
|
||||
auto const oldCap = m_cap;
|
||||
m_cap = cap;
|
||||
this->allocate(&m_items, cap);
|
||||
if (oldItems) { // move over old items
|
||||
auto itRange = ox::min(m_size, pos);
|
||||
for (std::size_t i = 0; i < itRange; ++i) {
|
||||
for (size_t i = 0; i < itRange; ++i) {
|
||||
std::construct_at(&m_items[i], std::move(oldItems[i]));
|
||||
oldItems[i].~T();
|
||||
}
|
||||
itRange = m_size;
|
||||
for (std::size_t i = pos; i < itRange; ++i) {
|
||||
for (size_t i = pos; i < itRange; ++i) {
|
||||
std::construct_at(&m_items[i + offset], std::move(oldItems[i]));
|
||||
oldItems[i].~T();
|
||||
}
|
||||
@@ -744,8 +747,8 @@ constexpr void Vector<T, SmallVectorSize, Allocator>::reserveInsert(
|
||||
|
||||
template<typename PlatSpec, typename T>
|
||||
[[nodiscard]]
|
||||
constexpr auto alignOf(const Vector<T>&) noexcept {
|
||||
const typename PlatSpec::size_t i = 0;
|
||||
constexpr auto alignOf(Vector<T> const&) noexcept {
|
||||
typename PlatSpec::size_t const i = 0;
|
||||
return PlatSpec::alignOf(i);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
# NEXT
|
||||
|
||||
* Add Get Info file dialog option in project explorer
|
||||
|
||||
# d2025.07.0
|
||||
|
||||
* Add sub-command for exporting TileSheets as PNG files.
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
static class: public keel::Module {
|
||||
public:
|
||||
static struct: keel::Module {
|
||||
|
||||
[[nodiscard]]
|
||||
ox::String id() const noexcept override {
|
||||
return ox::String{"net.drinkingtea.nostalgia.gfx"};
|
||||
@@ -59,31 +59,18 @@ static class: public keel::Module {
|
||||
ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
|
||||
return {
|
||||
// convert tilesheets to CompactTileSheets
|
||||
[](keel::Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) -> ox::Result<bool> {
|
||||
if (typeId == ox::ModelTypeId_v<TileSheetV1> ||
|
||||
typeId == ox::ModelTypeId_v<TileSheetV2> ||
|
||||
typeId == ox::ModelTypeId_v<TileSheetV3> ||
|
||||
typeId == ox::ModelTypeId_v<TileSheetV4> ||
|
||||
typeId == ox::ModelTypeId_v<TileSheetV5>) {
|
||||
OX_RETURN_ERROR(keel::convertBuffToBuff<CompactTileSheet>(
|
||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
[](keel::Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) -> ox::Result<bool> {
|
||||
if (typeId == ox::ModelTypeId_v<NostalgiaPalette> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV1> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV2> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV3> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV4> ||
|
||||
typeId == ox::ModelTypeId_v<PaletteV5>) {
|
||||
OX_RETURN_ERROR(keel::convertBuffToBuff<CompactPalette>(
|
||||
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
keel::transformRule<TileSheetV1, CompactTileSheet>,
|
||||
keel::transformRule<TileSheetV2, CompactTileSheet>,
|
||||
keel::transformRule<TileSheetV3, CompactTileSheet>,
|
||||
keel::transformRule<TileSheetV4, CompactTileSheet>,
|
||||
keel::transformRule<TileSheetV5, CompactTileSheet>,
|
||||
// convert palettes to CompactPalettes
|
||||
keel::transformRule<NostalgiaPalette, CompactPalette>,
|
||||
keel::transformRule<PaletteV1, CompactPalette>,
|
||||
keel::transformRule<PaletteV2, CompactPalette>,
|
||||
keel::transformRule<PaletteV3, CompactPalette>,
|
||||
keel::transformRule<PaletteV4, CompactPalette>,
|
||||
keel::transformRule<PaletteV5, CompactPalette>,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -109,8 +109,8 @@ static void convertSubsheet(
|
||||
dst.rows = src.rows;
|
||||
dst.pixels = std::move(src.pixels);
|
||||
++idIt;
|
||||
dst.subsheets.resize(src.subsheets.size());
|
||||
for (auto i = 0u; i < src.subsheets.size(); ++i) {
|
||||
dst.subsheets.reserveResize(src.subsheets.size());
|
||||
for (size_t i{}; i < src.subsheets.size(); ++i) {
|
||||
convertSubsheet(src.subsheets[i], dst.subsheets[i], idIt);
|
||||
}
|
||||
}
|
||||
@@ -136,8 +136,8 @@ static void convertSubsheet(
|
||||
dst.rows = src.rows;
|
||||
dst.pixels = std::move(src.pixels);
|
||||
++idIt;
|
||||
dst.subsheets.resize(src.subsheets.size());
|
||||
for (auto i = 0u; i < src.subsheets.size(); ++i) {
|
||||
dst.subsheets.reserveResize(src.subsheets.size());
|
||||
for (size_t i{}; i < src.subsheets.size(); ++i) {
|
||||
convertSubsheet(src.subsheets[i], dst.subsheets[i], idIt);
|
||||
}
|
||||
}
|
||||
@@ -173,8 +173,8 @@ static void convertSubsheet(
|
||||
} else {
|
||||
dst.pixels = std::move(src.pixels);
|
||||
}
|
||||
dst.subsheets.resize(src.subsheets.size());
|
||||
for (auto i = 0u; i < src.subsheets.size(); ++i) {
|
||||
dst.subsheets.reserveResize(src.subsheets.size());
|
||||
for (size_t i{}; i < src.subsheets.size(); ++i) {
|
||||
convertSubsheet(bpp, src.subsheets[i], dst.subsheets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
|
||||
namespace nostalgia::gfx {
|
||||
|
||||
TileSheetClipboard::Pixel::Pixel(uint16_t pColorIdx, ox::Point pPt) noexcept {
|
||||
colorIdx = pColorIdx;
|
||||
pt = pPt;
|
||||
}
|
||||
TileSheetClipboard::Pixel::Pixel(
|
||||
uint8_t const pColorIdx,
|
||||
ox::Point const pPt) noexcept:
|
||||
colorIdx(pColorIdx),
|
||||
pt(pPt) {}
|
||||
|
||||
|
||||
void TileSheetClipboard::addPixel(ox::Point const&pt, uint16_t colorIdx) noexcept {
|
||||
void TileSheetClipboard::addPixel(ox::Point const &pt, uint8_t colorIdx) noexcept {
|
||||
m_pixels.emplace_back(colorIdx, pt);
|
||||
}
|
||||
|
||||
@@ -22,43 +23,37 @@ const ox::Vector<TileSheetClipboard::Pixel> &TileSheetClipboard::pixels() const
|
||||
|
||||
|
||||
CutPasteCommand::CutPasteCommand(
|
||||
CommandId commandId,
|
||||
CommandId const commandId,
|
||||
TileSheet &img,
|
||||
TileSheet::SubSheetIdx subSheetIdx,
|
||||
ox::Point const&dstStart,
|
||||
ox::Point const &dstStart,
|
||||
ox::Point dstEnd,
|
||||
TileSheetClipboard const&cb):
|
||||
TileSheetClipboard const &cb):
|
||||
m_commandId(commandId),
|
||||
m_img(img),
|
||||
m_subSheetIdx(std::move(subSheetIdx)) {
|
||||
auto const&ss = getSubSheet(m_img, m_subSheetIdx);
|
||||
auto const &ss = getSubSheet(m_img, m_subSheetIdx);
|
||||
if (dstStart.x >= ss.columns * TileWidth || dstStart.y >= ss.rows * TileHeight) {
|
||||
throw ox::Exception{1, "paste starts beyond the bounds of target"};
|
||||
}
|
||||
dstEnd.x = std::min(ss.columns * TileWidth - 1, dstEnd.x);
|
||||
dstEnd.y = std::min(ss.rows * TileHeight - 1, dstEnd.y);
|
||||
for (auto const&p : cb.pixels()) {
|
||||
for (auto const &p : cb.pixels()) {
|
||||
auto const dstPt = p.pt + dstStart;
|
||||
if (dstPt.x <= dstEnd.x && dstPt.y <= dstEnd.y) {
|
||||
auto const idx = gfx::idx(ss, dstPt);
|
||||
m_changes.emplace_back(static_cast<uint32_t>(idx), p.colorIdx, getPixel(ss, idx));
|
||||
m_changes.emplace_back(static_cast<uint32_t>(idx), p.colorIdx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ox::Error CutPasteCommand::redo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto const &c : m_changes) {
|
||||
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.newPalIdx);
|
||||
}
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error CutPasteCommand::undo() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto const &c : m_changes) {
|
||||
subsheet.pixels[c.idx] = static_cast<uint8_t>(c.oldPalIdx);
|
||||
}
|
||||
swap();
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -66,8 +61,15 @@ int CutPasteCommand::commandId() const noexcept {
|
||||
return static_cast<int>(m_commandId);
|
||||
}
|
||||
|
||||
TileSheet::SubSheetIdx const&CutPasteCommand::subsheetIdx() const noexcept {
|
||||
TileSheet::SubSheetIdx const &CutPasteCommand::subsheetIdx() const noexcept {
|
||||
return m_subSheetIdx;
|
||||
}
|
||||
|
||||
void CutPasteCommand::swap() noexcept {
|
||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||
for (auto &c : m_changes) {
|
||||
std::swap(subsheet.pixels[c.idx], c.palIdx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
|
||||
struct Pixel {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.studio.TileSheetClipboard.Pixel";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
uint16_t colorIdx = 0;
|
||||
uint8_t colorIdx = 0;
|
||||
ox::Point pt;
|
||||
Pixel(uint16_t pColorIdx, ox::Point pPt) noexcept;
|
||||
Pixel(uint8_t pColorIdx, ox::Point pPt) noexcept;
|
||||
};
|
||||
protected:
|
||||
ox::Vector<Pixel> m_pixels;
|
||||
|
||||
public:
|
||||
void addPixel(ox::Point const &pt, uint16_t colorIdx) noexcept;
|
||||
void addPixel(ox::Point const &pt, uint8_t colorIdx) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<Pixel> const &pixels() const noexcept;
|
||||
@@ -49,12 +49,10 @@ class CutPasteCommand: public TileSheetCommand {
|
||||
private:
|
||||
struct Change {
|
||||
uint32_t idx = 0;
|
||||
uint16_t newPalIdx = 0;
|
||||
uint16_t oldPalIdx = 0;
|
||||
constexpr Change(uint32_t pIdx, uint16_t pNewPalIdx, uint16_t pOldPalIdx) noexcept {
|
||||
uint8_t palIdx = 0;
|
||||
constexpr Change(uint32_t const pIdx, uint8_t const pPalIdx) noexcept {
|
||||
idx = pIdx;
|
||||
newPalIdx = pNewPalIdx;
|
||||
oldPalIdx = pOldPalIdx;
|
||||
palIdx = pPalIdx;
|
||||
}
|
||||
};
|
||||
CommandId m_commandId;
|
||||
@@ -81,6 +79,9 @@ class CutPasteCommand: public TileSheetCommand {
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override;
|
||||
|
||||
private:
|
||||
void swap() noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -189,8 +189,4 @@ ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept;
|
||||
|
||||
ox::Result<ox::UPtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Result<char*> loadRom(ox::StringViewCR path = "") noexcept;
|
||||
|
||||
void unloadRom(char*) noexcept;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ class Module {
|
||||
virtual ox::Vector<PackTransform> packTransforms() const noexcept;
|
||||
};
|
||||
|
||||
void registerModule(Module const*mod) noexcept;
|
||||
void registerModule(Module const *mod) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<keel::Module const*> const &modules() noexcept;
|
||||
ox::Vector<Module const*> const &modules() noexcept;
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class Wrap {
|
||||
public:
|
||||
virtual ~Wrap() = default;
|
||||
[[nodiscard]]
|
||||
virtual ox::CStringView typeName() const noexcept = 0;
|
||||
virtual ox::StringLiteral typeName() const noexcept = 0;
|
||||
[[nodiscard]]
|
||||
virtual int typeVersion() const noexcept = 0;
|
||||
[[nodiscard]]
|
||||
@@ -48,7 +48,7 @@ class WrapRef final: public WrapT<T> {
|
||||
constexpr explicit WrapRef(T &obj): m_obj{obj} {}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::CStringView typeName() const noexcept override {
|
||||
ox::StringLiteral typeName() const noexcept override {
|
||||
return ox::ModelTypeName_v<T>;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class WrapInline final: public WrapT<T> {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ox::CStringView typeName() const noexcept override {
|
||||
ox::StringLiteral typeName() const noexcept override {
|
||||
return ox::ModelTypeName_v<T>;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class BaseConverter {
|
||||
constexpr virtual ~BaseConverter() noexcept = default;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr virtual ox::StringView srcTypeName() const noexcept = 0;
|
||||
constexpr virtual ox::StringLiteral srcTypeName() const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr virtual int srcTypeVersion() const noexcept = 0;
|
||||
@@ -154,7 +154,7 @@ class ConverterFunc final: public BaseConverter {
|
||||
using DstType = typename decltype(extractParams(Func))::Dst;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::StringView srcTypeName() const noexcept override {
|
||||
constexpr ox::StringLiteral srcTypeName() const noexcept override {
|
||||
return ox::ModelTypeName_v<SrcType>;
|
||||
}
|
||||
|
||||
@@ -253,19 +253,22 @@ template<typename DstType>
|
||||
ox::Result<DstType> convertObjToObj(
|
||||
Context &ctx,
|
||||
auto &src) noexcept {
|
||||
OX_REQUIRE_M(out, convert(ctx, WrapRef{src}, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
OX_REQUIRE_M(out,
|
||||
convert(ctx, WrapRef{src}, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
return std::move(wrapCast(*out));
|
||||
}
|
||||
|
||||
template<typename DstType>
|
||||
ox::Result<DstType> convert(Context &ctx, ox::BufferView const &src) noexcept {
|
||||
OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
OX_REQUIRE(out,
|
||||
convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
return std::move(wrapCast<DstType>(*out));
|
||||
}
|
||||
|
||||
template<typename DstType>
|
||||
ox::Error convert(Context &ctx, ox::BufferView const &buff, DstType &outObj) noexcept {
|
||||
OX_REQUIRE(out, convert(ctx, buff, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
OX_REQUIRE(out,
|
||||
convert(ctx, buff, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
outObj = std::move(wrapCast<DstType>(*out));
|
||||
return {};
|
||||
}
|
||||
@@ -280,7 +283,8 @@ ox::Error convertObjToObj(Context &ctx, auto &src, DstType &outObj) noexcept {
|
||||
template<typename DstType>
|
||||
ox::Result<ox::Buffer> convertBuffToBuff(
|
||||
Context &ctx, ox::BufferView const &src, ox::ClawFormat const fmt) noexcept {
|
||||
OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
OX_REQUIRE(out,
|
||||
convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
|
||||
return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ add_library(
|
||||
font.cpp
|
||||
popups/about.cpp
|
||||
popups/deleteconfirmation.cpp
|
||||
popups/fileinfo.cpp
|
||||
popups/makecopy.cpp
|
||||
popups/newdir.cpp
|
||||
popups/newmenu.cpp
|
||||
|
||||
126
src/olympic/studio/applib/src/popups/fileinfo.cpp
Normal file
126
src/olympic/studio/applib/src/popups/fileinfo.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
namespace studio {
|
||||
|
||||
FileInfo::FileInfo(Context &sctx) noexcept:
|
||||
Popup("File Info"),
|
||||
m_sctx(sctx) {}
|
||||
|
||||
ox::Error FileInfo::open(ox::StringParam filePath) noexcept {
|
||||
m_filePath = std::move(filePath);
|
||||
auto &fs = m_sctx.project->romFs();
|
||||
OX_REQUIRE(fileBuff, fs.read(m_filePath));
|
||||
auto [hdr, err] = keel::readAssetHeader(fileBuff);
|
||||
if (!err) {
|
||||
m_fileInfo.emplace(Info{
|
||||
.assetId = hdr.uuid.toString(),
|
||||
.typeName = std::move(hdr.clawHdr.typeName),
|
||||
.typeVersion = hdr.clawHdr.typeVersion,
|
||||
.format = [&hdr] {
|
||||
switch (hdr.clawHdr.fmt) {
|
||||
case ox::ClawFormat::Metal:
|
||||
return ox::StringLiteral{"Metal Claw"};
|
||||
case ox::ClawFormat::Organic:
|
||||
return ox::StringLiteral{"Organic Claw"};
|
||||
default:
|
||||
return ox::StringLiteral{"Other"};
|
||||
}
|
||||
}(),
|
||||
.dataSize = hdr.clawHdr.dataSize,
|
||||
});
|
||||
}
|
||||
Popup::open();
|
||||
return {};
|
||||
}
|
||||
|
||||
void FileInfo::draw(Context &sctx) noexcept {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(m_title.c_str());
|
||||
m_stage = Stage::Open;
|
||||
[[fallthrough]];
|
||||
case Stage::Open: {
|
||||
constexpr auto modalFlags =
|
||||
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
ig::centerNextWindow(sctx.tctx);
|
||||
auto open = true;
|
||||
if (ImGui::BeginPopupModal(m_title.c_str(), &open, modalFlags)) {
|
||||
drawTable();
|
||||
switch (auto const r = ig::PopupControlsOk(m_open, "Close")) {
|
||||
case ig::PopupResponse::None:
|
||||
break;
|
||||
case ig::PopupResponse::OK:
|
||||
response.emit(r);
|
||||
m_fileInfo.reset();
|
||||
m_filePath = ox::String{};
|
||||
close();
|
||||
break;
|
||||
case ig::PopupResponse::Cancel:
|
||||
break;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
if (!open) {
|
||||
m_stage = Stage::Closed;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileInfo::drawTable() const noexcept {
|
||||
ig::IDStackItem const idStackItem{"FileInfo"};
|
||||
ImGui::Text("%s", m_filePath.c_str());
|
||||
if (m_fileInfo && ImGui::BeginTable(
|
||||
"Table", 2,
|
||||
ImGuiTableFlags_Borders |
|
||||
ImGuiTableFlags_RowBg)) {
|
||||
ImGui::TableSetupColumn("Field", ImGuiTableColumnFlags_WidthFixed, 70);
|
||||
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_NoHide);
|
||||
// asset id
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Text("Asset ID:");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("%s", m_fileInfo->assetId.c_str());
|
||||
// typeName
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Text("Type Name:");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("%s", m_fileInfo->typeName.c_str());
|
||||
// typeVersion
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Text("Type Version:");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("%d", m_fileInfo->typeVersion);
|
||||
// format
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Text("Format:");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("%s", m_fileInfo->format.c_str());
|
||||
// size
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Text("Data Size:");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("%lluB", m_fileInfo->dataSize);
|
||||
ImGui::EndTable();
|
||||
} else {
|
||||
ImGui::Text("No information available");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
40
src/olympic/studio/applib/src/popups/fileinfo.hpp
Normal file
40
src/olympic/studio/applib/src/popups/fileinfo.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/string.hpp>
|
||||
|
||||
#include <studio/context.hpp>
|
||||
#include <studio/imguiutil.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
class FileInfo: public ig::Popup {
|
||||
private:
|
||||
Context &m_sctx;
|
||||
ox::String m_filePath;
|
||||
struct Info {
|
||||
ox::UUIDStr assetId;
|
||||
ox::String typeName;
|
||||
int typeVersion{};
|
||||
ox::StringLiteral format;
|
||||
// use manual sizing to work with %ull
|
||||
unsigned long long dataSize{};
|
||||
};
|
||||
ox::Optional<Info> m_fileInfo;
|
||||
|
||||
public:
|
||||
explicit FileInfo(Context &sctx) noexcept;
|
||||
|
||||
ox::Error open(ox::StringParam filePath) noexcept;
|
||||
|
||||
void draw(Context &sctx) noexcept override;
|
||||
|
||||
private:
|
||||
void drawTable() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -36,6 +36,13 @@ void ProjectExplorer::dirMoved(ox::StringViewCR src, ox::StringViewCR dst) const
|
||||
|
||||
void ProjectExplorer::fileContextMenu(ox::StringViewCR path) const noexcept {
|
||||
if (ImGui::BeginPopupContextItem("FileMenu", ImGuiPopupFlags_MouseButtonRight)) {
|
||||
if (ImGui::MenuItem("Open")) {
|
||||
fileChosen.emit(path);
|
||||
}
|
||||
if (ImGui::MenuItem("Get Info")) {
|
||||
getInfo.emit(path);
|
||||
}
|
||||
ImGui::Separator();
|
||||
if (ImGui::MenuItem("Delete")) {
|
||||
deleteItem.emit(path);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class ProjectExplorer final: public FileExplorer {
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> deleteItem;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> renameItem;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> makeCopy;
|
||||
ox::Signal<ox::Error(ox::StringViewCR)> getInfo;
|
||||
ox::Signal<ox::Error(ox::StringViewCR src, ox::StringViewCR dst)> moveDir;
|
||||
ox::Signal<ox::Error(ox::StringViewCR src, ox::StringViewCR dst)> moveItem;
|
||||
|
||||
|
||||
@@ -146,6 +146,7 @@ StudioUI::StudioUI(turbine::Context &tctx, ox::StringParam projectDataDir) noexc
|
||||
m_projectExplorer.addDir.connect(this, &StudioUI::addDir);
|
||||
m_projectExplorer.addItem.connect(this, &StudioUI::addFile);
|
||||
m_projectExplorer.deleteItem.connect(this, &StudioUI::deleteFile);
|
||||
m_projectExplorer.getInfo.connect(this, &StudioUI::getFileInfo);
|
||||
m_projectExplorer.renameItem.connect(this, &StudioUI::renameFile);
|
||||
m_projectExplorer.makeCopy.connect(this, &StudioUI::makeCopyDlg);
|
||||
m_projectExplorer.moveDir.connect(this, &StudioUI::queueDirMove);
|
||||
@@ -569,6 +570,10 @@ ox::Error StudioUI::deleteFile(ox::StringViewCR path) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error StudioUI::getFileInfo(ox::StringViewCR path) noexcept {
|
||||
return m_fileInfo.open(path);
|
||||
}
|
||||
|
||||
ox::Error StudioUI::renameFile(ox::StringViewCR path) noexcept {
|
||||
return m_renameFile.openPath(path);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "popups/newmenu.hpp"
|
||||
#include "popups/newproject.hpp"
|
||||
#include "projectexplorer.hpp"
|
||||
#include "popups/fileinfo.hpp"
|
||||
#include "popups/renamefile.hpp"
|
||||
|
||||
namespace studio {
|
||||
@@ -48,6 +49,7 @@ class StudioUI final: public ox::SignalHandler {
|
||||
NewMenu m_newMenu{keelCtx(m_tctx)};
|
||||
AboutPopup m_aboutPopup{m_tctx};
|
||||
DeleteConfirmation m_deleteConfirmation;
|
||||
FileInfo m_fileInfo{m_sctx};
|
||||
NewDir m_newDirDialog;
|
||||
ig::QuestionPopup m_closeFileConfirm{"Close File?", "This file has unsaved changes. Close?"};
|
||||
ig::QuestionPopup m_closeAppConfirm{
|
||||
@@ -62,10 +64,11 @@ class StudioUI final: public ox::SignalHandler {
|
||||
ig::QuestionPopup dlg{"Remove From Recents?", "Unable to load project. Remove from recent projects?"};
|
||||
size_t idx{};
|
||||
} m_removeRecentProject;
|
||||
ox::Array<Widget*, 11> const m_widgets {
|
||||
ox::Array<Widget*, 12> const m_widgets {
|
||||
&m_closeFileConfirm,
|
||||
&m_closeAppConfirm,
|
||||
&m_copyFilePopup,
|
||||
&m_fileInfo,
|
||||
&m_newMenu,
|
||||
&m_newProject,
|
||||
&m_aboutPopup,
|
||||
@@ -130,6 +133,8 @@ class StudioUI final: public ox::SignalHandler {
|
||||
|
||||
ox::Error deleteFile(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error getFileInfo(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error renameFile(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Error handleMoveFile(ox::StringViewCR oldPath, ox::StringViewCR newPath, ox::UUID const &id) noexcept;
|
||||
|
||||
Reference in New Issue
Block a user