Model Railroad System
2.2.1
|
This is the main Time Table Class. More...
#include <TimeTableSystem.h>
Public Member Functions | |
TimeTableSystem (const string filename, char **outmessage=NULL) | |
The constructor that creates a time table system from an existing file. More... | |
TimeTableSystem (const string name, int timescale, int timeinterval) | |
The constructor that creates a new, empty time table system from stratch, given a set of esentual parameters. More... | |
~TimeTableSystem () | |
Destructor. More... | |
int | AddStation (string name, double smile) |
Add a new station to the system. More... | |
int | FindStationByName (string name) |
Find a station by name. More... | |
int | NumberOfStations () const |
Number of stations. More... | |
TTSupport::Station * | IthStation (int i) |
Return Ith station object. More... | |
const char * | StationName (int i) const |
Return the Ith station name. More... | |
double | SMile (int i) const |
Return the Ith station's scale mile location. More... | |
double | TotalLength () const |
The total length of the route in scale miles. More... | |
int | DuplicateStationIndex (int i) const |
The duplicate station index for a given station. More... | |
void | SetDuplicateStationIndex (int i, int dup) |
Set the duplicate station index for a given station. More... | |
StorageTrack * | AddStorageTrack (int i, string name) |
Add a storage track to a station. More... | |
StorageTrack * | FindStorageTrack (int i, string name) |
Find a storage track at a station. More... | |
Cab * | AddCab (string name, string color) |
Add a new cab to the system. More... | |
int | NumberOfCabs () const |
The nymber of cabs. More... | |
Train * | AddTrain (string name, string number, int speed, int classnumber, int departure, int start=0, int end=-1) |
Add a train to the system, short version. More... | |
Train * | AddTrainLongVersion (string name, string number, int speed, int classnumber, int departure, int start, int end, const doubleVector *layoverVector, const stringVector *cabnameVector, const stringVector *storageTrackVector, char **outmessage=NULL) |
Add a train to the system, long version (includes storage track checking). More... | |
bool | DeleteTrain (string number, char **outmessage=NULL) |
Delete a train. More... | |
Cab * | FindCab (string name) const |
Find a cab (by name). More... | |
Train * | FindTrainByName (string name) const |
Find a train by name. More... | |
Train * | FindTrainByNumber (string number) const |
Find a train by number (or symbol). More... | |
int | NumberOfTrains () const |
Return the number of trains. More... | |
int | NumberOfNotes () const |
Return the number of notes. More... | |
const char * | Note (int i) |
Return the ith note (1-based!) as a string. More... | |
int | AddNote (string newnote) |
Add a note to the notes vector. More... | |
bool | SetNote (int i, string note) |
Set the ith note (1-based!). More... | |
const char * | GetPrintOption (const char *key) const |
Fetch a print option. More... | |
void | SetPrintOption (const char *key, string value) |
Set a print option. More... | |
bool | WriteNewTimeTableFile (string filename="TimeTableFile.tt", bool setfilename=false, char **outmessage=NULL) |
Write out a Time Table System to a new file. More... | |
bool | WriteOldTimeTableFile (char **outmessage=NULL) |
Write an old time table file. More... | |
int | TimeScale () const |
Return time scale. More... | |
int | TimeInterval () const |
Return time interval. More... | |
const char * | Name () const |
Return the name of the system. More... | |
const char * | Filename () const |
Return file pathname. More... | |
bool | CreateLaTeXTimetable (string filename, char **outmessage=NULL) |
Create a LaTeX file for generating a (hard copy) Employee Timetable. More... | |
CabNameMap::const_iterator | FirstCab () const |
First cab. More... | |
CabNameMap::const_iterator | LastCab () const |
Last cab. More... | |
TrainNumberMap::const_iterator | FirstTrain () const |
First train. More... | |
TrainNumberMap::const_iterator | LastTrain () const |
Last train. More... | |
OptionHashMap::const_iterator | FirstPrintOption () const |
First Print option. More... | |
OptionHashMap::const_iterator | LastPrintOption () const |
Last Print option. More... | |
Protected Member Functions | |
TimeTableSystem () | |
The default constructor. More... | |
Private Member Functions | |
string | ReadNote (istream &in) const |
Read in a note. More... | |
ostream & | WriteNote (ostream &out, string note) const |
Write out a note. More... | |
bool | MakeTimeTableGroupByClass (ostream &out, TrainList &allTrains, TrainList &forwardTrains, TrainList &backwardTrains, char **outmessage=NULL) |
Make a time table grouped by class. More... | |
bool | MakeTimeTableGroupManually (ostream &out, int maxTrains, TrainList &allTrains, TrainList &forwardTrains, TrainList &backwardTrains, char **outmessage=NULL) |
Make a time table grouped manually. More... | |
bool | MakeTimeTableOneTable (ostream &out, TrainList &allTrains, TrainList &forwardTrains, TrainList &backwardTrains, string header, string sectionTOP, char **outmessage=NULL) |
Make a time table as a single table. More... | |
bool | MakeTimeTableOneTableStationsLeft (ostream &out, TrainList &trains, string header, string sectionTOP, char **outmessage=NULL) |
Make a time table as a single table, with the stations on the left (single direction trains). More... | |
bool | MakeTimeTableOneTableStationsCenter (ostream &out, TrainList &forwardTrains, TrainList &backwardTrains, string header, string sectionTOP, char **outmessage=NULL) |
Make a time table as a single table, with the stations in the center (bi-directional trains). More... | |
void | ComputeTimes (TrainTimesAtStation ×AtStations, TrainList &trains) |
Precompute station times, given a list of trains. More... | |
Private Attributes | |
string | name |
The name of the time table system. More... | |
PathName | filepath |
The pathname of the file the system was loaded from. More... | |
int | timescale |
Time scale. More... | |
int | timeinterval |
Time interval. More... | |
StationVector | stations |
Station stop vector. More... | |
CabNameMap | cabs |
Cap name map. More... | |
TrainNumberMap | trains |
Train number/symbol map. More... | |
vector< string > | notes |
Notes. More... | |
OptionHashMap | printOptions |
Print option hash table. More... | |
bool | TOCP |
Table Of Contents? More... | |
string | DirectionName |
Direction Name. More... | |
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).
|
inlineprotected |
The default constructor.
This is protected to prevent the creation of an uninitialized class instance, which would be an error. Making the default constructor a protected method will cause a compiler error when application code attempts to create a TimeTableSystem instance without using one of the parameterized constructor. There is no meaningful way to create a proper TimeTableSystem without supplying some parameters.
TTSupport::TimeTableSystem::TimeTableSystem | ( | const string | filename, |
char ** | outmessage = NULL |
||
) |
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.
filename | The name of the file to load. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
TTSupport::TimeTableSystem::TimeTableSystem | ( | const string | name, |
int | timescale, | ||
int | timeinterval | ||
) |
The constructor that creates a new, empty time table system from stratch, given a set of esentual 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. |
TTSupport::TimeTableSystem::~TimeTableSystem | ( | ) |
Destructor.
Properly clean up and free up all used space.
Cab* TTSupport::TimeTableSystem::AddCab | ( | string | name, |
string | color | ||
) |
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.
name | The name of the cab. |
color | The color of the cab. |
|
inline |
Add a note to the notes vector.
newnote | The text of the new note. |
int TTSupport::TimeTableSystem::AddStation | ( | string | name, |
double | smile | ||
) |
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!
name | The name of the station. |
smile | The scale mile along the route where the station is located. |
|
inline |
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.
i | The index of the station to be updated. |
name | The name for the new storage track. |
References i.
Train* TTSupport::TimeTableSystem::AddTrain | ( | string | name, |
string | number, | ||
int | speed, | ||
int | classnumber, | ||
int | departure, | ||
int | start = 0 , |
||
int | end = -1 |
||
) |
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.
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. |
Train* TTSupport::TimeTableSystem::AddTrainLongVersion | ( | string | name, |
string | number, | ||
int | speed, | ||
int | classnumber, | ||
int | departure, | ||
int | start, | ||
int | end, | ||
const doubleVector * | layoverVector, | ||
const stringVector * | cabnameVector, | ||
const stringVector * | storageTrackVector, | ||
char ** | outmessage = NULL |
||
) |
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.
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. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
private |
Precompute station times, given a list of trains.
This helper function creates the table cell information for a time table.
timesAtStations | The time table matrix to be filled in. |
trains | A list of trains to process. |
bool TTSupport::TimeTableSystem::CreateLaTeXTimetable | ( | string | filename, |
char ** | outmessage = NULL |
||
) |
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.
filename | The name of the LaTeX file to create. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
bool TTSupport::TimeTableSystem::DeleteTrain | ( | string | number, |
char ** | outmessage = NULL |
||
) |
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.
number | The train number or symbol. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
inline |
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.
i | The index of the station. |
References i.
|
inline |
Return file pathname.
Cab* TTSupport::TimeTableSystem::FindCab | ( | string | name | ) | const |
Find a cab (by name).
Returns the pointer to the named cab or NULL if the cab was not found.
name | The cab name to look for. |
int TTSupport::TimeTableSystem::FindStationByName | ( | string | name | ) |
Find a station by name.
Returns the index of the station or -1 if the station cannot be found.
name | The name of the station. |
|
inline |
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.
i | The index of the station to be updated. |
name | The name of the storage track. |
References i.
Train* TTSupport::TimeTableSystem::FindTrainByName | ( | string | name | ) | const |
Find a train by name.
Returns the pointer to the named train or NULL if the train was not found.
name | The train name to look for. |
Train* TTSupport::TimeTableSystem::FindTrainByNumber | ( | string | number | ) | const |
Find a train by number (or symbol).
Returns the pointer to the train or NULL if the train was not found.
number | The train number (or symbol) to look for. |
|
inline |
First cab.
Return a const iterator for the first cab.
|
inline |
First Print option.
Return a const iterator for the first print option.
|
inline |
First train.
Return a const iterator for the first train.
|
inline |
Fetch a print option.
Returns the value of a specified print option or the empty string if the print option was not found.
key | The name of the print option. |
|
inline |
Return Ith station object.
Returns the NULL pointer if the index is out of range.
i | The index of the station. |
References i.
|
inline |
Last cab.
Return a const iterator for the last cab.
|
inline |
Last Print option.
Return a const iterator for the last print option.
References linuxgpio::in, and linuxgpio::out.
|
inline |
Last train.
Return a const iterator for the last train.
|
private |
Make a time table grouped by class.
Writes a time table LaTeX file grouped by train class. Each class will have its own table in its own section. Returns true if successfull and false if there were problems (errors).
out | The LaTeX output stream. |
allTrains | A list of all of the trains. |
forwardTrains | A list of all forward moving trains. |
backwardTrains | A list of all backward moving trains. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
private |
Make a time table grouped manually.
Writes a time table LaTeX file grouped manually. Returns true if successfull and false if there were problems (errors).
out | The LaTeX output stream. |
maxTrains | The maximum number of trains per table. |
allTrains | A list of all of the trains. |
forwardTrains | A list of all forward moving trains. |
backwardTrains | A list of all backward moving trains. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
private |
Make a time table as a single table.
Writes a time table LaTeX file with all trains in a single table. This only makes sense if the total number of trains is small.
out | The LaTeX output stream. |
allTrains | A list of all of the trains. |
forwardTrains | A list of all forward moving trains. |
backwardTrains | A list of all backward moving trains. |
header | String (LaTeX code) to use for the time table header. |
sectionTOP | String (LaTeX code) to use for the section start. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
private |
Make a time table as a single table, with the stations in the center (bi-directional trains).
out | The LaTeX output stream. |
forwardTrains | A list of all forward moving trains. |
backwardTrains | A list of all backward moving trains. |
header | String (LaTeX code) to use for the time table header. |
sectionTOP | String (LaTeX code) to use for the section start. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
private |
Make a time table as a single table, with the stations on the left (single direction trains).
out | The LaTeX output stream. |
trains | A list of the trains. |
header | String (LaTeX code) to use for the time table header. |
sectionTOP | String (LaTeX code) to use for the section start. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
inline |
Return the name of the system.
|
inline |
Return the ith note (1-based!) as a string.
Returns the NULL pointer if the index is out of range.
i | The note index. The first note is at index 1, not 0!. |
|
inline |
The nymber of cabs.
|
inline |
Return the number of notes.
|
inline |
Number of stations.
Returns the number of stations in the system.
|
inline |
Return the number of trains.
|
private |
Read in a note.
Reads a note from a stream. Returns the note text.
in | Stream to read from. |
|
inline |
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
i | The index of the station to be updated. |
dup | The other station index sharing this station location. |
References i.
|
inline |
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.
i | The note index. The first note is at index 1, not 0!. |
note | The new text for the note. |
|
inline |
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.
key | The name of the print option to be set. |
value | The value to set the print option to. |
|
inline |
Return the Ith station's scale mile location.
Returns -1.0 if the index is out of range.
i | The index of the station. |
References i.
|
inline |
Return the Ith station name.
Returns the NULL pointer if the index is out of range.
i | The index of the station. |
References i.
|
inline |
Return time interval.
|
inline |
Return time scale.
|
inline |
The total length of the route in scale miles.
This is just the scale mile location of the last station along the route.
bool TTSupport::TimeTableSystem::WriteNewTimeTableFile | ( | string | filename = "TimeTableFile.tt" , |
bool | setfilename = false , |
||
char ** | outmessage = NULL |
||
) |
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.
filename | The name of the file to write (if empty, use existing name, if available). |
setfilename | Change the filename if true. |
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
private |
Write out a note.
Writes the note text to a stream. Returns the stream.
out | Stream to write to. |
note | The note text. |
|
inline |
Write an old time table file.
The current contents of the time table is written to the file name stored in the time table object. This method just calls the WriteNewTimeTableFile method with the old file name. Returns true if successful and false if not.
outmessage | Pointer to a pointer to receive any error messages for any errors that might occur. |
|
private |
Cap name map.
|
private |
Direction Name.
Used by print functions.
|
private |
The pathname of the file the system was loaded from.
|
private |
The name of the time table system.
|
private |
Notes.
|
private |
Print option hash table.
|
private |
Station stop vector.
|
private |
Time interval.
|
private |
Time scale.
|
private |
Table Of Contents?
Used by print functions.
|
private |
Train number/symbol map.