Match TP debug TNodeLinkList, first pass TLinkList

This commit is contained in:
Cuyler36
2023-12-02 12:24:24 -05:00
parent fa466b571b
commit 1e3b101bbe
4 changed files with 239 additions and 95 deletions
+51
View File
@@ -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
+117 -32
View File
@@ -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
+1 -5
View File
@@ -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) \