mirror of
https://github.com/ACreTeam/ac-decomp
synced 2026-07-07 12:03:27 -04:00
Match TP debug TNodeLinkList, first pass TLinkList
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#ifndef DEFINE_H
|
||||
#define DEFINE_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
class JGadget_outMessage {
|
||||
public:
|
||||
typedef void (*MessageFunc)(const char*, int, const char*);
|
||||
|
||||
static void warning(const char*, int, const char*);
|
||||
|
||||
JGadget_outMessage(MessageFunc fn, const char* file, int line);
|
||||
~JGadget_outMessage();
|
||||
|
||||
JGadget_outMessage& operator<<(const char* str);
|
||||
|
||||
private:
|
||||
MessageFunc mMsgFunc;
|
||||
char mBuffer[256];
|
||||
char* mWrite_p;
|
||||
char* mFile;
|
||||
int mLine;
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define JGADGET_ASSERTWARN(cond) \
|
||||
((cond) || ((JGadget_outMessage(JGadget_outMessage::warning, __FILE__, __LINE__) << (#cond)), false))
|
||||
|
||||
#define JGADGET_EXITWARN(cond) \
|
||||
if (!(cond)) { JGadget_outMessage(JGadget_outMessage::warning, __FILE__, __LINE__) << (#cond), false; return false; }
|
||||
|
||||
#else
|
||||
|
||||
#define JGADGET_ASSERTWARN(cond) \
|
||||
((cond) || (false))
|
||||
|
||||
#define JGADGET_EXITWARN(cond) \
|
||||
if (!(cond)) { false; return false; }
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -4,25 +4,12 @@
|
||||
#include "types.h"
|
||||
|
||||
#include "JSystem/JUtility/JUTAssertion.h"
|
||||
#include "JSystem/JGadget/define.h"
|
||||
|
||||
namespace JGadget {
|
||||
|
||||
#define JGADGET_ASSERTWARN(cond) \
|
||||
if ((cond) == false) \
|
||||
{ \
|
||||
/*JGadget_outMessage msg(&warning);*/ \
|
||||
/*msg << (#cond);*/ \
|
||||
}
|
||||
namespace {
|
||||
|
||||
#define JGADGET_EXIT(cond) \
|
||||
if ((cond) == false) \
|
||||
{ \
|
||||
/*JGadget_outMessage msg(&warning);*/ \
|
||||
/*msg << (#cond);*/ \
|
||||
return false; \
|
||||
}
|
||||
|
||||
/* TODO: this definitely has a better place to live */
|
||||
template <typename T>
|
||||
class TPRIsEqual_pointer_ {
|
||||
public:
|
||||
@@ -36,6 +23,8 @@ private:
|
||||
const T* p_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class TLinkListNode {
|
||||
public:
|
||||
TLinkListNode() {
|
||||
@@ -43,10 +32,7 @@ public:
|
||||
this->pPrev_ = nullptr;
|
||||
}
|
||||
|
||||
~TLinkListNode() {
|
||||
JGADGET_ASSERTWARN(pNext_==NULL);
|
||||
JGADGET_ASSERTWARN(pPrev_==NULL);
|
||||
}
|
||||
~TLinkListNode();
|
||||
|
||||
TLinkListNode* getNext() const {
|
||||
return this->pNext_;
|
||||
@@ -56,10 +42,7 @@ public:
|
||||
return this->pPrev_;
|
||||
}
|
||||
|
||||
void clear_() {
|
||||
this->pNext_ = nullptr;
|
||||
this->pPrev_ = nullptr;
|
||||
}
|
||||
void clear_();
|
||||
|
||||
TLinkListNode* pNext_;
|
||||
TLinkListNode* pPrev_;
|
||||
@@ -67,14 +50,13 @@ public:
|
||||
|
||||
class TNodeLinkList {
|
||||
public:
|
||||
TNodeLinkList() { Initialize_(); }
|
||||
TNodeLinkList();
|
||||
~TNodeLinkList();
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
iterator() { this->p_ = nullptr; }
|
||||
iterator(TLinkListNode* node) { this->p_ = node; }
|
||||
iterator(const iterator& it) { this->p_ = it.p_; }
|
||||
|
||||
iterator& operator++() {
|
||||
this->p_ = this->p_->getNext();
|
||||
@@ -100,7 +82,6 @@ public:
|
||||
public:
|
||||
const_iterator(const TLinkListNode* node) { this->p_ = node; }
|
||||
const_iterator(iterator it) { this->p_ = it.p_; }
|
||||
const_iterator(const const_iterator& it) { this->p_ = it.p_; }
|
||||
|
||||
const const_iterator& operator++() {
|
||||
this->p_ = this->p_->getNext();
|
||||
@@ -123,7 +104,7 @@ public:
|
||||
iterator Find(const TLinkListNode* node);
|
||||
iterator Insert(iterator it, TLinkListNode* node);
|
||||
void Remove(TLinkListNode* node);
|
||||
template <typename Predicate> void Remove_if(Predicate predicate, TNodeLinkList& tList);
|
||||
template <typename Predicate> void Remove_if(Predicate predicate, TNodeLinkList& other);
|
||||
|
||||
s32 size() const { return this->size_; }
|
||||
bool empty() const { return this->size() == 0; }
|
||||
@@ -148,11 +129,7 @@ public:
|
||||
const_iterator end() const { return &this->oNode_; }
|
||||
|
||||
private:
|
||||
void Initialize_() {
|
||||
this->size_ = 0;
|
||||
this->oNode_.pNext_ = &this->oNode_;
|
||||
this->oNode_.pPrev_ = &this->oNode_;
|
||||
}
|
||||
void Initialize_();
|
||||
bool Iterator_isEnd_(const_iterator it) const { return &this->oNode_ == it.p_; }
|
||||
|
||||
s32 size_;
|
||||
@@ -165,6 +142,114 @@ bool operator!=(TNodeLinkList::iterator lhs, TNodeLinkList::iterator rhs) { retu
|
||||
bool operator==(TNodeLinkList::const_iterator lhs, TNodeLinkList::const_iterator rhs) { return lhs.p_ == rhs.p_; }
|
||||
bool operator!=(TNodeLinkList::const_iterator lhs, TNodeLinkList::const_iterator rhs) { return !(lhs == rhs); }
|
||||
|
||||
template <typename T, int O>
|
||||
class TLinkList : public TNodeLinkList {
|
||||
class iterator {
|
||||
public:
|
||||
iterator iterator(TNodeLinkList::iterator it) : mIt(it) { }
|
||||
|
||||
bool operator==(iterator other) { return (mIt == other.mIt); }
|
||||
bool operator!=(iterator other) { return !(*this == other); }
|
||||
iterator& operator++() {
|
||||
++mIt;
|
||||
return *this;
|
||||
}
|
||||
iterator& operator--() {
|
||||
--mIt;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T* operator->() const { return TLinkList::Element_toValue(TNodeLinkList::iterator::operator->(mIt)); }
|
||||
T& operator*() const {
|
||||
T* p = TLinkList::iterator::operator->();
|
||||
#line 541
|
||||
JUT_ASSERT(p!=0);
|
||||
return *p;
|
||||
}
|
||||
|
||||
private:
|
||||
TNodeLinkList::iterator mIt;
|
||||
};
|
||||
|
||||
class const_iterator {
|
||||
public:
|
||||
const_iterator iterator(TNodeLinkList::const_iterator it) : mIt(it) { }
|
||||
|
||||
bool operator==(const_iterator other) { return (mIt == other.mIt); }
|
||||
bool operator!=(const_iterator other) { return !(*this == other); }
|
||||
const_iterator& operator++() {
|
||||
++mIt;
|
||||
return *this;
|
||||
}
|
||||
const_iterator& operator--() {
|
||||
--mIt;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const T* operator->() const { return TLinkList::Element_toValue(TNodeLinkList::const_iterator::operator->(mIt)); }
|
||||
const T& operator*() const {
|
||||
T* p = TLinkList::const_iterator::operator->();
|
||||
#line 586
|
||||
JUT_ASSERT(p!=0);
|
||||
return *p;
|
||||
}
|
||||
|
||||
private:
|
||||
TNodeLinkList::const_iterator mIt;
|
||||
};
|
||||
|
||||
iterator Find(const T* p) { return TNodeLinkList::Find(TLinkList::Element_toNode(p)); }
|
||||
iterator Erase( T* p) { return TNodeLinkList::Erase(Element_toNode(p)); }
|
||||
iterator Insert(iterator it, T* p) { return TNodeLinkList::Insert(it, Element_toNode(p)); }
|
||||
void Remove(T* p) { TNodeLinkList::Remove(TLinkList::Element_toNode(p)); }
|
||||
void Push_front(T* p) { Insert(begin(), p); }
|
||||
void Push_back(T* p) { Insert(end(), p); }
|
||||
|
||||
T& front() {
|
||||
#line 642
|
||||
JUT_ASSERT(!empty());
|
||||
return *begin();
|
||||
}
|
||||
|
||||
T& back() {
|
||||
#line 652
|
||||
JUT_ASSERT(!empty());
|
||||
iterator itEnd = end();
|
||||
--itEnd;
|
||||
return *itEnd;
|
||||
}
|
||||
|
||||
iterator begin() { return TNodeLinkList::begin(); }
|
||||
const_iterator begin() const { return TNodeLinkList::begin(); }
|
||||
|
||||
iterator end() { return TNodeLinkList::end(); }
|
||||
const_iterator end() const { return TNodeLinkList::end(); }
|
||||
|
||||
static TLinkListNode* Element_toNode(T* p) {
|
||||
#line 753
|
||||
JUT_ASSERT(p!=0);
|
||||
return (TLinkListNode*)((char*)p + O);
|
||||
}
|
||||
|
||||
static const TLinkListNode* Element_toNode(const T* p) {
|
||||
#line 758
|
||||
JUT_ASSERT(p!=0);
|
||||
return (const TLinkListNode*)((const char*)p + O);
|
||||
}
|
||||
|
||||
static T* Element_toValue(TLinkListNode* p) {
|
||||
#line 763
|
||||
JUT_ASSERT(p!=0);
|
||||
return (T*)((char*)p - O);
|
||||
}
|
||||
|
||||
static const T* Element_toValue(const TLinkListNode* p) {
|
||||
#line 763
|
||||
JUT_ASSERT(p!=0);
|
||||
return (const T*)((const char*)p - O);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -52,11 +52,7 @@ namespace JUTAssertion
|
||||
#else
|
||||
|
||||
#define JUT_ASSERT(COND) \
|
||||
if ((COND) == false) \
|
||||
{ \
|
||||
JUTAssertion::showAssert(JUTAssertion::getSDevice(), __FILE__, __LINE__, #COND); \
|
||||
OSHalt("Halt"); \
|
||||
}
|
||||
((COND)) ? (void)0 : (JUTAssertion::showAssert(JUTAssertion::getSDevice(), __FILE__, __LINE__, #COND), OSHalt("Halt"));
|
||||
|
||||
#define JUT_ASSERT_F(COND, ...) \
|
||||
if ((COND) == false) \
|
||||
|
||||
@@ -19,8 +19,13 @@ void TNodeLinkList::Initialize_() {
|
||||
}
|
||||
|
||||
TNodeLinkList::iterator TNodeLinkList::erase(iterator it, iterator itEnd) {
|
||||
for (it; it != itEnd; ++it) {
|
||||
this->Erase(it.p_);
|
||||
TLinkListNode* cur = it.p_;
|
||||
TLinkListNode* end = itEnd.p_;
|
||||
TLinkListNode* next;
|
||||
|
||||
for (; cur != end; cur = next) {
|
||||
next = cur->pNext_;
|
||||
this->Erase(cur);
|
||||
}
|
||||
|
||||
return itEnd;
|
||||
@@ -76,13 +81,8 @@ void TNodeLinkList::splice(TNodeLinkList::iterator it, TNodeLinkList& rSrc, TNod
|
||||
void TNodeLinkList::splice(TNodeLinkList::iterator it, TNodeLinkList& rSrc, TNodeLinkList::iterator itSrc) {
|
||||
iterator itSrcNext = itSrc;
|
||||
++itSrcNext;
|
||||
bool invalid = true;
|
||||
|
||||
if (!(it == itSrc) && !(it == itSrcNext)) {
|
||||
invalid = false;
|
||||
}
|
||||
|
||||
if (!invalid) {
|
||||
if (((it == itSrc) || (it == itSrcNext)) == false) {
|
||||
TLinkListNode& node = *itSrc;
|
||||
|
||||
rSrc.Erase(&node);
|
||||
@@ -97,31 +97,13 @@ void TNodeLinkList::splice(iterator it, TNodeLinkList& rSrc) {
|
||||
JUT_ASSERT(rSrc.empty());
|
||||
}
|
||||
|
||||
void TNodeLinkList::Remove(TLinkListNode* node) {
|
||||
this->remove_if(TPRIsEqual_pointer_(node));
|
||||
}
|
||||
|
||||
template<typename Predicate>
|
||||
void TNodeLinkList::Remove_if(Predicate predicate, TNodeLinkList& tList) {
|
||||
iterator itBeg = this->begin();
|
||||
iterator it = itBeg;
|
||||
|
||||
while(!Iterator_isEnd_(it)) {
|
||||
if (predicate(*it) == true) {
|
||||
iterator itPrev = it;
|
||||
++it;
|
||||
tList.splice(tList.end(), *this, itPrev);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TNodeLinkList::iterator TNodeLinkList::Find(const TLinkListNode* node) {
|
||||
return std::find_if(this->begin(), this->end(), TPRIsEqual_pointer_(node));
|
||||
return std::find_if(this->begin(), this->end(), TPRIsEqual_pointer_<TLinkListNode>(node));
|
||||
}
|
||||
|
||||
#undef NULL
|
||||
#define NULL 0
|
||||
|
||||
TNodeLinkList::iterator TNodeLinkList::Insert(iterator it, TLinkListNode* p) {
|
||||
#line 300
|
||||
JUT_ASSERT(p!=0);
|
||||
@@ -131,8 +113,8 @@ TNodeLinkList::iterator TNodeLinkList::Insert(iterator it, TLinkListNode* p) {
|
||||
TLinkListNode* pItPrev = pIt->pPrev_;
|
||||
JUT_ASSERT(pItPrev!=0);
|
||||
|
||||
JUT_ASSERT(p->pNext_==NULL);
|
||||
JUT_ASSERT(p->pPrev_==NULL);
|
||||
JGADGET_ASSERTWARN(p->pNext_==NULL);
|
||||
JGADGET_ASSERTWARN(p->pPrev_==NULL);
|
||||
|
||||
p->pNext_ = pIt;
|
||||
p->pPrev_ = pItPrev;
|
||||
@@ -143,6 +125,9 @@ TNodeLinkList::iterator TNodeLinkList::Insert(iterator it, TLinkListNode* p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
#undef NULL
|
||||
#define NULL (void*)0;
|
||||
|
||||
TNodeLinkList::iterator TNodeLinkList::Erase(TLinkListNode* p) {
|
||||
#line 325
|
||||
JUT_ASSERT(!empty());
|
||||
@@ -159,38 +144,65 @@ TNodeLinkList::iterator TNodeLinkList::Erase(TLinkListNode* p) {
|
||||
return pNext;
|
||||
}
|
||||
|
||||
bool TNodeLinkList::Confirm() const {
|
||||
u32 u = 0;
|
||||
const_iterator itEnd(this->end());
|
||||
|
||||
#line 357
|
||||
JGADGET_EXIT(itEnd.p_==&oNode_)
|
||||
const_iterator it(this->begin());
|
||||
JGADGET_EXIT(it.p_==oNode_.pNext_); // #line 359
|
||||
void TNodeLinkList::Remove(TLinkListNode* node) {
|
||||
this->remove_if(TPRIsEqual_pointer_<TLinkListNode>(node));
|
||||
}
|
||||
|
||||
for (it; it != itEnd; ++it, ++u) {
|
||||
JGADGET_EXIT(u<size()); // #line 362
|
||||
const TLinkListNode* pIt = it.p_;
|
||||
JUT_ASSERT(pIt!=0); // #line 364
|
||||
JGADGET_EXIT(pIt->pNext_->pPrev_==pIt); // #line 365
|
||||
JGADGET_EXIT(pIt->pPrev_->pNext_==pIt); // #line 366
|
||||
}
|
||||
if (it.p_ == &this->oNode_) {
|
||||
JGADGET_EXIT(u==size()); // #line 369
|
||||
return true;
|
||||
template<typename Predicate>
|
||||
void TNodeLinkList::Remove_if(Predicate predicate, TNodeLinkList& tList) {
|
||||
iterator it = this->begin();
|
||||
|
||||
while(!Iterator_isEnd_(it)) {
|
||||
if (predicate(*it)) {
|
||||
iterator itPrev = it;
|
||||
++it;
|
||||
tList.splice(tList.end(), *this, itPrev);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TNodeLinkList::Confirm_iterator(const_iterator it) const {
|
||||
const_iterator itCur(this->begin());
|
||||
const_iterator itEnd(this->end());
|
||||
for (itCur; itCur != itEnd; ++itCur) {
|
||||
if (itCur==it) {
|
||||
return true;
|
||||
}
|
||||
bool TNodeLinkList::Confirm() const {
|
||||
u32 u = 0;
|
||||
const_iterator itEnd = this->end();
|
||||
|
||||
#line 357
|
||||
JGADGET_EXITWARN(itEnd.p_==&oNode_);
|
||||
const_iterator it = this->begin();
|
||||
JGADGET_EXITWARN(it.p_==oNode_.pNext_); // #line 359
|
||||
|
||||
for (; it != itEnd; ++it, ++u) {
|
||||
JGADGET_EXITWARN(u<size()); // #line 362
|
||||
const TLinkListNode* pIt = it.p_;
|
||||
JUT_ASSERT(pIt!=0); // #line 364
|
||||
#line 365
|
||||
JGADGET_EXITWARN(pIt->pNext_->pPrev_==pIt);
|
||||
JGADGET_EXITWARN(pIt->pPrev_->pNext_==pIt); // #line 366
|
||||
}
|
||||
|
||||
JGADGET_EXIT(it==itEnd); // #line 383
|
||||
#line 368
|
||||
JGADGET_EXITWARN(it.p_==&oNode_);
|
||||
JGADGET_EXITWARN(u==size());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TNodeLinkList::Confirm_iterator(const_iterator it) const {
|
||||
const_iterator itBegin = begin();
|
||||
const_iterator itEnd = end();
|
||||
|
||||
while (itBegin != itEnd) {
|
||||
if (itBegin == it) {
|
||||
return true;
|
||||
}
|
||||
|
||||
++itBegin;
|
||||
}
|
||||
|
||||
#line 383
|
||||
JGADGET_EXITWARN(it==itEnd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user