Microscopic Traffic Simulator
GeometricTopology.cs
Go to the documentation of this file.
2 using System;
3 using System.Collections.Generic;
4 using System.Collections.ObjectModel;
5 using System.IO;
6 using System.Runtime.Serialization.Formatters.Binary;
7 
8 namespace Microscopic_Traffic_Simulator___Model.GeometricObjects
9 {
13  [Serializable]
14  public class GeometricTopology
15  {
19  private List<Lane> lanes = new List<Lane>();
23  public ReadOnlyCollection<Lane> Lanes { get { return lanes.AsReadOnly(); } }
24 
28  public bool IsEmpty { get { return lanes.Count == 0; } }
29 
34  public void AddLane(Lane newLane)
35  {
36  lanes.Add(newLane);
37  }
38 
43  public void Serialize(string path)
44  {
45  using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
46  {
47  new BinaryFormatter().Serialize(fs, this);
48  }
49  }
50 
56  public static GeometricTopology Deserialize(string path)
57  {
58  using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
59  {
60  GeometricTopology loadedTopology = (GeometricTopology)new BinaryFormatter().Deserialize(fs);
61  if (loadedTopology.lanes == null)
62  {
63  loadedTopology.lanes = new List<Lane>();
64  }
65  return loadedTopology;
66  }
67  }
68  }
69 }
Class representing geometric topology of road network.
void Serialize(string path)
Save geometric topology to file.
static GeometricTopology Deserialize(string path)
Load geometric topology from file.
void AddLane(Lane newLane)
Adds new lane to geometric topology.