TimeTableSystem

Struct TimeTableSystem 

Source
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

Source

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.
Examples found in repository?
examples/LJandBS/main.rs (line 43)
42fn main() {
43    let mut lj_and_bs = TimeTableSystem::old("LJandBS.tt")
44                            .expect("Failed to open time table file");
45    lj_and_bs.CreateLaTeXTimetable("LJandBS.tex")
46                            .expect("Failed to create time table LaTeX file");
47    println!("LJandBS.tex created.  Now use pdflatex to process this file");
48    println!("into LJandBS.pdf.  You will need to run pdflatex 2 or three");
49    println!("times to get the table of contents properly created.");
50}
Source

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?
examples/ValleyFlyer/main.rs (lines 68-69)
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}
Source

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.
Examples found in repository?
examples/ValleyFlyer/main.rs (line 43)
42fn InsertStations(time_table: &mut TimeTableSystem) {
43    time_table.AddStation(String::from("Greenfield, MA"),0.0);
44    time_table.AddStation(String::from("Northampton, MA"),25.0);
45    time_table.AddStation(String::from("Holyoke, MA"),15.0+25.0);
46    time_table.AddStation(String::from("Springfield, MA"),28.0+15.0+25.0);
47}
Source

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.
Source

pub fn NumberOfStations(&self) -> usize

Number of stations.

Returns the number of stations in the system.

Examples found in repository?
examples/ValleyFlyer/main.rs (line 71)
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}
Source

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.
Source

pub fn IthStationMut(&mut self, i: usize) -> Option<&mut Station>

Source

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.
Source

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.
Source

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.

Source

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.
Source

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.
Source

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.
Source

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.
Source

pub fn FindStorageTrack_mut( &mut self, i: usize, name: &String, ) -> Option<&mut StorageTrack>

Source

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.
Source

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.
Source

pub fn NumberOfCabs(&self) -> usize

The nymber of cabs.

Source

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?
examples/ValleyFlyer/main.rs (lines 50-51)
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}
Source

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.
Source

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.
Source

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.
Source

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.
Source

pub fn NumberOfTrains(&self) -> usize

Return the number of trains.

Examples found in repository?
examples/ValleyFlyer/main.rs (line 73)
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}
Source

pub fn NumberOfNotes(&self) -> usize

Return the number of notes.

Source

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!.
Source

pub fn AddNote(&mut self, newnote: String) -> usize

Add a note to the notes vector.

§Parameters:
  • newnote The text of the new note.
Source

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.
Source

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.
Source

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?
examples/ValleyFlyer/main.rs (line 76)
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}
Source

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.
Source

pub fn TimeScale(&self) -> u32

Return time scale.

Source

pub fn TimeInterval(&self) -> u32

Return time interval.

Source

pub fn Name(&self) -> String

Return the name of the system.

Source

pub fn Filename(&self) -> String

Return file pathname.

Source

pub fn StationsIter(&self) -> Iter<'_, Station>

Source

pub fn StationsIter_mut(&mut self) -> IterMut<'_, Station>

Source

pub fn CabsIter(&self) -> Iter<'_, String, Cab>

Source

pub fn CabsIter_mut(&mut self) -> IterMut<'_, String, Cab>

Source

pub fn TrainsIter(&self) -> Iter<'_, String, Train>

Source

pub fn TrainsIter_mut(&mut self) -> IterMut<'_, String, Train>

Source

pub fn NotesIter(&self) -> Iter<'_, String>

Source

pub fn NotesIter_mut(&mut self) -> IterMut<'_, String>

Source

pub fn PrintOptionsIter(&self) -> Iter<'_, String, String>

Source

pub fn PrintOptionsIter_mut(&mut self) -> IterMut<'_, String, String>

Source

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?
examples/LJandBS/main.rs (line 45)
42fn main() {
43    let mut lj_and_bs = TimeTableSystem::old("LJandBS.tt")
44                            .expect("Failed to open time table file");
45    lj_and_bs.CreateLaTeXTimetable("LJandBS.tex")
46                            .expect("Failed to create time table LaTeX file");
47    println!("LJandBS.tex created.  Now use pdflatex to process this file");
48    println!("into LJandBS.pdf.  You will need to run pdflatex 2 or three");
49    println!("times to get the table of contents properly created.");
50}
More examples
Hide additional examples
examples/ValleyFlyer/main.rs (line 77)
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

Source§

fn clone(&self) -> TimeTableSystem

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeTableSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TimeTableSystem

Source§

fn eq(&self, other: &TimeTableSystem) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TimeTableSystem

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.