CARLA
Loading...
Searching...
No Matches
CarlaRecorderTraficLightTime.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 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"
10
11
12void 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
20void 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
34
39
40void 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
56 {
57 TrafficLightTime.Write(OutFile);
58 }
59}
60
61void CarlaRecorderTrafficLightTimes::Read(std::istream &InFile)
62{
63 uint16_t Total = 0;
64 ReadValue<uint16_t>(InFile, Total);
65 for (uint16_t i = 0; (i < Total) && InFile; ++i)
66 {
68 Record.Read(InFile);
69 Add(Record);
70 }
71}
72
73const std::vector<CarlaRecorderTrafficLightTime>& CarlaRecorderTrafficLightTimes::GetTrafficLightTimes() const
74{
75 return TrafficLightTimes;
76}
77
79{
80 return TrafficLightTimes.empty();
81}
void WriteValue(std::ostream &OutFile, const T &InObj)
void ReadValue(std::istream &InFile, T &OutObj)
const std::vector< CarlaRecorderTrafficLightTime > & GetTrafficLightTimes() const
void Add(const CarlaRecorderTrafficLightTime &InObj)
std::vector< CarlaRecorderTrafficLightTime > TrafficLightTimes