mirror of https://github.com/zeldaret/tp.git
linklist debug (#3025)
This commit is contained in:
parent
2b52bc59d0
commit
0e7b42e9ea
|
|
@ -55,9 +55,9 @@ private:
|
|||
JGadget_outMessage out(JGadget_outMessage::warning, __FILE__, line); \
|
||||
out << msg << (arg1) << (arg2) << (arg3) << (arg4);
|
||||
|
||||
#define JGADGET_EXITWARN(cond) \
|
||||
if (!(cond)) { \
|
||||
false; \
|
||||
#define JGADGET_EXITWARN(line, COND) \
|
||||
if (!(COND)) { \
|
||||
JGadget_outMessage(JGadget_outMessage::warning, __FILE__, line) << #COND, false; \
|
||||
return false; \
|
||||
}
|
||||
#else
|
||||
|
|
@ -65,6 +65,7 @@ private:
|
|||
#define JGADGET_WARNMSG(line, msg) (void)0
|
||||
#define JGADGET_WARNMSG1(line, msg, arg) (void)0
|
||||
#define JGADGET_WARNMSG4(line, msg, arg1, arg2, arg3, arg4) (void)0
|
||||
#define JGADGET_EXITWARN(line, COND) (void)0
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,88 +10,96 @@
|
|||
namespace JGadget {
|
||||
struct TLinkListNode {
|
||||
TLinkListNode() {
|
||||
mNext = NULL;
|
||||
mPrev = NULL;
|
||||
pNext_ = NULL;
|
||||
pPrev_ = NULL;
|
||||
}
|
||||
|
||||
~TLinkListNode() {}
|
||||
|
||||
TLinkListNode* getNext() const { return mNext; }
|
||||
TLinkListNode* getPrev() const { return mPrev; }
|
||||
TLinkListNode* getNext() const { return pNext_; }
|
||||
TLinkListNode* getPrev() const { return pPrev_; }
|
||||
void clear_() { pNext_ = NULL; pPrev_ = NULL; }
|
||||
|
||||
public:
|
||||
/* 0x0 */ TLinkListNode* mNext;
|
||||
/* 0x4 */ TLinkListNode* mPrev;
|
||||
/* 0x0 */ TLinkListNode* pNext_;
|
||||
/* 0x4 */ TLinkListNode* pPrev_;
|
||||
}; // Size: 0x8
|
||||
|
||||
struct TNodeLinkList {
|
||||
struct iterator {
|
||||
iterator() { node = NULL; }
|
||||
explicit iterator(TLinkListNode* pNode) { node = pNode; }
|
||||
iterator& operator=(const iterator& other) { node = other.node; return *this; }
|
||||
struct iterator : public std::iterator<std::bidirectional_iterator_tag, TLinkListNode, s32, TLinkListNode*, TLinkListNode&> {
|
||||
iterator() { p_ = NULL; }
|
||||
explicit iterator(TLinkListNode* pNode) { p_ = pNode; }
|
||||
iterator& operator=(const iterator& other) { p_ = other.p_; return *this; }
|
||||
|
||||
iterator& operator++() { node = node->getNext(); return *this; }
|
||||
iterator& operator--() { node = node->getPrev(); return *this; }
|
||||
iterator& operator++() { p_ = p_->getNext(); return *this; }
|
||||
iterator& operator--() { p_ = p_->getPrev(); return *this; }
|
||||
iterator operator++(int) { const iterator old(*this); (void)++*this; return old; }
|
||||
iterator operator--(int) { const iterator old(*this); (void)--*this; return old; }
|
||||
friend bool operator==(iterator a, iterator b) { return a.node == b.node; }
|
||||
friend bool operator==(iterator a, iterator b) { return a.p_ == b.p_; }
|
||||
friend bool operator!=(iterator a, iterator b) { return !(a == b); }
|
||||
|
||||
TLinkListNode* operator->() const { return node; }
|
||||
TLinkListNode& operator*() const { return *node; }
|
||||
TLinkListNode* operator->() const { return p_; }
|
||||
TLinkListNode& operator*() const {
|
||||
JUT_ASSERT(196, p_!=NULL);
|
||||
return *p_;
|
||||
}
|
||||
|
||||
public:
|
||||
/* 0x00 */ TLinkListNode* node;
|
||||
/* 0x00 */ TLinkListNode* p_;
|
||||
};
|
||||
|
||||
struct const_iterator {
|
||||
explicit const_iterator(TLinkListNode* pNode) { node = pNode; }
|
||||
explicit const_iterator(iterator it) { node = it.node; }
|
||||
explicit const_iterator(const TLinkListNode* pNode) { p_ = pNode; }
|
||||
explicit const_iterator(const iterator it) { p_ = it.p_; }
|
||||
|
||||
const_iterator& operator++() { node = node->getNext(); return *this; }
|
||||
const_iterator& operator--() { node = node->getPrev(); return *this; }
|
||||
const_iterator& operator++() { p_ = p_->getNext(); return *this; }
|
||||
const_iterator& operator--() { p_ = p_->getPrev(); return *this; }
|
||||
const_iterator operator++(int) { const const_iterator old(*this); (void)++*this; return old; }
|
||||
const_iterator operator--(int) { const const_iterator old(*this); (void)--*this; return old; }
|
||||
friend bool operator==(const_iterator a, const_iterator b) { return a.node == b.node; }
|
||||
friend bool operator==(const_iterator a, const_iterator b) { return a.p_ == b.p_; }
|
||||
friend bool operator!=(const_iterator a, const_iterator b) { return !(a == b); }
|
||||
|
||||
friend bool operator==(const_iterator a, iterator b) { return a.node == b.node; }
|
||||
friend bool operator==(const_iterator a, iterator b) { return a.p_ == b.p_; }
|
||||
friend bool operator!=(const_iterator a, iterator b) { return !(a == b); }
|
||||
|
||||
const TLinkListNode* operator->() const { return node; }
|
||||
const TLinkListNode& operator*() const { return *node; }
|
||||
const TLinkListNode* operator->() const { return p_; }
|
||||
const TLinkListNode& operator*() const { return *p_; }
|
||||
|
||||
public:
|
||||
/* 0x00 */ TLinkListNode* node;
|
||||
/* 0x00 */ const TLinkListNode* p_;
|
||||
};
|
||||
|
||||
TNodeLinkList() : ocObject_() { Initialize_(); }
|
||||
TNodeLinkList() : oNode_() { Initialize_(); }
|
||||
~TNodeLinkList();
|
||||
|
||||
void Initialize_() {
|
||||
count = 0;
|
||||
ocObject_.mNext = &ocObject_;
|
||||
ocObject_.mPrev = &ocObject_;
|
||||
oNode_.pNext_ = &oNode_;
|
||||
oNode_.pPrev_ = &oNode_;
|
||||
}
|
||||
|
||||
iterator begin() { return iterator(ocObject_.getNext()); }
|
||||
const_iterator begin() const { return const_iterator(ocObject_.getNext()); }
|
||||
iterator end() { return iterator(&ocObject_); }
|
||||
const_iterator end() const { return const_iterator((TLinkListNode*)(&ocObject_)); }
|
||||
iterator begin() { return iterator(oNode_.getNext()); }
|
||||
const_iterator begin() const { return const_iterator(oNode_.getNext()); }
|
||||
iterator end() { return iterator(&oNode_); }
|
||||
const_iterator end() const { return const_iterator((TLinkListNode*)(&oNode_)); }
|
||||
u32 size() const { return count; }
|
||||
bool empty() const { return size() == 0; }
|
||||
iterator pop_front() { return erase(begin()); }
|
||||
void clear() { erase(begin(), end()); }
|
||||
|
||||
iterator erase(JGadget::TNodeLinkList::iterator, JGadget::TNodeLinkList::iterator);
|
||||
iterator erase(JGadget::TNodeLinkList::iterator);
|
||||
void splice(JGadget::TNodeLinkList::iterator, JGadget::TNodeLinkList&,
|
||||
JGadget::TNodeLinkList::iterator);
|
||||
iterator Find(const JGadget::TLinkListNode*);
|
||||
iterator Insert(JGadget::TNodeLinkList::iterator, JGadget::TLinkListNode*);
|
||||
iterator Erase(JGadget::TLinkListNode*);
|
||||
void Remove(JGadget::TLinkListNode*);
|
||||
iterator erase(iterator, iterator);
|
||||
iterator erase(iterator);
|
||||
void splice(iterator, TNodeLinkList&);
|
||||
void splice(iterator, TNodeLinkList&, iterator);
|
||||
void splice(iterator, TNodeLinkList&, iterator, iterator);
|
||||
iterator Find(const TLinkListNode*);
|
||||
iterator Insert(iterator, TLinkListNode*);
|
||||
iterator Erase(TLinkListNode*);
|
||||
void Remove(TLinkListNode*);
|
||||
bool Confirm() const;
|
||||
bool Confirm_iterator(const_iterator) const;
|
||||
|
||||
bool Iterator_isEnd_(const_iterator it) const { return it.node == &ocObject_; }
|
||||
bool Iterator_isEnd_(const_iterator it) const { return it.p_ == &oNode_; }
|
||||
template <typename Predicate>
|
||||
void Remove_if(Predicate predicate, TNodeLinkList& tList) {
|
||||
iterator it = begin();
|
||||
|
|
@ -115,7 +123,7 @@ struct TNodeLinkList {
|
|||
|
||||
public:
|
||||
/* 0x00 */ u32 count;
|
||||
/* 0x04 */ TLinkListNode ocObject_;
|
||||
/* 0x04 */ TLinkListNode oNode_;
|
||||
}; // Size: 0xC
|
||||
|
||||
template <typename T, int I>
|
||||
|
|
@ -130,7 +138,7 @@ struct TLinkList : TNodeLinkList {
|
|||
//TODO: Probably fakematch? Not sure what's going on here exactly
|
||||
(TIterator<std::bidirectional_iterator_tag, T, s32, T*, T&>&)*this =
|
||||
(const TIterator<std::bidirectional_iterator_tag, T, s32, T*, T&>&)rhs;
|
||||
this->node = rhs.node;
|
||||
this->p_ = rhs.p_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
||||
|
||||
#include "JSystem/JGadget/linklist.h"
|
||||
#include "JSystem/JGadget/define.h"
|
||||
|
||||
namespace JGadget {
|
||||
namespace {
|
||||
template <typename T>
|
||||
class TPRIsEqual_pointer_ {
|
||||
public:
|
||||
|
|
@ -12,29 +15,45 @@ public:
|
|||
private:
|
||||
const T* p_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
JGadget::TNodeLinkList::~TNodeLinkList() {}
|
||||
JGadget::TNodeLinkList::~TNodeLinkList() {
|
||||
#if DEBUG
|
||||
Confirm();
|
||||
clear();
|
||||
JGADGET_ASSERTWARN(84, empty())
|
||||
oNode_.clear_();
|
||||
#endif
|
||||
}
|
||||
|
||||
JGadget::TNodeLinkList::iterator
|
||||
JGadget::TNodeLinkList::erase(JGadget::TNodeLinkList::iterator it) {
|
||||
JUT_ASSERT(102, it.p_!=&oNode_);
|
||||
iterator next = it;
|
||||
++next;
|
||||
return erase(it, next);
|
||||
}
|
||||
|
||||
JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::erase(iterator a, iterator b) {
|
||||
TLinkListNode* cur = a.node;
|
||||
TLinkListNode* end = b.node;
|
||||
TLinkListNode* cur = a.p_;
|
||||
TLinkListNode* end = b.p_;
|
||||
TLinkListNode* next;
|
||||
|
||||
for (; cur != end; cur = next) {
|
||||
next = cur->mNext;
|
||||
next = cur->pNext_;
|
||||
Erase(cur);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void JGadget::TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc) {
|
||||
JUT_ASSERT(146, this!=&rSrc);
|
||||
splice(it, rSrc, rSrc.begin(), rSrc.end());
|
||||
JUT_ASSERT(148, rSrc.empty());
|
||||
}
|
||||
|
||||
void JGadget::TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc, iterator itSrc) {
|
||||
iterator itSrcNext = itSrc;
|
||||
++itSrcNext;
|
||||
|
|
@ -48,24 +67,69 @@ void JGadget::TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc, iterator i
|
|||
}
|
||||
}
|
||||
|
||||
JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::Insert(iterator it, TLinkListNode* p) {
|
||||
TLinkListNode* pIt = it.node;
|
||||
TLinkListNode* pItPrev = pIt->mPrev;
|
||||
void JGadget::TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc, iterator itBegin, iterator itEnd) {
|
||||
s32 dist = 0;
|
||||
if (this == &rSrc) {
|
||||
if (itBegin == itEnd) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
dist = std::distance(itBegin, itEnd);
|
||||
if (dist == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
TLinkListNode* r31 = it.p_;
|
||||
TLinkListNode* r30 = itBegin.p_;
|
||||
TLinkListNode* r29 = itEnd.p_;
|
||||
TLinkListNode* r25 = r29->pPrev_;
|
||||
TLinkListNode* r24 = r30->pPrev_;
|
||||
r24->pNext_ = r29;
|
||||
r29->pPrev_ = r24;
|
||||
rSrc.count -= dist;
|
||||
TLinkListNode* r23 = r31->pPrev_;
|
||||
r23->pNext_ = r30;
|
||||
r30->pPrev_ = r23;
|
||||
r25->pNext_ = r31;
|
||||
r31->pPrev_ = r25;
|
||||
count += dist;
|
||||
}
|
||||
|
||||
p->mNext = pIt;
|
||||
p->mPrev = pItPrev;
|
||||
pIt->mPrev = p;
|
||||
pItPrev->mNext = p;
|
||||
JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::Find(const JGadget::TLinkListNode* p) {
|
||||
return std::find_if(begin(), end(), TPRIsEqual_pointer_<TLinkListNode>(p));
|
||||
}
|
||||
|
||||
JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::Insert(iterator it, TLinkListNode* p) {
|
||||
JUT_ASSERT(300, p!=NULL);
|
||||
TLinkListNode* pIt = it.p_;
|
||||
JUT_ASSERT(302, pIt!=NULL);
|
||||
TLinkListNode* pItPrev = pIt->pPrev_;
|
||||
JUT_ASSERT(305, pItPrev!=0);
|
||||
JGADGET_ASSERTWARN(307, p->pNext_==NULL);
|
||||
JGADGET_ASSERTWARN(308, p->pPrev_==NULL);
|
||||
|
||||
p->pNext_ = pIt;
|
||||
p->pPrev_ = pItPrev;
|
||||
pIt->pPrev_ = p;
|
||||
pItPrev->pNext_ = p;
|
||||
count++;
|
||||
return iterator(p);
|
||||
}
|
||||
|
||||
JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::Erase(TLinkListNode* p) {
|
||||
TLinkListNode* pNext = p->mNext;
|
||||
TLinkListNode* pPrev = p->mPrev;
|
||||
pNext->mPrev = pPrev;
|
||||
pPrev->mNext = pNext;
|
||||
JUT_ASSERT(325, !empty());
|
||||
JUT_ASSERT(326, p!=0);
|
||||
JUT_ASSERT(327, p!=&oNode_);
|
||||
TLinkListNode* pNext = p->pNext_;
|
||||
TLinkListNode* pPrev = p->pPrev_;
|
||||
JUT_ASSERT(330, pNext!=NULL);
|
||||
pNext->pPrev_ = pPrev;
|
||||
JUT_ASSERT(332, pPrev!=NULL);
|
||||
pPrev->pNext_ = pNext;
|
||||
count--;
|
||||
#if DEBUG
|
||||
p->clear_();
|
||||
#endif
|
||||
return iterator(pNext);
|
||||
}
|
||||
|
||||
|
|
@ -73,3 +137,34 @@ JGadget::TNodeLinkList::iterator JGadget::TNodeLinkList::Erase(TLinkListNode* p)
|
|||
void JGadget::TNodeLinkList::Remove(TLinkListNode* p) {
|
||||
remove_if(TPRIsEqual_pointer_<TLinkListNode>(p));
|
||||
}
|
||||
|
||||
bool JGadget::TNodeLinkList::Confirm() const {
|
||||
int u = 0;
|
||||
const_iterator itEnd = end();
|
||||
JGADGET_EXITWARN(357, itEnd.p_==&oNode_);
|
||||
const_iterator it = begin();
|
||||
JGADGET_EXITWARN(359, it.p_==oNode_.pNext_);
|
||||
for (; it != itEnd; ++it, ++u) {
|
||||
JGADGET_EXITWARN(362, u<size());
|
||||
const TLinkListNode* pIt = it.p_;
|
||||
JUT_ASSERT(364, pIt!=NULL);
|
||||
JGADGET_EXITWARN(365, pIt->pNext_->pPrev_==pIt);
|
||||
JGADGET_EXITWARN(366, pIt->pPrev_->pNext_==pIt);
|
||||
}
|
||||
JGADGET_EXITWARN(368, it.p_==&oNode_);
|
||||
JGADGET_EXITWARN(369, u==size());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JGadget::TNodeLinkList::Confirm_iterator(const_iterator it) const {
|
||||
const_iterator itBegin = begin();
|
||||
const_iterator itEnd = end();
|
||||
while (itBegin != itEnd) {
|
||||
if (itBegin == it) {
|
||||
return true;
|
||||
}
|
||||
++itBegin;
|
||||
}
|
||||
JGADGET_EXITWARN(383, it==itEnd);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue