CARLA
CarlaRecorderLightVehicle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
8 #include "CarlaRecorder.h"
9 #include "CarlaRecorderHelpers.h"
10 
11 
12 void CarlaRecorderLightVehicle::Write(std::ostream &OutFile)
13 {
14  // database id
15  WriteValue<uint32_t>(OutFile, this->DatabaseId);
16  WriteValue<VehicleLightStateType>(OutFile, this->State);
17 }
18 void CarlaRecorderLightVehicle::Read(std::istream &InFile)
19 {
20  // database id
21  ReadValue<uint32_t>(InFile, this->DatabaseId);
22  ReadValue<VehicleLightStateType>(InFile, this->State);
23 }
24 
25 // ---------------------------------------------
26 
28 {
29  Vehicles.clear();
30 }
31 
33 {
34  Vehicles.push_back(Vehicle);
35 }
36 
37 void CarlaRecorderLightVehicles::Write(std::ostream &OutFile)
38 {
39  // write the packet id
40  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::VehicleLight));
41 
42  // write a dummy packet size
43  uint32_t Total = 2 + Vehicles.size() * sizeof(CarlaRecorderLightVehicle);
44  WriteValue<uint32_t>(OutFile, Total);
45 
46  // write total records
47  Total = Vehicles.size();
48  WriteValue<uint16_t>(OutFile, Total);
49 
50  for (auto& Vehicle : Vehicles)
51  {
52  Vehicle.Write(OutFile);
53  }
54 }
55 
56 void CarlaRecorderLightVehicles::Read(std::istream &InFile)
57 {
58  uint16_t Total;
59  CarlaRecorderLightVehicle LightVehicle;
60 
61  // read Total walkers
62  ReadValue<uint16_t>(InFile, Total);
63  for (uint16_t i = 0; i < Total; ++i)
64  {
65  LightVehicle.Read(InFile);
66  Add(LightVehicle);
67  }
68 }
69 
70 const std::vector<CarlaRecorderLightVehicle>& CarlaRecorderLightVehicles::GetLightVehicles()
71 {
72  return Vehicles;
73 }
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderLightVehicle &InObj)
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderLightVehicle > & GetLightVehicles()
void Read(std::istream &InFile)
void Read(std::istream &InFile)