Microscopic Traffic Simulator

- Main Page
- Packages
- Classes
- Files

- File List

GeometricTopology.cs
Go to the documentation of this file.
1 using Microscopic_Traffic_Simulator___Model.GeometricObjects.Lanes;
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 }
Microscopic_Traffic_Simulator___Model.GeometricObjects.GeometricTopology
Class representing geometric topology of road network.
Definition: GeometricTopology.cs:14
Microscopic_Traffic_Simulator___Model.GeometricObjects.GeometricTopology.Serialize
void Serialize(string path)
Save geometric topology to file.
Definition: GeometricTopology.cs:43
System
Microscopic_Traffic_Simulator___Model.GeometricObjects.GeometricTopology.Deserialize
static GeometricTopology Deserialize(string path)
Load geometric topology from file.
Definition: GeometricTopology.cs:56
Microscopic_Traffic_Simulator___Model.GeometricObjects.GeometricTopology.AddLane
void AddLane(Lane newLane)
Adds new lane to geometric topology.
Definition: GeometricTopology.cs:34
Microscopic_Traffic_Simulator___Model.GeometricObjects.Lanes.Lane
Represent single lane.
Definition: Lane.cs:14
Microscopic_Traffic_Simulator___Model.GeometricObjects.Lanes
Definition: BezierLane.cs:5
Microscopic_Traffic_Simulator___Model.GeometricObjects
Definition: GeometricTopology.cs:8
Microscopic_Traffic_Simulator___Model