6#include "Misc/AssertionMacros.h"
11template <
class ContainerType>
22 checkSlow(CurrentLink);
23 CurrentLink = (ContainerType*)CurrentLink->GetNextLink();
32 FORCEINLINE TLinkedListIteratorBase operator++(
int)
40 FORCEINLINE
explicit operator bool()
const {
return CurrentLink !=
nullptr; }
43 ContainerType* CurrentLink;
47 return Lhs.CurrentLink == Rhs.CurrentLink;
49 FORCEINLINE
friend bool operator!=(
const TLinkedListIteratorBase& Lhs,
const TLinkedListIteratorBase& Rhs)
51 return Lhs.CurrentLink != Rhs.CurrentLink;
55template <
class ContainerType,
class ElementType>
64 FORCEINLINE ElementType& operator->()
const
66 checkSlow(this->CurrentLink);
67 return **(this->CurrentLink);
70 FORCEINLINE ElementType& operator*()
const
72 checkSlow(this->CurrentLink);
73 return **(this->CurrentLink);
77template <
class ContainerType,
class ElementType>
86 FORCEINLINE ElementType& operator->()
const
88 checkSlow(this->CurrentLink);
89 return *(this->CurrentLink);
92 FORCEINLINE ElementType& operator*()
const
94 checkSlow(this->CurrentLink);
95 return *(this->CurrentLink);
102template <
class ContainerType,
class ElementType,
template <
class,
class>
class IteratorType>
109 typedef IteratorType<ContainerType, ElementType>
TIterator;
110 typedef IteratorType<ContainerType, const ElementType> TConstIterator;
144 checkSlow(Before != NULL);
164 checkSlow(After != NULL);
184 checkSlow(Replace != NULL);
186 ContainerType**& ReplacePrev = Replace->PrevLink;
187 ContainerType*& ReplaceNext = Replace->NextLink;
223 Head = (ContainerType*)
this;
233 FORCEINLINE ContainerType** GetPrevLink()
const {
return PrevLink; }
235 FORCEINLINE ContainerType* GetNextLink()
const {
return NextLink; }
237 FORCEINLINE ContainerType* Next() {
return NextLink; }
247 FORCEINLINE
friend TConstIterator begin(
const ContainerType& List) {
return TConstIterator(
const_cast<ContainerType*
>(&List)); }
249 FORCEINLINE
friend TConstIterator end(
const ContainerType& List) {
return TConstIterator(
nullptr); }
257template <
class ElementType>
274 FORCEINLINE ElementType* operator->() {
return ∈ }
275 FORCEINLINE
const ElementType* operator->()
const {
return ∈ }
276 FORCEINLINE ElementType& operator*() {
return Element; }
277 FORCEINLINE
const ElementType& operator*()
const {
return Element; }
300template <
class ElementType>
310template <
class NodeType,
class ElementType>
317 FORCEINLINE
explicit operator bool()
const {
return CurrentNode !=
nullptr; }
321 checkSlow(CurrentNode);
322 CurrentNode = CurrentNode->GetNextNode();
326 TDoubleLinkedListIterator operator++(
int)
333 TDoubleLinkedListIterator& operator--()
335 checkSlow(CurrentNode);
336 CurrentNode = CurrentNode->GetPrevNode();
340 TDoubleLinkedListIterator operator--(
int)
348 ElementType& operator->()
const
350 checkSlow(CurrentNode);
351 return CurrentNode->GetValue();
354 ElementType& operator*()
const
356 checkSlow(CurrentNode);
357 return CurrentNode->GetValue();
360 NodeType* GetNode()
const
362 checkSlow(CurrentNode);
367 NodeType* CurrentNode;
369 friend bool operator==(
const TDoubleLinkedListIterator& Lhs,
const TDoubleLinkedListIterator& Rhs)
371 return Lhs.CurrentNode == Rhs.CurrentNode;
373 friend bool operator!=(
const TDoubleLinkedListIterator& Lhs,
const TDoubleLinkedListIterator& Rhs)
375 return Lhs.CurrentNode != Rhs.CurrentNode;
384template <
class ElementType>
396 const ElementType& GetValue()
const {
return Value; }
398 ElementType& GetValue() {
return Value; }
437 bool AddHead(TDoubleLinkedListNode* NewNode)
439 if (NewNode ==
nullptr)
445 if (HeadNode !=
nullptr)
447 NewNode->NextNode = HeadNode;
448 HeadNode->PrevNode = NewNode;
453 HeadNode = TailNode = NewNode;
469 bool AddTail(TDoubleLinkedListNode* NewNode)
471 if (NewNode ==
nullptr)
476 if (TailNode !=
nullptr)
478 TailNode->NextNode = NewNode;
479 NewNode->PrevNode = TailNode;
484 HeadNode = TailNode = NewNode;
505 bool InsertNode(TDoubleLinkedListNode* NewNode, TDoubleLinkedListNode* NodeToInsertBefore =
nullptr)
507 if (NewNode ==
nullptr)
512 if (NodeToInsertBefore ==
nullptr || NodeToInsertBefore == HeadNode)
517 NewNode->PrevNode = NodeToInsertBefore->PrevNode;
518 NewNode->NextNode = NodeToInsertBefore;
520 NodeToInsertBefore->PrevNode->NextNode = NewNode;
521 NodeToInsertBefore->PrevNode = NewNode;
547 if (NodeToRemove !=
nullptr)
552 checkSlow(NodeToRemove == HeadNode);
559 NodeToRemove->NextNode = NodeToRemove->PrevNode =
nullptr;
560 HeadNode = TailNode =
nullptr;
566 if (NodeToRemove == HeadNode)
568 HeadNode = HeadNode->NextNode;
569 HeadNode->PrevNode =
nullptr;
572 else if (NodeToRemove == TailNode)
574 TailNode = TailNode->PrevNode;
575 TailNode->NextNode =
nullptr;
579 NodeToRemove->NextNode->PrevNode = NodeToRemove->PrevNode;
580 NodeToRemove->PrevNode->NextNode = NodeToRemove->NextNode;
589 NodeToRemove->NextNode = NodeToRemove->PrevNode =
nullptr;
599 while (HeadNode !=
nullptr)
601 Node = HeadNode->NextNode;
606 HeadNode = TailNode =
nullptr;
637 while (Node !=
nullptr)
639 if (Node->GetValue() == InElement)
644 Node = Node->NextNode;
650 bool Contains(
const ElementType& InElement) {
return (
FindNode(InElement) !=
nullptr); }
658 bool IsEmpty()
const {
return ListSize == 0; }
665 int32
Num()
const {
return ListSize; }
667 void MoveTailAfterHead()
669 TailNode->PrevNode->NextNode =
nullptr;
670 auto* NewTailNode = TailNode->PrevNode;
672 TailNode->NextNode = HeadNode->NextNode;
673 HeadNode->NextNode->PrevNode = TailNode;
675 TailNode->PrevNode = HeadNode;
676 HeadNode->NextNode = TailNode;
678 TailNode = NewTailNode;
688 virtual void SetListSize(int32 NewListSize) { ListSize = NewListSize; }
691 TDoubleLinkedListNode* HeadNode;
692 TDoubleLinkedListNode* TailNode;
699 friend TConstIterator begin(
const TDoubleLinkedList& List) {
return TConstIterator(List.GetHead()); }
701 friend TConstIterator end(
const TDoubleLinkedList& List) {
return TConstIterator(
nullptr); }
711template <
class ElementType>
TDoubleLinkedListNode(const ElementType &InValue)
Definition: List.h:394
TDoubleLinkedListIterator< TDoubleLinkedListNode, ElementType > TIterator
Definition: List.h:417
TDoubleLinkedList()
Definition: List.h:421
void RemoveNode(TDoubleLinkedListNode *NodeToRemove, bool bDeleteNode=true)
Definition: List.h:545
void RemoveNode(const ElementType &InElement)
Definition: List.h:533
int32 Num() const
Definition: List.h:665
bool AddTail(const ElementType &InElement)
Definition: List.h:467
virtual void SetListSize(int32 NewListSize)
Definition: List.h:688
bool InsertNode(const ElementType &InElement, TDoubleLinkedListNode *NodeToInsertBefore=nullptr)
Definition: List.h:500
void Empty()
Definition: List.h:596
TDoubleLinkedListNode * GetHead() const
Definition: List.h:618
bool AddHead(const ElementType &InElement)
Definition: List.h:435
virtual ~TDoubleLinkedList()
Definition: List.h:424
bool IsEmpty() const
Definition: List.h:658
TDoubleLinkedListNode * FindNode(const ElementType &InElement)
Definition: List.h:634
TDoubleLinkedListNode * GetTail() const
Definition: List.h:626
TIntrusiveLinkedList()
Definition: List.h:307
ContainerType * NextLink
Definition: List.h:241
TLinkedListBase()
Definition: List.h:115
FORCEINLINE void Unlink()
Definition: List.h:122
ContainerType ** PrevLink
Definition: List.h:244
FORCEINLINE void LinkBefore(ContainerType *Before)
Definition: List.h:142
FORCEINLINE void LinkAfter(ContainerType *After)
Definition: List.h:162
IteratorType< ContainerType, ElementType > TIterator
Definition: List.h:109
FORCEINLINE bool IsLinked()
Definition: List.h:231
FORCEINLINE void LinkReplace(ContainerType *Replace)
Definition: List.h:182
FORCEINLINE void LinkHead(ContainerType *&Head)
Definition: List.h:214
TLinkedList()
Definition: List.h:264
TLinkedList(const ElementType &InElement)
Definition: List.h:271
FORCEINLINE void Next()
Definition: List.h:20
Definition: SnakeGame.Build.cs:6