mirror of
https://github.com/thunderbrewhq/squall.git
synced 2026-02-04 00:49:08 +00:00
feat(list): add TSList::IsEmpty
This commit is contained in:
parent
d590e2e94f
commit
b52736a360
2 changed files with 26 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ class TSList {
|
||||||
T* DeleteNode(T* ptr);
|
T* DeleteNode(T* ptr);
|
||||||
T* Head();
|
T* Head();
|
||||||
void InitializeTerminator();
|
void InitializeTerminator();
|
||||||
|
bool IsEmpty();
|
||||||
bool IsLinked(T* ptr);
|
bool IsLinked(T* ptr);
|
||||||
TSLink<T>* Link(const T* ptr);
|
TSLink<T>* Link(const T* ptr);
|
||||||
void LinkNode(T* ptr, uint32_t linktype, T* existingptr);
|
void LinkNode(T* ptr, uint32_t linktype, T* existingptr);
|
||||||
|
|
@ -96,6 +97,11 @@ void TSList<T, TGetLink>::InitializeTerminator() {
|
||||||
this->m_terminator.m_next = reinterpret_cast<T*>(~reinterpret_cast<uintptr_t>(&this->m_terminator));
|
this->m_terminator.m_next = reinterpret_cast<T*>(~reinterpret_cast<uintptr_t>(&this->m_terminator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class TGetLink>
|
||||||
|
bool TSList<T, TGetLink>::IsEmpty() {
|
||||||
|
return this->Head() == nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template <class T, class TGetLink>
|
template <class T, class TGetLink>
|
||||||
bool TSList<T, TGetLink>::IsLinked(T* ptr) {
|
bool TSList<T, TGetLink>::IsLinked(T* ptr) {
|
||||||
return TGetLink::Link(ptr, this->m_linkoffset)->IsLinked();
|
return TGetLink::Link(ptr, this->m_linkoffset)->IsLinked();
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,26 @@ TEST_CASE("TSList::Head", "[list]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("TSList::IsEmpty", "[list]") {
|
||||||
|
SECTION("returns true if just initialized") {
|
||||||
|
STORM_LIST(TestListNode) list;
|
||||||
|
CHECK(list.IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("returns false if there are linked items") {
|
||||||
|
STORM_LIST(TestListNode) list;
|
||||||
|
list.NewNode(STORM_LIST_TAIL, 0, 0);
|
||||||
|
CHECK_FALSE(list.IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("returns true after clearing a populated list") {
|
||||||
|
STORM_LIST(TestListNode) list;
|
||||||
|
list.NewNode(STORM_LIST_TAIL, 0, 0);
|
||||||
|
list.Clear();
|
||||||
|
CHECK(list.IsEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("TSList::LinkToHead", "[list]") {
|
TEST_CASE("TSList::LinkToHead", "[list]") {
|
||||||
SECTION("links node to head correctly") {
|
SECTION("links node to head correctly") {
|
||||||
STORM_LIST(TestListNode) list;
|
STORM_LIST(TestListNode) list;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue