mirror of
https://github.com/zeldaret/botw
synced 2026-09-03 09:59:44 -04:00
ksys: Declutter Utils by creating new Utils/Container folder
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <basis/seadTypes.h>
|
||||
#include <codec/seadHashCRC32.h>
|
||||
#include <container/seadTreeMap.h>
|
||||
#include <prim/seadDelegate.h>
|
||||
|
||||
namespace ksys::util {
|
||||
|
||||
class StrTreeMapKey {
|
||||
public:
|
||||
StrTreeMapKey() = default;
|
||||
StrTreeMapKey(u32 key_hash, const sead::SafeString& key) : mKeyHash(key_hash), mKey(key) {}
|
||||
StrTreeMapKey(const sead::SafeString& key)
|
||||
: StrTreeMapKey(sead::HashCRC32::calcStringHash(key), key) {}
|
||||
|
||||
const sead::SafeString& key() const { return mKey; }
|
||||
|
||||
void setKey(const sead::SafeString& key) { *this = StrTreeMapKey{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:
|
||||
using KeyType = StrTreeMapKey;
|
||||
~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 <basis/seadTypes.h>
|
||||
#include "KingSystem/Utils/SafeDelete.h"
|
||||
|
||||
namespace ksys::util {
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
class UniqueArrayPtr {
|
||||
public:
|
||||
UniqueArrayPtr() = default;
|
||||
UniqueArrayPtr(const UniqueArrayPtr&) = delete;
|
||||
// Not movable either for now.
|
||||
UniqueArrayPtr(UniqueArrayPtr&&) = delete;
|
||||
~UniqueArrayPtr() { safeDeleteArray(mData); }
|
||||
|
||||
auto& operator=(const UniqueArrayPtr&) = delete;
|
||||
auto& operator=(UniqueArrayPtr&&) = delete;
|
||||
|
||||
T* data() const { return mData; }
|
||||
std::size_t size() const { return N; }
|
||||
|
||||
T* begin() const { return mData; }
|
||||
T* end() const { return mData + N; }
|
||||
T*& operator[](std::size_t i) const { return mData[i]; }
|
||||
|
||||
private:
|
||||
T* mData = new T[N];
|
||||
};
|
||||
|
||||
} // namespace ksys::util
|
||||
Reference in New Issue
Block a user