| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.IO; |
| | 3 | | using System.Linq; |
| | 4 | | using System.Runtime.CompilerServices; |
| | 5 | | using Itinero.Data; |
| | 6 | | using Itinero.Data.Usage; |
| | 7 | | using Itinero.Indexes; |
| | 8 | | using Itinero.IO; |
| | 9 | | using Itinero.Network; |
| | 10 | | using Itinero.Network.Mutation; |
| | 11 | | using Itinero.Network.Serialization; |
| | 12 | | using Itinero.Profiles; |
| | 13 | |
|
| | 14 | | [assembly: InternalsVisibleTo("Itinero.Tests")] |
| | 15 | | [assembly: InternalsVisibleTo("Itinero.Tests.Benchmarks")] |
| | 16 | | [assembly: InternalsVisibleTo("Itinero.Tests.Functional")] |
| | 17 | |
|
| | 18 | | namespace Itinero; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Represents a router db. |
| | 22 | | /// </summary> |
| | 23 | | /// <remarks> |
| | 24 | | /// This is mostly a wrapper around a RoutingNetwork. |
| | 25 | | /// If an update happens to the underlying routing network, this update will be presented here atomically. |
| | 26 | | /// In other words, to do route planning, use routerDb.getLatest() to get a consistent routing network |
| | 27 | | /// </remarks> |
| | 28 | | public sealed partial class RouterDb : IRouterDbMutable |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Creates a new router db. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name="configuration">The configuration.</param> |
| 151 | 34 | | public RouterDb(RouterDbConfiguration? configuration = null) |
| 151 | 35 | | { |
| 151 | 36 | | configuration ??= RouterDbConfiguration.Default(); |
| | 37 | |
|
| 151 | 38 | | this.Latest = new RoutingNetwork(this, configuration.Zoom, configuration.MaxIslandSize); |
| 151 | 39 | | _edgeTypeIndex = configuration.EdgeTypeIndex; |
| 151 | 40 | | this.EdgeTypeMap = configuration.EdgeTypeMap ?? AttributeSetMap.Default(); |
| 151 | 41 | | _turnCostTypeIndex = configuration.TurnCostTypeIndex; |
| 151 | 42 | | _turnCostTypeMap = configuration.TurnCostTypeMap ?? AttributeSetMap.Default(); |
| | 43 | |
|
| 151 | 44 | | this.ProfileConfiguration = new RouterDbProfileConfiguration(this); |
| 151 | 45 | | } |
| | 46 | |
|
| 1 | 47 | | private RouterDb(Stream stream, RouterDbReadSettings settings) |
| 1 | 48 | | { |
| | 49 | | // check version #. |
| 1 | 50 | | var version = stream.ReadVarInt32(); |
| 1 | 51 | | if (version != 1) |
| 0 | 52 | | { |
| 0 | 53 | | throw new InvalidDataException("Unknown version #."); |
| | 54 | | } |
| | 55 | |
|
| | 56 | | // read network. |
| 1 | 57 | | this.Latest = stream.ReadFrom(this); |
| | 58 | |
|
| | 59 | | // read edge type map data. |
| 1 | 60 | | _edgeTypeIndex = settings.EdgeTypeAttributeSetIndex; |
| 1 | 61 | | _edgeTypeIndex.ReadFrom(stream); |
| 1 | 62 | | _turnCostTypeIndex = settings.TurnCostAttributeSetIndex; |
| 1 | 63 | | _turnCostTypeIndex.ReadFrom(stream); |
| | 64 | |
|
| | 65 | | // read attributes. |
| 1 | 66 | | this.Meta = new List<(string key, string value)>(this.ReadAttributesFrom(stream)); |
| | 67 | |
|
| 1 | 68 | | this.EdgeTypeMap = AttributeSetMap.Default(); |
| 1 | 69 | | _turnCostTypeMap = AttributeSetMap.Default(); |
| 1 | 70 | | this.ProfileConfiguration = new RouterDbProfileConfiguration(this); |
| 1 | 71 | | } |
| | 72 | |
|
| | 73 | | /// <summary> |
| | 74 | | /// Gets the latest. |
| | 75 | | /// </summary> |
| 568 | 76 | | public RoutingNetwork Latest { get; private set; } |
| | 77 | | } |