CARLA
Loading...
Searching...
No Matches
CarlaRecorderState.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#include <algorithm>
12#include <limits>
13
14void CarlaRecorderStateTrafficLight::Write(std::ostream &OutFile)
15{
16 WriteValue<uint32_t>(OutFile, this->DatabaseId);
17 WriteValue<bool>(OutFile, this->IsFrozen);
18 WriteValue<float>(OutFile, this->ElapsedTime);
19 WriteValue<char>(OutFile, this->State);
20}
21
22void CarlaRecorderStateTrafficLight::Read(std::istream &InFile)
23{
24 ReadValue<uint32_t>(InFile, this->DatabaseId);
25 ReadValue<bool>(InFile, this->IsFrozen);
26 ReadValue<float>(InFile, this->ElapsedTime);
27 ReadValue<char>(InFile, this->State);
28}
29
30// ---------------------------------------------
31
33{
34 StatesTrafficLights.clear();
35}
36
41
42void CarlaRecorderStates::Write(std::ostream &OutFile)
43{
44 // write the packet id
45 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::State));
46
47 // a uint16 count of records follows; never write more than it can hold
48 const uint16_t Count = std::min<size_t>(StatesTrafficLights.size(), std::numeric_limits<uint16_t>::max());
49
50 // write the packet size
51 uint32_t Total = 2 + Count * sizeof(CarlaRecorderStateTrafficLight);
52 WriteValue<uint32_t>(OutFile, Total);
53
54 // write total records
55 Total = Count;
56 WriteValue<uint16_t>(OutFile, Total);
57
58 for (uint16_t i = 0; i < Total; ++i)
59 {
60 StatesTrafficLights[i].Write(OutFile);
61 }
62}
63
64void CarlaRecorderStates::Read(std::istream &InFile)
65{
66 uint16_t i, Total = 0;
67 CarlaRecorderStateTrafficLight StateTrafficLight;
68
69 // read Total traffic light states
70 ReadValue<uint16_t>(InFile, Total);
71 for (i = 0; (i < Total) && InFile; ++i)
72 {
73 StateTrafficLight.Read(InFile);
74 Add(StateTrafficLight);
75 }
76}
77
78const std::vector<CarlaRecorderStateTrafficLight>& CarlaRecorderStates::GetStates()
79{
81}
void Write(std::ostream &OutFile)
void Add(const CarlaRecorderStateTrafficLight &State)
std::vector< CarlaRecorderStateTrafficLight > StatesTrafficLights
void Read(std::istream &InFile)
const std::vector< CarlaRecorderStateTrafficLight > & GetStates()
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)