// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using JetBrains.Annotations; namespace osu.Game.Database { /// /// A wrapper to provide access to database backed classes in a thread-safe manner. /// /// The databased type. public abstract class Live : IEquatable> where T : class, IHasGuidPrimaryKey { public Guid ID { get; } /// /// Perform a read operation on this live object. /// /// The action to perform. public abstract void PerformRead([InstantHandle] Action perform); /// /// Perform a read operation on this live object. /// /// The action to perform. public abstract TReturn PerformRead([InstantHandle] Func perform); /// /// Perform a write operation on this live object. /// /// The action to perform. public abstract void PerformWrite([InstantHandle] Action perform); /// /// Whether this instance is tracking data which is managed by the database backing. /// public abstract bool IsManaged { get; } /// /// Resolve the value of this instance on the update thread. /// /// /// After resolving, the data should not be passed between threads. /// public abstract T Value { get; } protected Live(Guid id) { ID = id; } public bool Equals(Live? other) => ID == other?.ID; public override string ToString() => PerformRead(i => i.ToString()); } }