|
MTCT
Design Automation and Optimization for ETCS Railway Networks
|
Container for trains with name-based indexing. More...
#include <Train.hpp>
Public Member Functions | |
| TrainList ()=default | |
| Constructs an empty train list. | |
| TrainList (std::filesystem::path const &p) | |
| Constructs a train list by importing trains.json from a directory. | |
| TrainList (std::string const &path) | |
| Constructs a train list by importing from a path string. | |
| TrainList (char const *const path) | |
| Constructs a train list from a C-string path. | |
| constexpr auto | begin () const |
| Read-only iterator to the first train. | |
| constexpr auto | end () const |
| Read-only iterator past the last train. | |
| constexpr auto | cbegin () const |
| Const iterator to the first train. | |
| constexpr auto | cend () const |
| Gets a const iterator past the end of the train list. | |
| constexpr auto | crbegin () const |
| Read-only reverse iterator to the last train. | |
| constexpr auto | crend () const |
| Read-only reverse iterator before the first train. | |
| size_t | size () const |
| Retrieves the number of trains in the list. | |
| size_t | get_train_index (const std::string &name) const |
| Returns the index of a train by name. | |
| Train const & | get_train (size_t index) const |
| Returns a train by index. | |
| Train const & | get_train (std::string const &name) const |
| Retrieves a train by name. | |
| Train & | editable_train (size_t index) |
| Retrieves the train at the specified index. | |
| Train & | editable_train (std::string const &name) |
| Accesses a train by name for editing. | |
| size_t | get_number_of_trains () const |
| Queries the number of trains in the list. | |
| bool | has_train (const std::string &name) const |
| Checks whether a train with the given name exists. | |
| bool | has_train (size_t const index) const |
| Checks whether a train index is valid. | |
| size_t | add_train (std::string const &name, double const length, double const maxSpeed, double const acceleration, double const deceleration, bool const tim=true) |
| Creates and adds a train from its attributes. | |
| size_t | add_train (Train train) |
| Adds a train to the list. | |
| void | rename_train (std::string const &old_name, std::string new_name) |
| Renames an existing train while preserving its index and properties. | |
| void | export_trains (std::string const &path) const |
| Exports all trains to trains.json in the target directory. | |
| void | export_trains (char const *const path) const |
| Exports all trains to trains.json in the target directory. | |
| void | export_trains (std::filesystem::path const &p) const |
| Exports all trains to trains.json in the target directory. | |
| void | throw_if_train_not_exist (std::string const &train_name) const |
| Ensures a train with the given name exists. | |
| void | throw_if_train_not_exist (size_t const trainIndex) const |
| Validates that a train exists at the specified index. | |
Static Public Member Functions | |
| static TrainList | import_trains (std::string const &path) |
| Creates a train list by importing trains from a directory. | |
| static TrainList | import_trains (char const *const path) |
| Imports a train list from a directory. | |
| static TrainList | import_trains (std::filesystem::path const &p) |
| Imports a train list from a filesystem path. | |
Container for trains with name-based indexing.
Maintains a sequence of trains and a lookup map from train name to index.
|
default |
Constructs an empty train list.
|
explicit |
Constructs a train list by importing trains.json from a directory.
| p | Path to the directory containing trains.json. |
| cda_rail::exceptions::ImportException | If p is not an existing directory. |
| cda_rail::exceptions::ConsistencyException | If imported train names are duplicated. |
| cda_rail::exceptions::InvalidInputException | If imported train attributes violate train constraints. |
|
inlineexplicit |
Constructs a train list by importing from a path string.
| path | Path to the directory containing trains.json. |
|
inlineexplicit |
Constructs a train list from a C-string path.
| path | Path to the directory containing trains.json. |
| cda_rail::exceptions::ImportException | if the path is not an existing directory. |
| cda_rail::exceptions::ConsistencyException | if imported train names are duplicated. |
| cda_rail::exceptions::InvalidInputException | if imported train attributes violate train constraints. |
|
inline |
Creates and adds a train from its attributes.
| name | Train name. |
| length | Train length in meters. |
| maxSpeed | Maximum speed in m/s. |
| acceleration | Maximum acceleration in m/s^2. |
| deceleration | Maximum deceleration in m/s^2. |
| tim | Train integrity monitoring flag. |
| cda_rail::exceptions::ConsistencyException | If a train with name already exists. |
| cda_rail::exceptions::InvalidInputException | If train attributes are invalid. |
| size_t cda_rail::TrainList::add_train | ( | Train | train | ) |
Adds a train to the list.
| train | Train to add. |
| cda_rail::exceptions::ConsistencyException | If a train with the same name already exists. |
|
inlinenodiscardconstexpr |
Read-only iterator to the first train.
|
inlinenodiscardconstexpr |
Const iterator to the first train.
|
inlinenodiscardconstexpr |
Gets a const iterator past the end of the train list.
|
inlinenodiscardconstexpr |
Read-only reverse iterator to the last train.
|
inlinenodiscardconstexpr |
Read-only reverse iterator before the first train.
|
inlinenodiscard |
Retrieves the train at the specified index.
| index | Index of the train. |
| cda_rail::exceptions::TrainNotExistentException | If index is out of range. |
|
inlinenodiscard |
Accesses a train by name for editing.
| name | The name of the train to retrieve. |
| cda_rail::exceptions::TrainNotExistentException | If no train with the given name exists. |
|
inlinenodiscardconstexpr |
Read-only iterator past the last train.
|
inline |
Exports all trains to trains.json in the target directory.
| path | Path to the export directory. |
| void cda_rail::TrainList::export_trains | ( | std::filesystem::path const & | p | ) | const |
Exports all trains to trains.json in the target directory.
Creates the directory if needed and writes one JSON object keyed by train name.
| p | Path to the export directory. |
| cda_rail::exceptions::ExportException | If the directory cannot be created. |
|
inline |
Exports all trains to trains.json in the target directory.
| path | Path to the export directory. |
|
inlinenodiscard |
Queries the number of trains in the list.
|
nodiscard |
Returns a train by index.
| index | Index of the train. |
| cda_rail::exceptions::TrainNotExistentException | If index is out of range. |
|
inlinenodiscard |
Retrieves a train by name.
| name | Train name. |
| cda_rail::exceptions::TrainNotExistentException | If no train with the specified name exists. |
|
nodiscard |
Returns the index of a train by name.
| name | Train name. |
| cda_rail::exceptions::TrainNotExistentException | If no train with name exists. |
|
inlinenodiscard |
Checks whether a train with the given name exists.
| name | Train name. |
|
inlinenodiscard |
Checks whether a train index is valid.
| index | Train index. |
|
inlinestaticnodiscard |
Imports a train list from a directory.
Reads the trains.json file from the specified directory.
| path | Path to the directory containing trains.json. |
| cda_rail::exceptions::ImportException | if path is not an existing directory. |
| cda_rail::exceptions::ConsistencyException | if the imported data contains duplicate train names. |
| cda_rail::exceptions::InvalidInputException | if any imported train attributes violate train constraints. |
|
inlinestaticnodiscard |
Imports a train list from a filesystem path.
| p | Path to the directory containing trains.json. |
|
inlinestaticnodiscard |
Creates a train list by importing trains from a directory.
| path | Path to the directory containing trains.json. |
| void cda_rail::TrainList::rename_train | ( | std::string const & | old_name, |
| std::string | new_name ) |
Renames an existing train while preserving its index and properties.
| old_name | Current train name. |
| new_name | New train name. |
| cda_rail::exceptions::TrainNotExistentException | If no train named old_name exists. |
| cda_rail::exceptions::ConsistencyException | If new_name is already used by another train. |
|
inlinenodiscard |
Retrieves the number of trains in the list.
|
inline |
Validates that a train exists at the specified index.
| trainIndex | Index of the train to validate. |
| TrainNotExistentException | If no train exists at the given index. |
|
inline |
Ensures a train with the given name exists.
| train_name | The name of the train to validate. |
| TrainNotExistentException | if no train with the given name exists. |