CARLA
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Recorder
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
7
#include "
CarlaRecorderState.h
"
8
#include "
CarlaRecorder.h
"
9
#include "
CarlaRecorderHelpers.h
"
10
11
#include <algorithm>
12
#include <limits>
13
14
void
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
22
void
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
32
void
CarlaRecorderStates::Clear
(
void
)
33
{
34
StatesTrafficLights
.clear();
35
}
36
37
void
CarlaRecorderStates::Add
(
const
CarlaRecorderStateTrafficLight
&
State
)
38
{
39
StatesTrafficLights
.push_back(std::move(
State
));
40
}
41
42
void
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
64
void
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
78
const
std::vector<CarlaRecorderStateTrafficLight>&
CarlaRecorderStates::GetStates
()
79
{
80
return
StatesTrafficLights
;
81
}
CarlaRecorderHelpers.h
CarlaRecorderState.h
CarlaRecorder.h
CarlaRecorderPacketId::State
@ State
CarlaRecorderStates::Write
void Write(std::ostream &OutFile)
Definition
CarlaRecorderState.cpp:42
CarlaRecorderStates::Clear
void Clear(void)
Definition
CarlaRecorderState.cpp:32
CarlaRecorderStates::Add
void Add(const CarlaRecorderStateTrafficLight &State)
Definition
CarlaRecorderState.cpp:37
CarlaRecorderStates::StatesTrafficLights
std::vector< CarlaRecorderStateTrafficLight > StatesTrafficLights
Definition
CarlaRecorderState.h:46
CarlaRecorderStates::Read
void Read(std::istream &InFile)
Definition
CarlaRecorderState.cpp:64
CarlaRecorderStates::GetStates
const std::vector< CarlaRecorderStateTrafficLight > & GetStates()
Definition
CarlaRecorderState.cpp:78
CarlaRecorderStateTrafficLight
Definition
CarlaRecorderState.h:15
CarlaRecorderStateTrafficLight::IsFrozen
bool IsFrozen
Definition
CarlaRecorderState.h:17
CarlaRecorderStateTrafficLight::Write
void Write(std::ostream &OutFile)
Definition
CarlaRecorderState.cpp:14
CarlaRecorderStateTrafficLight::State
char State
Definition
CarlaRecorderState.h:19
CarlaRecorderStateTrafficLight::Read
void Read(std::istream &InFile)
Definition
CarlaRecorderState.cpp:22
CarlaRecorderStateTrafficLight::DatabaseId
uint32_t DatabaseId
Definition
CarlaRecorderState.h:16
CarlaRecorderStateTrafficLight::ElapsedTime
float ElapsedTime
Definition
CarlaRecorderState.h:18
Generated by
1.9.8