linklist match

stolen from Cuyler & ac-decomp
This commit is contained in:
Jasper St. Pierre
2023-12-02 13:01:36 -08:00
parent fe69529cbd
commit a663f3c824
3 changed files with 94 additions and 18 deletions
+21
View File
@@ -38,6 +38,7 @@ struct TNodeLinkList {
struct const_iterator {
const_iterator(TLinkListNode* pNode) { node = pNode; }
const_iterator(iterator it) { node = it.node; }
const_iterator& operator++() { node = node->getNext(); return *this; }
const_iterator& operator--() { node = node->getPrev(); return *this; }
@@ -76,6 +77,26 @@ struct TNodeLinkList {
iterator Erase(JGadget::TLinkListNode*);
void Remove(JGadget::TLinkListNode*);
bool Iterator_isEnd_(const_iterator it) const { return it.node == &ocObject_; }
template <typename Predicate> void Remove_if(Predicate predicate, TNodeLinkList& tList) {
iterator it = begin();
while (!Iterator_isEnd_(it)) {
if (predicate(*it)) {
iterator itPrev = it;
++it;
tList.splice(tList.end(), *this, itPrev);
} else {
++it;
}
}
}
template <typename Predicate> void remove_if(Predicate predicate) {
TNodeLinkList list;
Remove_if(predicate, list);
}
public:
/* 0x00 */ u32 count;
/* 0x04 */ TLinkListNode ocObject_;