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