pub struct TimeTableSystem { /* private fields */ }Expand description
This is the main Time Table Class.
It implements all of the basic data and algorithms used in the Time Table program.
This class includes code to load a set of stations and the trains that run between these stations, along with code to read and write a time table file and code to create a formatted time table, suitable for printing (by way of LaTeX).
Implementations§
Source§impl TimeTableSystem
impl TimeTableSystem
Sourcepub fn old(filename: &str) -> Result<Self, ConstructorError>
pub fn old(filename: &str) -> Result<Self, ConstructorError>
The constructor that creates a time table system from an existing file.
The file is read in and the class is properly initialized from the data in the file.
§Parameters:
- filename The name of the file to load.
Sourcepub fn new(name: String, timescale: u32, timeinterval: u32) -> Self
pub fn new(name: String, timescale: u32, timeinterval: u32) -> Self
The constructor that creates a new, empty time table system from stratch, given a set of esentual parameters.
§Parameters:
- name The name of the time table system.
- timescale Number of time units per 24 hours. There are 1440 minutes in 24 hours.
- timeinterval The tick frequency in time units.
Examples found in repository?
67fn main() {
68 let mut valley_flyer = TimeTableSystem::new(String::from("Northern NE"),
69 1440,15);
70 InsertStations(&mut valley_flyer);
71 println!("Number of Stations: {}",valley_flyer.NumberOfStations());
72 InsertSouthboundTrains(&mut valley_flyer);
73 println!("Number of trains after InsertSouthboundTrains: {}",valley_flyer.NumberOfTrains());
74 InsertNorthboundTrains(&mut valley_flyer);
75 println!("Number of trains after InsertNorthboundTrains: {}",valley_flyer.NumberOfTrains());
76 valley_flyer.SetPrintOption("DirectionName","Southbound");
77 valley_flyer.CreateLaTeXTimetable("ValleyFlyer.tex")
78 .expect("Failed to create time table LaTeX file");
79}Sourcepub fn AddStation(&mut self, name: String, smile: f64) -> Option<usize>
pub fn AddStation(&mut self, name: String, smile: f64) -> Option<usize>
Add a new station to the system.
Creates a new Station class instance and adds it to the station vector. Stations must be added in order of their scale mile location. If the new station is out of order, -1 is returned and the station is not added!
§Parameters:
- name The name of the station.
- smile The scale mile along the route where the station is located.
Sourcepub fn FindStationByName(&self, name: String) -> Option<usize>
pub fn FindStationByName(&self, name: String) -> Option<usize>
Find a station by name.
Returns the index of the station or -1 if the station cannot be found.
§Parameters:
- name The name of the station.
Sourcepub fn NumberOfStations(&self) -> usize
pub fn NumberOfStations(&self) -> usize
Number of stations.
Returns the number of stations in the system.
Examples found in repository?
67fn main() {
68 let mut valley_flyer = TimeTableSystem::new(String::from("Northern NE"),
69 1440,15);
70 InsertStations(&mut valley_flyer);
71 println!("Number of Stations: {}",valley_flyer.NumberOfStations());
72 InsertSouthboundTrains(&mut valley_flyer);
73 println!("Number of trains after InsertSouthboundTrains: {}",valley_flyer.NumberOfTrains());
74 InsertNorthboundTrains(&mut valley_flyer);
75 println!("Number of trains after InsertNorthboundTrains: {}",valley_flyer.NumberOfTrains());
76 valley_flyer.SetPrintOption("DirectionName","Southbound");
77 valley_flyer.CreateLaTeXTimetable("ValleyFlyer.tex")
78 .expect("Failed to create time table LaTeX file");
79}Sourcepub fn IthStation(&self, i: usize) -> Option<&Station>
pub fn IthStation(&self, i: usize) -> Option<&Station>
Return Ith station object.
Returns the NULL pointer if the index is out of range.
§Parameters:
- i The index of the station.
pub fn IthStationMut(&mut self, i: usize) -> Option<&mut Station>
Sourcepub fn StationName(&self, i: usize) -> Option<String>
pub fn StationName(&self, i: usize) -> Option<String>
Return the Ith station name.
Returns the NULL pointer if the index is out of range.
§Parameters:
- i The index of the station.
Sourcepub fn SMile(&self, i: usize) -> Option<f64>
pub fn SMile(&self, i: usize) -> Option<f64>
Return the Ith station’s scale mile location.
Returns -1.0 if the index is out of range.
§Parameters:
- i The index of the station.
Sourcepub fn TotalLength(&self) -> f64
pub fn TotalLength(&self) -> f64
The total length of the route in scale miles.
This is just the scale mile location of the last station along the route.
Sourcepub fn DuplicateStationIndex(&self, i: usize) -> Option<usize>
pub fn DuplicateStationIndex(&self, i: usize) -> Option<usize>
The duplicate station index for a given station.
Only meaningful for out and back type layouts or layouts that have shared trackage. This would be stations along shared trackage. Returns -1 if the index is out of range or if there is not a duplicate station for the ith station.
§Parameters:
- i The index of the station.
Sourcepub fn SetDuplicateStationIndex(&mut self, i: usize, dup: usize)
pub fn SetDuplicateStationIndex(&mut self, i: usize, dup: usize)
Set the duplicate station index for a given station.
Only meaningful for out and back type layouts or layouts that have shared trackage. This would be stations along shared trackage. setting the duplicate station index indicates there is no duplicate station
§Parameters:
- i The index of the station to be updated.
- dup The other station index sharing this station location.
Sourcepub fn AddStorageTrack(
&mut self,
i: usize,
name: &String,
) -> Option<&mut StorageTrack>
pub fn AddStorageTrack( &mut self, i: usize, name: &String, ) -> Option<&mut StorageTrack>
Add a storage track to a station.
Sometimes stations, especially major terminals, have extra tracks for storing terminating and originating trains. Returns the NULL pointer if the index is out of range. Otherwise returns the pointer to the new StorageTrack object.
§Parameters:
- i The index of the station to be updated.
- name The name for the new storage track.
Sourcepub fn FindStorageTrack(&self, i: usize, name: &String) -> Option<&StorageTrack>
pub fn FindStorageTrack(&self, i: usize, name: &String) -> Option<&StorageTrack>
Find a storage track at a station.
Sometimes stations, especially major terminals, have extra tracks for storing terminating and originating trains. Returns the NULL pointer if the index is out of range or if there is no storage track with the specified name. Otherwise the StorageTrack object pointer is returned.
§Parameters:
- i The index of the station to be updated.
- name The name of the storage track.
pub fn FindStorageTrack_mut( &mut self, i: usize, name: &String, ) -> Option<&mut StorageTrack>
Sourcepub fn AddCab(&mut self, name: String, color: String) -> &Cab
pub fn AddCab(&mut self, name: String, color: String) -> &Cab
Add a new cab to the system.
With DC systems this would be an actual cab. With DCC systems, this can be used to define a logical operator for the train. The color is used for visual distintion. A pointer to the new cab object is returned.
§Parameters:
- name The name of the cab.
- color The color of the cab.
Sourcepub fn FindCab(&self, name: &String) -> Option<&Cab>
pub fn FindCab(&self, name: &String) -> Option<&Cab>
Find a cab (by name).
Returns the pointer to the named cab or NULL if the cab was not found.
§Parameters:
- name The cab name to look for.
Sourcepub fn NumberOfCabs(&self) -> usize
pub fn NumberOfCabs(&self) -> usize
The nymber of cabs.
Sourcepub fn AddTrain(
&mut self,
name: String,
number: String,
speed: u32,
classnumber: u32,
departure: u32,
start: usize,
iend: isize,
) -> Result<&Train, AddTrainError>
pub fn AddTrain( &mut self, name: String, number: String, speed: u32, classnumber: u32, departure: u32, start: usize, iend: isize, ) -> Result<&Train, AddTrainError>
Add a train to the system, short version.
Creates a new Train opject and adds it to the train map. The short version assumes that the train does not layover at any of the stops. Layover times can be added later. Returns a pointer to the new Train object.
§Parameters:
- name The name of the train.
- number The number (or symbol) of the train.
- speed The trains maximum speed.
- classnumber The class (inverse priority) of the train.
- departure The train’s departure time.
- start The train’s origin station index. Defaults to the first station.
- end The train’s destination station index. Defaults to the last station.
Examples found in repository?
49fn InsertSouthboundTrains(time_table: &mut TimeTableSystem) {
50 time_table.AddTrain(String::from("Valley Flyer"),String::from("479"),60,1,
51 18*60+5,0,3).expect("Failed to insert 479");
52 time_table.AddTrain(String::from("Valley Flyer"),String::from("425"),60,1,
53 6*60+5,0,3).expect("Failed to insert 425");
54}
55
56fn InsertNorthboundTrains(time_table: &mut TimeTableSystem) {
57 time_table.AddTrain(String::from("Valley Flyer"),String::from("494"),60,1,
58 21*60+25,3,0).expect("Failed to insert 494");
59 time_table.AddTrain(String::from("Valley Flyer"),String::from("486"),60,1,
60 15*60+15,3,0).expect("Failed to insert 486");
61}Sourcepub fn AddTrainLongVersion(
&mut self,
name: String,
number: String,
speed: u32,
classnumber: u32,
departure: u32,
start: usize,
end: usize,
layoverVector: &DoubleVector,
cabnameVector: &StringList,
storageTrackVector: &StringList,
) -> Result<&Train, AddTrainError>
pub fn AddTrainLongVersion( &mut self, name: String, number: String, speed: u32, classnumber: u32, departure: u32, start: usize, end: usize, layoverVector: &DoubleVector, cabnameVector: &StringList, storageTrackVector: &StringList, ) -> Result<&Train, AddTrainError>
Add a train to the system, long version (includes storage track checking).
This version includes layover times, cabnames, and storage track assignments. Returns a pointer to the new Train object or the NULL pointer if there was an error, in which case the error message will be stored in the pointer provided.
§Parameters:
- name The name of the train.
- number The number (or symbol) of the train.
- speed The trains maximum speed.
- classnumber The class (inverse priority) of the train.
- departure The train’s departure time.
- start The train’s origin station index.
- end The train’s destination station index.
- layoverVector The train’s layover vector.
- cabnameVector The train’s departure cab name vector.
- storageTrackVector The train’s storage track name vector.
Sourcepub fn DeleteTrain(&mut self, number: String) -> Result<(), DeleteTrainError>
pub fn DeleteTrain(&mut self, number: String) -> Result<(), DeleteTrainError>
Delete a train.
Returns true if the train was successfully deleted and false if not. If the train was not deleted, an error message will be provided in the pointer provided.
§Parameters:
- number The train number or symbol.
Sourcepub fn FindTrainByName(&self, name: &String) -> Option<&Train>
pub fn FindTrainByName(&self, name: &String) -> Option<&Train>
Find a train by name.
Returns the pointer to the named train or NULL if the train was not found.
§Parameters:
- name The train name to look for.
Sourcepub fn FindTrainByNumber(&self, number: &String) -> Option<&Train>
pub fn FindTrainByNumber(&self, number: &String) -> Option<&Train>
Find a train by number (or symbol).
Returns the pointer to the train or NULL if the train was not found.
§Parameters:
- number The train number (or symbol) to look for.
Sourcepub fn NumberOfTrains(&self) -> usize
pub fn NumberOfTrains(&self) -> usize
Return the number of trains.
Examples found in repository?
67fn main() {
68 let mut valley_flyer = TimeTableSystem::new(String::from("Northern NE"),
69 1440,15);
70 InsertStations(&mut valley_flyer);
71 println!("Number of Stations: {}",valley_flyer.NumberOfStations());
72 InsertSouthboundTrains(&mut valley_flyer);
73 println!("Number of trains after InsertSouthboundTrains: {}",valley_flyer.NumberOfTrains());
74 InsertNorthboundTrains(&mut valley_flyer);
75 println!("Number of trains after InsertNorthboundTrains: {}",valley_flyer.NumberOfTrains());
76 valley_flyer.SetPrintOption("DirectionName","Southbound");
77 valley_flyer.CreateLaTeXTimetable("ValleyFlyer.tex")
78 .expect("Failed to create time table LaTeX file");
79}Sourcepub fn NumberOfNotes(&self) -> usize
pub fn NumberOfNotes(&self) -> usize
Return the number of notes.
Sourcepub fn Note(&self, i: usize) -> Option<String>
pub fn Note(&self, i: usize) -> Option<String>
Return the ith note (1-based!) as a string. , Returns the NULL pointer if the index is out of range.
§Parameters:
- i The note index. The first note is at index 1, not 0!.
Sourcepub fn SetNote(&mut self, i: usize, note: String) -> bool
pub fn SetNote(&mut self, i: usize, note: String) -> bool
Set the ith note (1-based!).
Updates the text of the specificed note. Returns true if the note was updated or false if the index was out of range.
§Parameters:
- i The note index. The first note is at index 1, not 0!.
- note The new text for the note.
Sourcepub fn GetPrintOption(&self, key: &str) -> Option<&String>
pub fn GetPrintOption(&self, key: &str) -> Option<&String>
Fetch a print option.
Returns the value of a specified print option or the empty string if the print option was not found.
§Parameters:
- key The name of the print option.
Sourcepub fn SetPrintOption(&mut self, key: &str, value: &str)
pub fn SetPrintOption(&mut self, key: &str, value: &str)
Set a print option.
Sets the value of a print option. Creates a new hash table element if the specified print option does not already exist.
§Parameters:
- key The name of the print option to be set.
- value The value to set the print option to.
Examples found in repository?
67fn main() {
68 let mut valley_flyer = TimeTableSystem::new(String::from("Northern NE"),
69 1440,15);
70 InsertStations(&mut valley_flyer);
71 println!("Number of Stations: {}",valley_flyer.NumberOfStations());
72 InsertSouthboundTrains(&mut valley_flyer);
73 println!("Number of trains after InsertSouthboundTrains: {}",valley_flyer.NumberOfTrains());
74 InsertNorthboundTrains(&mut valley_flyer);
75 println!("Number of trains after InsertNorthboundTrains: {}",valley_flyer.NumberOfTrains());
76 valley_flyer.SetPrintOption("DirectionName","Southbound");
77 valley_flyer.CreateLaTeXTimetable("ValleyFlyer.tex")
78 .expect("Failed to create time table LaTeX file");
79}Sourcepub fn WriteNewTimeTableFile(
&mut self,
filename: &String,
setfilename: bool,
) -> Result<()>
pub fn WriteNewTimeTableFile( &mut self, filename: &String, setfilename: bool, ) -> Result<()>
Write out a Time Table System to a new file.
The current contents of the time table is written to a new time table file. Returns true if successful and false if not.
§Parameters:
- filename The name of the file to write (if empty, use existing name, if available).
- setfilename Change the filename if true.
Sourcepub fn TimeInterval(&self) -> u32
pub fn TimeInterval(&self) -> u32
Return time interval.
pub fn StationsIter(&self) -> Iter<'_, Station>
pub fn StationsIter_mut(&mut self) -> IterMut<'_, Station>
pub fn CabsIter(&self) -> Iter<'_, String, Cab>
pub fn CabsIter_mut(&mut self) -> IterMut<'_, String, Cab>
pub fn TrainsIter(&self) -> Iter<'_, String, Train>
pub fn TrainsIter_mut(&mut self) -> IterMut<'_, String, Train>
pub fn NotesIter(&self) -> Iter<'_, String>
pub fn NotesIter_mut(&mut self) -> IterMut<'_, String>
pub fn PrintOptionsIter(&self) -> Iter<'_, String, String>
pub fn PrintOptionsIter_mut(&mut self) -> IterMut<'_, String, String>
Sourcepub fn CreateLaTeXTimetable(
&mut self,
filename: &str,
) -> Result<(), CreateLaTeXError>
pub fn CreateLaTeXTimetable( &mut self, filename: &str, ) -> Result<(), CreateLaTeXError>
Create a LaTeX file for generating a (hard copy) Employee Timetable.
This method create a LaTeX source file from the information in the time table structure. It access various print options to control how the LaTeX file is generated.
§Parameters:
- filename The name of the LaTeX file to create.
Examples found in repository?
More examples
67fn main() {
68 let mut valley_flyer = TimeTableSystem::new(String::from("Northern NE"),
69 1440,15);
70 InsertStations(&mut valley_flyer);
71 println!("Number of Stations: {}",valley_flyer.NumberOfStations());
72 InsertSouthboundTrains(&mut valley_flyer);
73 println!("Number of trains after InsertSouthboundTrains: {}",valley_flyer.NumberOfTrains());
74 InsertNorthboundTrains(&mut valley_flyer);
75 println!("Number of trains after InsertNorthboundTrains: {}",valley_flyer.NumberOfTrains());
76 valley_flyer.SetPrintOption("DirectionName","Southbound");
77 valley_flyer.CreateLaTeXTimetable("ValleyFlyer.tex")
78 .expect("Failed to create time table LaTeX file");
79}Trait Implementations§
Source§impl Clone for TimeTableSystem
impl Clone for TimeTableSystem
Source§fn clone(&self) -> TimeTableSystem
fn clone(&self) -> TimeTableSystem
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more