-
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 1 commit
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,33 @@ | ||
| #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(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,27 @@ | ||
| #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: | ||
| Station(Id id, Delay managementTime); | ||
| Station(Id id, std::pair<double, double> coords, Delay managementTime); | ||
| Station(Station const& other); | ||
|
|
||
| void enqueue(Id trainId, train_t trainType); | ||
|
|
||
| Id dequeue(); | ||
|
|
||
| Delay managementTime() const; | ||
| double density() const final; | ||
| bool isFull() const final; | ||
| bool isStation() const noexcept final; | ||
| }; | ||
| } // namespace dsm |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note