diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-07-18 20:06:00 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-07-18 20:06:00 +0200 |
commit | f26f6c62202c77acf430225662dc7691212cdee3 (patch) | |
tree | e5f3a7f22f76cfe77a94431d24e1bfbad901c1e8 | |
parent | 838d7c636406a1529f4953e6fd3ec5a6fe8ed3c6 (diff) |
Core/Misc: Add splice/pop_front/pop_back to LinkedListHead
-rw-r--r-- | src/common/Threading/LockedQueue.h | 5 | ||||
-rw-r--r-- | src/server/shared/Dynamic/LinkedList.h | 44 |
2 files changed, 45 insertions, 4 deletions
diff --git a/src/common/Threading/LockedQueue.h b/src/common/Threading/LockedQueue.h index fb4a740c69e..25666db9358 100644 --- a/src/common/Threading/LockedQueue.h +++ b/src/common/Threading/LockedQueue.h @@ -77,10 +77,11 @@ public: if (_queue.empty()) return false; - if (!check.Process(_queue.front())) + decltype(auto) front = _queue.front(); + if (!check.Process(front)) return false; - result = std::move(_queue.front()); + result = std::move(front); _queue.pop_front(); return true; } diff --git a/src/server/shared/Dynamic/LinkedList.h b/src/server/shared/Dynamic/LinkedList.h index 4b9e0422a36..6fec8c98a3d 100644 --- a/src/server/shared/Dynamic/LinkedList.h +++ b/src/server/shared/Dynamic/LinkedList.h @@ -15,8 +15,8 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _LINKEDLIST -#define _LINKEDLIST +#ifndef TRINITYCORE_LINKED_LIST_H +#define TRINITYCORE_LINKED_LIST_H #include "Define.h" #include <iterator> @@ -35,6 +35,12 @@ class LinkedListElement public: LinkedListElement() : iNext(nullptr), iPrev(nullptr) { } + bool isInList() const + { + return iNext != nullptr /*unlinked element*/ + && iNext != this /*list head*/; + } + LinkedListElement * next() { return iNext; } LinkedListElement const* next() const { return iNext; } LinkedListElement * prev() { return iPrev; } @@ -110,6 +116,16 @@ class LinkedListHead iHeader.insertBefore(pElem); } + void pop_front() + { + front_impl<LinkedListElement>()->delink(); + } + + void pop_back() + { + back_impl<LinkedListElement>()->delink(); + } + uint32 size() const { if (!iSize) @@ -156,6 +172,11 @@ class LinkedListHead return static_cast<pointer>(_Ptr); } + base_pointer node() const + { + return _Ptr; + } + Iterator& operator++() { // preincrement _Ptr = _Ptr->next(); @@ -214,6 +235,25 @@ class LinkedListHead template <typename T> Iterator<T const> end_impl() const { return Iterator<T const>(&iHeader); } + void splice_impl(LinkedListElement* where, LinkedListElement* first, LinkedListElement* last) + { + LinkedListElement* wherePrev = where->iPrev; + LinkedListElement* firstPrev = first->iPrev; + LinkedListElement* lastPrev = last->iPrev; + lastPrev->iNext = where; + where->iPrev = lastPrev; + firstPrev->iNext = last; + last->iPrev = firstPrev; + wherePrev->iNext = first; + first->iPrev = wherePrev; + } + + template <typename T> + void splice_impl(Iterator<T> where, Iterator<T> first, Iterator<T> last) + { + splice_impl(where.node(), first.node(), last.node()); + } + private: LinkedListHead(LinkedListHead const&) = delete; LinkedListHead(LinkedListHead&&) = delete; |