CARLA
Loading...
Searching...
No Matches
CarlaRecorderEventDel.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 CarlaRecorderEventDel::Read(std::istream &InFile)
15{
16 // database id
17 ReadValue<uint32_t>(InFile, this->DatabaseId);
18}
19void CarlaRecorderEventDel::Write(std::ostream &OutFile) const
20{
21 // database id
22 WriteValue<uint32_t>(OutFile, this->DatabaseId);
23}
24
25//---------------------------------------------
26
28{
29 Events.clear();
30}
31
33{
34 Events.push_back(std::move(Event));
35}
36
37void CarlaRecorderEventsDel::Write(std::ostream &OutFile)
38{
39 // write the packet id
40 WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::EventDel));
41
42 std::streampos PosStart = OutFile.tellp();
43
44 // write a dummy packet size
45 uint32_t Total = 0;
46 WriteValue<uint32_t>(OutFile, Total);
47
48 // write total records
49 Total = std::min<size_t>(Events.size(), std::numeric_limits<uint16_t>::max());
50 WriteValue<uint16_t>(OutFile, Total);
51
52 for (uint16_t i=0; i<Total; ++i)
53 {
54 Events[i].Write(OutFile);
55 }
56
57 // write the real packet size
58 std::streampos PosEnd = OutFile.tellp();
59 Total = PosEnd - PosStart - sizeof(uint32_t);
60 OutFile.seekp(PosStart, std::ios::beg);
61 WriteValue<uint32_t>(OutFile, Total);
62 OutFile.seekp(PosEnd, std::ios::beg);
63}
64
65void CarlaRecorderEventsDel::Read(std::istream &InFile)
66{
67 uint16_t i, Total = 0;
69
70 // process destroy events
71 ReadValue<uint16_t>(InFile, Total);
72 for (i = 0; (i < Total) && InFile; ++i)
73 {
74 EventDel.Read(InFile);
76 }
77}
78
79const std::vector<CarlaRecorderEventDel>& CarlaRecorderEventsDel::GetEvents()
80{
81 return Events;
82}
void Add(const CarlaRecorderEventDel &Event)
const std::vector< CarlaRecorderEventDel > & GetEvents()
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)
std::vector< CarlaRecorderEventDel > Events
void Read(std::istream &InFile)
void Write(std::ostream &OutFile) const