| | 1 | | using System; |
| | 2 | | using OsmSharp; |
| | 3 | | using OsmSharp.Streams.Filters; |
| | 4 | |
|
| | 5 | | namespace Itinero.IO.Osm.Streams; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// An OSM tags preprocessor. |
| | 9 | | /// </summary> |
| | 10 | | internal class OsmGeoTagsPreprocessor : OsmStreamFilter |
| | 11 | | { |
| | 12 | | private readonly Func<OsmGeo, bool> _action; |
| | 13 | |
|
| | 14 | | private OsmGeo? _current; |
| | 15 | |
|
| 5 | 16 | | public OsmGeoTagsPreprocessor(Func<OsmGeo, bool> action) |
| 5 | 17 | | { |
| 5 | 18 | | _action = action; |
| 5 | 19 | | } |
| | 20 | |
|
| | 21 | | public override bool MoveNext(bool ignoreNodes, bool ignoreWays, bool ignoreRelations) |
| 46 | 22 | | { |
| 46 | 23 | | _current = null; |
| | 24 | |
|
| 50 | 25 | | while (true) |
| 50 | 26 | | { |
| 60 | 27 | | if (!this.Source.MoveNext(ignoreNodes, ignoreWays, ignoreRelations)) return false; |
| | 28 | |
|
| 40 | 29 | | var current = this.Source.Current(); |
| 44 | 30 | | if (!_action(current)) continue; |
| | 31 | |
|
| 36 | 32 | | _current = current; |
| 36 | 33 | | break; |
| | 34 | | } |
| | 35 | |
|
| 36 | 36 | | return true; |
| 46 | 37 | | } |
| | 38 | |
|
| | 39 | | public override OsmGeo Current() |
| 36 | 40 | | { |
| 36 | 41 | | if (_current == null) |
| 0 | 42 | | throw new InvalidOperationException( |
| 0 | 43 | | $"Current is null, do {nameof(MoveNext)} first."); |
| | 44 | |
|
| 36 | 45 | | return _current; |
| 36 | 46 | | } |
| | 47 | |
|
| | 48 | | public override void Reset() |
| 8 | 49 | | { |
| 8 | 50 | | this.Source.Reset(); |
| 8 | 51 | | } |
| | 52 | |
|
| 3 | 53 | | public override bool CanReset => this.Source.CanReset; |
| | 54 | | } |