using Qrakhen.Qamp.Core.Collections; namespace Qrakhen.Qamp.Core.Values.Objects; using T = ValueType; /// /// Wrapper to access values that are spread around the stack inside contexts /// public class Outer(Pointer target) : Obj(T.Outer) { private Value _stored = Value.Void; public Pointer Target = target; public bool IsClosed { get; private set; } /// /// Dynamic getter & setter that returns or writes to either the target value directly, /// or the stored value if this has been closed. /// public Value Value { get => IsClosed ? _stored : Target!.Get(); set { if (IsClosed) _stored = value; else Target.Set(value); } } public Value Close() { if (IsClosed) throw new Exception($"meh, something not right here (cant close already closed outer)"); _stored = Target!.Get(); IsClosed = true; return _stored; } }