A game about forced loneliness, made by TACStudios
1using System; 2using System.Collections.Generic; 3 4namespace Unity.VisualScripting 5{ 6 public sealed class GraphStack : GraphPointer, IPoolable, IDisposable 7 { 8 #region Lifecycle 9 10 private GraphStack() { } 11 12 private void InitializeNoAlloc(IGraphRoot root, List<IGraphParentElement> parentElements, bool ensureValid) 13 { 14 Initialize(root); 15 16 Ensure.That(nameof(parentElements)).IsNotNull(parentElements); 17 18 foreach (var parentElement in parentElements) 19 { 20 if (!TryEnterParentElement(parentElement, out var error)) 21 { 22 if (ensureValid) 23 { 24 throw new GraphPointerException(error, this); 25 } 26 else 27 { 28 break; 29 } 30 } 31 } 32 } 33 34 internal static GraphStack New(IGraphRoot root, List<IGraphParentElement> parentElements) 35 { 36 var stack = GenericPool<GraphStack>.New(() => new GraphStack()); 37 stack.InitializeNoAlloc(root, parentElements, true); 38 return stack; 39 } 40 41 internal static GraphStack New(GraphPointer model) 42 { 43 var stack = GenericPool<GraphStack>.New(() => new GraphStack()); 44 stack.CopyFrom(model); 45 return stack; 46 } 47 48 public GraphStack Clone() 49 { 50 return New(this); 51 } 52 53 public void Dispose() 54 { 55 GenericPool<GraphStack>.Free(this); 56 } 57 58 void IPoolable.New() 59 { 60 } 61 62 void IPoolable.Free() 63 { 64 root = null; 65 parentStack.Clear(); 66 parentElementStack.Clear(); 67 graphStack.Clear(); 68 dataStack.Clear(); 69 debugDataStack.Clear(); 70 } 71 72 #endregion 73 74 #region Conversion 75 76 public override GraphReference AsReference() 77 { 78 return ToReference(); 79 } 80 81 public GraphReference ToReference() 82 { 83 return GraphReference.Intern(this); 84 } 85 86 internal void ClearReference() 87 { 88 GraphReference.ClearIntern(this); 89 } 90 91 #endregion 92 93 #region Traversal 94 95 public new void EnterParentElement(IGraphParentElement parentElement) 96 { 97 base.EnterParentElement(parentElement); 98 } 99 100 public bool TryEnterParentElement(IGraphParentElement parentElement) 101 { 102 return TryEnterParentElement(parentElement, out var error); 103 } 104 105 public bool TryEnterParentElementUnsafe(IGraphParentElement parentElement) 106 { 107 return TryEnterParentElement(parentElement, out var error, null, true); 108 } 109 110 public new void ExitParentElement() 111 { 112 base.ExitParentElement(); 113 } 114 115 #endregion 116 } 117}