CARLA
CarlaRecorderEventDel.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017 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 "CarlaRecorder.h"
9 #include "CarlaRecorderHelpers.h"
10 
11 void CarlaRecorderEventDel::Read(std::istream &InFile)
12 {
13  // database id
14  ReadValue<uint32_t>(InFile, this->DatabaseId);
15 }
16 void CarlaRecorderEventDel::Write(std::ostream &OutFile) const
17 {
18  // database id
19  WriteValue<uint32_t>(OutFile, this->DatabaseId);
20 }
21 
22 //---------------------------------------------
23 
25 {
26  Events.clear();
27 }
28 
30 {
31  Events.push_back(std::move(Event));
32 }
33 
34 void CarlaRecorderEventsDel::Write(std::ostream &OutFile)
35 {
36  // write the packet id
37  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::EventDel));
38 
39  std::streampos PosStart = OutFile.tellp();
40 
41  // write a dummy packet size
42  uint32_t Total = 0;
43  WriteValue<uint32_t>(OutFile, Total);
44 
45  // write total records
46  Total = Events.size();
47  WriteValue<uint16_t>(OutFile, Total);
48 
49  for (uint16_t i=0; i<Total; ++i)
50  {
51  Events[i].Write(OutFile);
52  }
53 
54  // write the real packet size
55  std::streampos PosEnd = OutFile.tellp();
56  Total = PosEnd - PosStart - sizeof(uint32_t);
57  OutFile.seekp(PosStart, std::ios::beg);
58  WriteValue<uint32_t>(OutFile, Total);
59  OutFile.seekp(PosEnd, std::ios::beg);
60 }
61 
62 void CarlaRecorderEventsDel::Read(std::istream &InFile)
63 {
64  uint16_t i, Total;
66 
67  // process destroy events
68  ReadValue<uint16_t>(InFile, Total);
69  for (i = 0; i < Total; ++i)
70  {
71  EventDel.Read(InFile);
72  Add(EventDel);
73  }
74 }
75 
76 const std::vector<CarlaRecorderEventDel>& CarlaRecorderEventsDel::GetEvents()
77 {
78  return Events;
79 }
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderEventDel > & GetEvents()
void Read(std::istream &InFile)
void Add(const CarlaRecorderEventDel &Event)
void Read(std::istream &InFile)
void Write(std::ostream &OutFile) const