| | | 1 | | //======================================================================= |
| | | 2 | | // ObstacleToken.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | |
| | | 10 | | namespace GridForge; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Opaque process-unique identity for one obstacle registration lifetime. |
| | | 14 | | /// </summary> |
| | | 15 | | public readonly struct ObstacleToken : IEquatable<ObstacleToken> |
| | | 16 | | { |
| | | 17 | | private readonly long _value; |
| | | 18 | | |
| | | 19 | | internal ObstacleToken(long value) |
| | | 20 | | { |
| | 511 | 21 | | _value = value; |
| | 511 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Indicates whether this token identifies an allocated obstacle registration. |
| | | 26 | | /// </summary> |
| | 1344 | 27 | | public bool IsValid => _value != 0; |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | 107 | 30 | | public bool Equals(ObstacleToken other) => _value == other._value; |
| | | 31 | | |
| | | 32 | | /// <inheritdoc /> |
| | 2 | 33 | | public override bool Equals(object? obj) => obj is ObstacleToken other && Equals(other); |
| | | 34 | | |
| | | 35 | | /// <inheritdoc /> |
| | 1103 | 36 | | public override int GetHashCode() => _value.GetHashCode(); |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Returns the runtime token value for diagnostics. |
| | | 40 | | /// </summary> |
| | 1 | 41 | | public override string ToString() => _value.ToString(); |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Compares two obstacle registration tokens for equality. |
| | | 45 | | /// </summary> |
| | 2 | 46 | | public static bool operator ==(ObstacleToken left, ObstacleToken right) => left.Equals(right); |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Compares two obstacle registration tokens for inequality. |
| | | 50 | | /// </summary> |
| | 2 | 51 | | public static bool operator !=(ObstacleToken left, ObstacleToken right) => !left.Equals(right); |
| | | 52 | | } |