Initial commit

This commit is contained in:
Léo Lam
2020-06-05 17:09:06 +02:00
commit 2de366be0f
52 changed files with 113067 additions and 0 deletions
+45
View File
@@ -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
+31
View File
@@ -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