| | | 1 | | using System; |
| | | 2 | | using System.Collections; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | |
| | | 5 | | namespace Itinero.Network.Tiles.Standalone.Global; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// A restriction on the network. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// A sequence of restricted edges that can either be prohibitive or obligatory. This can be used to represent the class |
| | | 12 | | /// </remarks> |
| | | 13 | | public class NetworkRestriction : IEnumerable<(EdgeId edge, bool forward)> |
| | | 14 | | { |
| | | 15 | | private readonly List<(EdgeId edge, bool forward)> _sequence; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Creates a new network turn restriction. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <param name="sequence">The sequence that is either prohibited or mandatory.</param> |
| | | 21 | | /// <param name="isProhibitory">Flag to set the restriction to prohibited or mandatory.</param> |
| | | 22 | | /// <param name="attributes">The attributes.</param> |
| | 1032 | 23 | | public NetworkRestriction(IEnumerable<(EdgeId edge, bool forward)> sequence, bool isProhibitory, |
| | 1032 | 24 | | IEnumerable<(string key, string value)> attributes) |
| | 1032 | 25 | | { |
| | 1032 | 26 | | _sequence = new List<(EdgeId edge, bool forward)>(sequence); |
| | 1032 | 27 | | if (_sequence.Count < 2) throw new ArgumentException("A restriction has to have at least 2 edges"); |
| | | 28 | | |
| | 1032 | 29 | | this.IsProhibitory = isProhibitory; |
| | 1032 | 30 | | this.Attributes = attributes; |
| | 1032 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Gets the number of edges. |
| | | 35 | | /// </summary> |
| | 4115 | 36 | | public int Count => _sequence.Count; |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Gets the edge at the given index. |
| | | 40 | | /// </summary> |
| | | 41 | | /// <param name="index">The index.</param> |
| | 2064 | 42 | | public (EdgeId edge, bool forward) this[int index] => _sequence[index]; |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Returns true if the restriction is negative. |
| | | 46 | | /// </summary> |
| | 1032 | 47 | | public bool IsProhibitory { get; } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// The attributes associated with the restriction. |
| | | 51 | | /// </summary> |
| | 1019 | 52 | | public IEnumerable<(string key, string value)> Attributes { get; } |
| | | 53 | | |
| | | 54 | | public IEnumerator<(EdgeId edge, bool forward)> GetEnumerator() |
| | 0 | 55 | | { |
| | 0 | 56 | | return _sequence.GetEnumerator(); |
| | 0 | 57 | | } |
| | | 58 | | |
| | | 59 | | IEnumerator IEnumerable.GetEnumerator() |
| | 0 | 60 | | { |
| | 0 | 61 | | return this.GetEnumerator(); |
| | 0 | 62 | | } |
| | | 63 | | } |