CARLA
CarlaRecorderEventParent.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 
12 void CarlaRecorderEventParent::Read(std::ifstream &InFile)
13 {
14  // database id
15  ReadValue<uint32_t>(InFile, this->DatabaseId);
16  // database id parent
17  ReadValue<uint32_t>(InFile, this->DatabaseIdParent);
18 }
19 void CarlaRecorderEventParent::Write(std::ofstream &OutFile) const
20 {
21  // database id
22  WriteValue<uint32_t>(OutFile, this->DatabaseId);
23  // database id parent
24  WriteValue<uint32_t>(OutFile, this->DatabaseIdParent);
25 }
26 
27 //---------------------------------------------
28 
30 {
31  Events.clear();
32 }
33 
35 {
36  Events.push_back(std::move(Event));
37 }
38 
39 void CarlaRecorderEventsParent::Write(std::ofstream &OutFile)
40 {
41  // write the packet id
42  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::EventParent));
43 
44  std::streampos PosStart = OutFile.tellp();
45 
46  // write a dummy packet size
47  uint32_t Total = 0;
48  WriteValue<uint32_t>(OutFile, Total);
49 
50  // write total records
51  Total = Events.size();
52  WriteValue<uint16_t>(OutFile, Total);
53 
54  for (uint16_t i=0; i<Total; ++i)
55  {
56  Events[i].Write(OutFile);
57  }
58 
59  // write the real packet size
60  std::streampos PosEnd = OutFile.tellp();
61  Total = PosEnd - PosStart - sizeof(uint32_t);
62  OutFile.seekp(PosStart, std::ios::beg);
63  WriteValue<uint32_t>(OutFile, Total);
64  OutFile.seekp(PosEnd, std::ios::beg);
65 }
void Write(std::ofstream &OutFile) const
void Write(std::ofstream &OutFile)
void Read(std::ifstream &InFile)
void Add(const CarlaRecorderEventParent &Event)