Files
botw/lib/sead/include/container/seadListImpl.h
T
Léo Lam 18c60323a9 Switch to subrepos
git subrepo clone https://github.com/open-ead/sead lib/sead

subrepo:
  subdir:   "lib/sead"
  merged:   "1b66e825d"
upstream:
  origin:   "https://github.com/open-ead/sead"
  branch:   "master"
  commit:   "1b66e825d"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

git subrepo clone (merge) https://github.com/open-ead/nnheaders lib/NintendoSDK

subrepo:
  subdir:   "lib/NintendoSDK"
  merged:   "9ee21399f"
upstream:
  origin:   "https://github.com/open-ead/nnheaders"
  branch:   "master"
  commit:   "9ee21399f"
git-subrepo:
  version:  "0.4.3"
  origin:   "ssh://git@github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

git subrepo clone https://github.com/open-ead/agl lib/agl

subrepo:
  subdir:   "lib/agl"
  merged:   "7c063271b"
upstream:
  origin:   "https://github.com/open-ead/agl"
  branch:   "master"
  commit:   "7c063271b"
git-subrepo:
  version:  "0.4.3"
  origin:   "ssh://git@github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

git subrepo clone https://github.com/open-ead/EventFlow lib/EventFlow

subrepo:
  subdir:   "lib/EventFlow"
  merged:   "c35d21b34"
upstream:
  origin:   "https://github.com/open-ead/EventFlow"
  branch:   "master"
  commit:   "c35d21b34"
git-subrepo:
  version:  "0.4.3"
  origin:   "ssh://git@github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"
2022-03-21 21:31:42 +01:00

122 lines
2.9 KiB
C++

#ifndef SEAD_LIST_IMPL_H_
#define SEAD_LIST_IMPL_H_
#include <basis/seadTypes.h>
namespace sead
{
class Random;
class ListNode
{
public:
ListNode* next() const { return mNext; }
ListNode* prev() const { return mPrev; }
bool isLinked() const { return mNext || mPrev; }
private:
friend class ListImpl;
void init_() { *this = {}; }
void insertBack_(ListNode* node);
void insertFront_(ListNode* node);
void erase_();
ListNode* mPrev = nullptr;
ListNode* mNext = nullptr;
};
class ListImpl
{
public:
__attribute__((always_inline)) ListImpl() : mStartEnd(), mCount(0)
{
mStartEnd.mNext = &mStartEnd;
mStartEnd.mPrev = &mStartEnd;
}
bool isEmpty() const { return mCount == 0; }
s32 size() const { return mCount; }
void reverse();
void shuffle();
void shuffle(Random* random);
bool checkLinks() const;
protected:
using CompareCallbackImpl = int (*)(const void*, const void*);
template <class T, class ComparePredicate>
void sort(s32 offset, const ComparePredicate& cmp)
{
this->mergeSort<T, ComparePredicate>(offset, cmp);
}
template <class T, class ComparePredicate>
void mergeSort(s32 offset, const ComparePredicate& cmp)
{
this->mergeSortImpl_<T, ComparePredicate>(mStartEnd.mNext, mStartEnd.mPrev, size(), offset,
cmp);
}
void pushBack(ListNode* item)
{
mStartEnd.insertFront_(item);
++mCount;
}
void pushFront(ListNode* item)
{
mStartEnd.insertBack_(item);
++mCount;
}
ListNode* popBack();
ListNode* popFront();
void insertBefore(ListNode* node, ListNode* node_to_insert)
{
node->insertFront_(node_to_insert);
++mCount;
}
void insertAfter(ListNode* node, ListNode* node_to_insert)
{
node->insertBack_(node_to_insert);
++mCount;
}
void erase(ListNode* item)
{
item->erase_();
--mCount;
}
ListNode* front() const { return mCount >= 1 ? mStartEnd.mNext : nullptr; }
ListNode* back() const { return mCount >= 1 ? mStartEnd.mPrev : nullptr; }
ListNode* nth(int n) const;
s32 indexOf(const ListNode*) const;
void swap(ListNode* n1, ListNode* n2);
void moveAfter(ListNode* basis, ListNode* n);
void moveBefore(ListNode* basis, ListNode* n);
ListNode* find(const void* ptr, s32 offset, CompareCallbackImpl cmp) const;
void uniq(s32 offset, CompareCallbackImpl cmp);
void clear();
// FIXME: this should take an rvalue reference for predicate.
template <class T, class ComparePredicate>
static void mergeSortImpl_(ListNode* front, ListNode* back, s32 num, s32 offset,
const ComparePredicate& predicate);
protected:
ListNode mStartEnd;
s32 mCount;
};
} // namespace sead
#endif // SEAD_LIST_IMPL_H_