mirror of
https://github.com/zeldaret/botw
synced 2026-07-31 07:56:30 -04:00
Initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <basis/seadTypes.h>
|
||||
#include <codec/seadHashCRC32.h>
|
||||
#include <container/seadTreeMap.h>
|
||||
|
||||
namespace ksys::util {
|
||||
|
||||
class StrTreeMapKey {
|
||||
public:
|
||||
const sead::SafeString& key() const { return mKey; }
|
||||
|
||||
// NON_MATCHING: stack
|
||||
void setKey(u32 hash, sead::SafeString key) {
|
||||
mKeyHash = hash;
|
||||
mKey = key;
|
||||
}
|
||||
|
||||
void setKey(const sead::SafeString& key) {
|
||||
setKey(sead::HashCRC32::calcStringHash(key.cstr()), key);
|
||||
}
|
||||
|
||||
s32 compare(const StrTreeMapKey& rhs) const {
|
||||
if (mKeyHash < rhs.mKeyHash)
|
||||
return -1;
|
||||
if (mKeyHash > rhs.mKeyHash)
|
||||
return 1;
|
||||
return mKey.compare(rhs.mKey);
|
||||
}
|
||||
|
||||
private:
|
||||
u32 mKeyHash = 0;
|
||||
sead::SafeString mKey;
|
||||
};
|
||||
|
||||
class StrTreeMapNode : public sead::TreeMapNode<StrTreeMapKey> {
|
||||
public:
|
||||
~StrTreeMapNode() override { ; }
|
||||
void erase_() override { mLeft = mRight = nullptr; }
|
||||
};
|
||||
|
||||
template <typename Node>
|
||||
class StrTreeMap : public sead::IntrusiveTreeMap<StrTreeMapKey, Node> {};
|
||||
|
||||
} // namespace ksys::util
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef SEAD_DEBUG
|
||||
#define KSYS_CHECK_SIZE_NX150(CLASS, SIZE)
|
||||
#else
|
||||
#define KSYS_CHECK_SIZE_NX150(CLASS, SIZE) static_assert(sizeof(CLASS) == SIZE)
|
||||
#endif
|
||||
|
||||
namespace ksys::util {
|
||||
|
||||
/// For storing an enum with a particular storage size when specifying the underlying type of the
|
||||
/// enum is not an option.
|
||||
template <typename Enum, typename Storage>
|
||||
struct SizedEnum {
|
||||
static_assert(std::is_enum<Enum>());
|
||||
static_assert(!std::is_enum<Storage>());
|
||||
|
||||
constexpr SizedEnum() = default;
|
||||
constexpr SizedEnum(Enum value) { *this = value; }
|
||||
constexpr operator Enum() const { return static_cast<Enum>(mValue); }
|
||||
constexpr SizedEnum& operator=(Enum value) {
|
||||
mValue = static_cast<Storage>(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Storage mValue;
|
||||
};
|
||||
|
||||
} // namespace ksys::util
|
||||
Reference in New Issue
Block a user