-
Notifications
You must be signed in to change notification settings - Fork 4
Add Station Class
#226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Station Class
#226
Changes from all commits
96b6e14
0996558
9149507
bbec3d3
9a78f4c
194937d
c5b0fa7
b17dad7
d98a632
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include "Station.hpp" | ||
|
|
||
| namespace dsm { | ||
| Station::Station(Id id, Delay managementTime) | ||
| : Node(id), m_managementTime{managementTime} {} | ||
|
|
||
| Station::Station(Id id, std::pair<double, double> coords, Delay managementTime) | ||
| : Node(id, coords), m_managementTime{managementTime} {} | ||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.3 rule Note
MISRA 12.3 rule
|
||
|
|
||
| Station::Station(Node const& node, Delay managementTime) | ||
| : Node(node), m_managementTime{managementTime} {} | ||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.3 rule Note
MISRA 12.3 rule
|
||
|
|
||
| Station::Station(Station const& other) | ||
| : Node(other), m_managementTime{other.m_managementTime}, m_trains{other.m_trains} {} | ||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.3 rule Note
MISRA 12.3 rule
|
||
|
|
||
| void Station::enqueue(Id trainId, train_t trainType) { | ||
| m_trains.emplace(trainType, trainId); | ||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 17.7 rule Note
MISRA 17.7 rule
|
||
| } | ||
|
|
||
| Id Station::dequeue() { | ||
| auto it = m_trains.begin(); | ||
| Id trainId = it->second; | ||
| m_trains.erase(it); | ||
| return trainId; | ||
| } | ||
|
|
||
| Delay Station::managementTime() const { return m_managementTime; } | ||
|
|
||
| double Station::density() const { | ||
| return static_cast<double>(m_trains.size()) / m_capacity; | ||
| } | ||
|
|
||
| bool Station::isFull() const { return m_trains.size() >= m_capacity; } | ||
|
|
||
| bool Station::isStation() const noexcept { return true; } | ||
| } // namespace dsm | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /// @file /src/dsm/headers/Station.hpp | ||
| /// @brief Defines the Station class. | ||
| /// | ||
| /// @details The Station class represents a train station in the network. | ||
| /// It is a derived class of the Node class. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "Node.hpp" | ||
|
|
||
| #include <map> | ||
|
|
||
| namespace dsm { | ||
| class Station : public Node { | ||
| private: | ||
| Delay m_managementTime; | ||
| std::multimap<train_t, Id, std::greater<train_t>> m_trains; | ||
|
|
||
| public: | ||
| /// @brief Construct a new Station object | ||
| /// @param id The station's id | ||
| /// @param managementTime The time it takes between two train departures/arrivals | ||
| Station(Id id, Delay managementTime); | ||
| /// @brief Construct a new Station object | ||
| /// @param id The station's id | ||
| /// @param coords A std::pair containing the station's coordinates (lat, lon) | ||
| /// @param managementTime The time it takes between two train departures/arrivals | ||
| Station(Id id, std::pair<double, double> coords, Delay managementTime); | ||
| /// @brief Construct a new Station object | ||
| /// @param node A Node object representing the station | ||
| /// @param managementTime The time it takes between two train departures/arrivals | ||
| Station(Node const& node, Delay managementTime); | ||
| /// @brief Construct a new Station object by copying another Station object | ||
| /// @param other The Station object to copy | ||
| Station(Station const& other); | ||
| /// @brief Enqueue a train in the station | ||
| /// @param trainId The id of the train to enqueue | ||
| /// @param trainType The type of the train to enqueue | ||
| void enqueue(Id trainId, train_t trainType); | ||
| /// @brief Dequeue a train from the station | ||
| /// @return The id of the dequeued train | ||
| Id dequeue(); | ||
| /// @brief Get the time it takes between two train departures/arrivals | ||
| /// @return The management time | ||
| Delay managementTime() const; | ||
| /// @brief Get the train density of the station | ||
| /// @return The train density of the station | ||
| double density() const final; | ||
| /// @brief Check if the station is full | ||
| /// @return True if the station is full, false otherwise | ||
| bool isFull() const final; | ||
| /// @brief Check if the node is a station | ||
| /// @return True | ||
| bool isStation() const noexcept final; | ||
| }; | ||
| } // namespace dsm |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note