UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMTree.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
8
9namespace Verse
10{
11template <typename DerivedType>
12struct TIntrusiveTree
13{
18
21 {
22 if (Parent)
23 {
24 if (Parent->LastChild)
25 {
26 Prev.Set(Context, Parent->LastChild.Get());
27 Parent->LastChild->Next.Set(Context, This());
28 }
29 Parent->LastChild.Set(Context, This());
30 }
31 }
32
33 template <bool bTransactional>
34 void Detach(FAllocationContext Context)
35 {
36 if (Parent && Parent->LastChild.Get() == This())
37 {
39 Parent->LastChild.template Set<bTransactional>(Context, Prev.Get());
40 }
41 if (Prev)
42 {
43 V_DIE_UNLESS(Prev->Next.Get() == This());
44 Prev->Next.template Set<bTransactional>(Context, Next.Get());
45 }
46 if (Next)
47 {
48 V_DIE_UNLESS(Next->Prev.Get() == This());
49 Next->Prev.template Set<bTransactional>(Context, Prev.Get());
50 }
53 }
54
55 void Detach(FAllocationContext Context)
56 {
58 }
59
60 void DetachTransactionally(FAllocationContext Context)
61 {
63 }
64
65 // Visit each element of the subtree rooted at `this`.
66 template <typename FunctionType>
67 void ForEach(FunctionType&& Function)
68 {
69 if (LIKELY(!LastChild.Get()))
70 {
71 Function(*This());
72 return;
73 }
74
76 ToVisit.Push(This());
77 while (ToVisit.Num())
78 {
79 DerivedType* Derived = ToVisit.Pop();
81 for (DerivedType* Child = Derived->LastChild.Get(); Child; Child = Child->Prev.Get())
82 {
83 ToVisit.Push(Child);
84 }
85 }
86 }
87
88 DerivedType* This()
89 {
90 return static_cast<DerivedType*>(this);
91 }
92
93 template <typename TVisitor>
94 void VisitReferencesImpl(TVisitor& Visitor)
95 {
96 Visitor.Visit(Parent, TEXT("Parent"));
97 Visitor.Visit(LastChild, TEXT("LastChild"));
98 Visitor.Visit(Prev, TEXT("Prev"));
99 Visitor.Visit(Next, TEXT("Next"));
100 }
101};
102} // namespace Verse
103
104#endif
EForEachResult ForEach(T &Array, const PREDICATE_CLASS &Predicate)
Definition AISense_Sight.cpp:60
#define LIKELY(x)
Definition CityHash.cpp:107
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition Array.h:670
UE_NODEBUG UE_FORCEINLINE_HINT void Push(ElementType &&Item)
Definition Array.h:1224
@ Visitor
Definition XmppMultiUserChat.h:94
Definition Archive.h:36