Traffic Flow Dynamics Model
Vehicle.hpp
1 #ifndef VEHICLE_HPP
2 #define VEHICLE_HPP
3 
5 
9 
10 #include "VehicleType.hpp"
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 class Vehicle {
16 private:
17  static std::vector<std::shared_ptr<VehicleType>> _vehicleType;
18  uint8_t _index;
19  uint16_t _position;
20  int _previousPosition = -1;
21  int _street = -1;
22  int _timePenalty = 0;
23  double _velocity = 0.;
24  int _timeTraveled = 0;
25 
26 public:
27  Vehicle(int);
28  Vehicle(const Vehicle &v)
29  : _index(v._index), _position(v._position),
30  _previousPosition(v._previousPosition), _street(v._street),
31  _timePenalty(v._timePenalty), _velocity(v._velocity),
32  _timeTraveled(v._timeTraveled) {}
33  ~Vehicle() = default;
34 
35  static void addVehicleType(int,
36  int);
37  static void addVehicleType(
38  std::string);
39  static std::shared_ptr<VehicleType>
40  getVehicleType(int8_t const);
41  static uint8_t
42  getNVehicleType();
43  uint8_t getType()
44  const noexcept; // return the index of the vehicle type in _vehicleType
45  void setPosition(int);
46  uint16_t getPosition() const noexcept;
47  int getPreviousPosition() const noexcept;
48  void setStreet(int);
49  int getStreet() const;
50  uint16_t getDestination() const noexcept;
51  void setTimePenalty(int);
52  int getTimePenalty() const noexcept;
53  void setVelocity(double);
54  double getVelocity() const noexcept;
55  void incrementTimeTraveled() noexcept;
56  int getTimeTraveled() const noexcept;
57  void resetTimeTraveled() noexcept;
58 };
59 
60 #endif
Vehicle class.
Definition: Vehicle.hpp:15
void setTimePenalty(int)
Set the time penalty of the vehicle.
Definition: Vehicle.cpp:126
void setVelocity(double)
Set the velocity of the vehicle.
Definition: Vehicle.cpp:145
Vehicle(int)
create a vehicle of a type in _vehicleType
Definition: Vehicle.cpp:11
uint16_t getPosition() const noexcept
Get the position of the vehicle.
Definition: Vehicle.cpp:108
static std::shared_ptr< VehicleType > getVehicleType(int8_t const)
get a vehicle type from _vehicleType
Definition: Vehicle.cpp:76
uint16_t getDestination() const noexcept
Get the destination of the vehicle.
Definition: Vehicle.cpp:136
double getVelocity() const noexcept
Get the velocity of the vehicle.
Definition: Vehicle.cpp:155
void incrementTimeTraveled() noexcept
Increment the time traveled by the vehicle.
Definition: Vehicle.cpp:157
static uint8_t getNVehicleType()
get the number of vehicle types in _vehicleType
Definition: Vehicle.cpp:89
int getPreviousPosition() const noexcept
Get the previous position of the vehicle.
Definition: Vehicle.cpp:113
int getTimeTraveled() const noexcept
Get the time traveled by the vehicle.
Definition: Vehicle.cpp:160
static void addVehicleType(int, int)
add a vehicle type in _vehicleType
Definition: Vehicle.cpp:24
int getTimePenalty() const noexcept
Get the time penalty of the vehicle.
Definition: Vehicle.cpp:141
int getStreet() const
Get the street of the vehicle.
Definition: Vehicle.cpp:122
void resetTimeTraveled() noexcept
Reset the time traveled by the vehicle, setting it to 0.
Definition: Vehicle.cpp:162
uint8_t getType() const noexcept
Get the vehicle type index.
Definition: Vehicle.cpp:86
void setStreet(int)
Set the street of the vehicle.
Definition: Vehicle.cpp:118
void setPosition(int)
Set the position of the vehicle.
Definition: Vehicle.cpp:96