CARLA
CarlaRecorderEventAdd.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 CarlaRecorderEventAdd::Write(std::ofstream &OutFile) const
12 {
13  // database id
14  WriteValue<uint32_t>(OutFile, this->DatabaseId);
15  WriteValue<uint8_t>(OutFile, this->Type);
16 
17  // transform
18  WriteFVector(OutFile, this->Location);
19  WriteFVector(OutFile, this->Rotation);
20 
21  // description type
22  WriteValue<uint32_t>(OutFile, this->Description.UId);
23  WriteFString(OutFile, this->Description.Id);
24 
25  // attributes
26  uint16_t Total = this->Description.Attributes.size();
27  WriteValue<uint16_t>(OutFile, Total);
28  for (uint16_t i=0; i<Total; ++i)
29  {
30  // type
31  WriteValue<uint8_t>(OutFile, this->Description.Attributes[i].Type);
32  WriteFString(OutFile, this->Description.Attributes[i].Id);
33  WriteFString(OutFile, this->Description.Attributes[i].Value);
34  }
35 }
36 
37 void CarlaRecorderEventAdd::Read(std::ifstream &InFile)
38 {
39  // database id
40  ReadValue<uint32_t>(InFile, this->DatabaseId);
41 
42  // database type
43  ReadValue<uint8_t>(InFile, this->Type);
44 
45  // transform
46  ReadFVector(InFile, this->Location);
47  ReadFVector(InFile, this->Rotation);
48 
49  // description type
50  ReadValue<uint32_t>(InFile, this->Description.UId);
51  ReadFString(InFile, this->Description.Id);
52 
53  // attributes
54  uint16_t Total;
55  ReadValue<uint16_t>(InFile, Total);
56  this->Description.Attributes.clear();
57  this->Description.Attributes.reserve(Total);
58  for (uint16_t i=0; i<Total; ++i)
59  {
61  ReadValue<uint8_t>(InFile, Att.Type);
62  ReadFString(InFile, Att.Id);
63  ReadFString(InFile, Att.Value);
64  this->Description.Attributes.push_back(std::move(Att));
65  }
66 }
67 
68 //---------------------------------------------
69 
71 {
72  Events.clear();
73 }
74 
76 {
77  Events.push_back(std::move(Event));
78 }
79 
80 void CarlaRecorderEventsAdd::Write(std::ofstream &OutFile)
81 {
82  // write the packet id
83  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::EventAdd));
84 
85  std::streampos PosStart = OutFile.tellp();
86 
87  // write a dummy packet size
88  uint32_t Total = 0;
89  WriteValue<uint32_t>(OutFile, Total);
90 
91  // write total records
92  Total = Events.size();
93  WriteValue<uint16_t>(OutFile, Total);
94 
95  for (uint16_t i=0; i<Total; ++i)
96  Events[i].Write(OutFile);
97 
98  // write the real packet size
99  std::streampos PosEnd = OutFile.tellp();
100  Total = PosEnd - PosStart - sizeof(uint32_t);
101  OutFile.seekp(PosStart, std::ios::beg);
102  WriteValue<uint32_t>(OutFile, Total);
103  OutFile.seekp(PosEnd, std::ios::beg);
104 }
void Read(std::ifstream &InFile)
void Add(const CarlaRecorderEventAdd &Event)
void WriteFString(std::ofstream &OutFile, const FString &InObj)
void ReadFString(std::ifstream &InFile, FString &OutObj)
std::vector< CarlaRecorderActorAttribute > Attributes
void Write(std::ofstream &OutFile)
void Write(std::ofstream &OutFile) const
void WriteFVector(std::ofstream &OutFile, const FVector &InObj)
void ReadFVector(std::ifstream &InFile, FVector &OutObj)
CarlaRecorderActorDescription Description