CARLA
CarlaRecorderTraficLightTime.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 CarlaRecorderTrafficLightTime::Write(std::ostream &OutFile)
13 {
14  WriteValue<uint32_t>(OutFile, this->DatabaseId);
15  WriteValue(OutFile, this->GreenTime);
16  WriteValue(OutFile, this->YellowTime);
17  WriteValue(OutFile, this->RedTime);
18 }
19 
20 void CarlaRecorderTrafficLightTime::Read(std::istream &InFile)
21 {
22  ReadValue<uint32_t>(InFile, this->DatabaseId);
23  ReadValue(InFile, this->GreenTime);
24  ReadValue(InFile, this->YellowTime);
25  ReadValue(InFile, this->RedTime);
26 }
27 
28 // ---------------------------------------------
29 
31 {
32  TrafficLightTimes.clear();
33 }
34 
36 {
37  TrafficLightTimes.push_back(InObj);
38 }
39 
40 void CarlaRecorderTrafficLightTimes::Write(std::ostream &OutFile)
41 {
42  if (TrafficLightTimes.size() == 0)
43  {
44  return;
45  }
46  // write the packet id
47  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::TrafficLightTime));
48 
49  uint32_t Total = sizeof(uint16_t) + TrafficLightTimes.size() * sizeof(CarlaRecorderTrafficLightTime);
50  WriteValue<uint32_t>(OutFile, Total);
51 
52  Total = TrafficLightTimes.size();
53  WriteValue<uint16_t>(OutFile, Total);
54 
55  for (auto& TrafficLightTime : TrafficLightTimes)
56  {
57  TrafficLightTime.Write(OutFile);
58  }
59 }
void ReadValue(std::istream &InFile, T &OutObj)
void Add(const CarlaRecorderTrafficLightTime &InObj)
void WriteValue(std::ostream &OutFile, const T &InObj)