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