CARLA
CarlaRecorderCollision.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 CarlaRecorderCollision::Read(std::istream &InFile)
12 {
13  // id
14  ReadValue<uint32_t>(InFile, this->Id);
15  // actors database id
16  ReadValue<uint32_t>(InFile, this->DatabaseId1);
17  ReadValue<uint32_t>(InFile, this->DatabaseId2);
18  // is hero
19  ReadValue<bool>(InFile, this->IsActor1Hero);
20  ReadValue<bool>(InFile, this->IsActor2Hero);
21 }
22 void CarlaRecorderCollision::Write(std::ostream &OutFile) const
23 {
24  // id
25  WriteValue<uint32_t>(OutFile, this->Id);
26  // actors database id
27  WriteValue<uint32_t>(OutFile, this->DatabaseId1);
28  WriteValue<uint32_t>(OutFile, this->DatabaseId2);
29  // is hero
30  WriteValue<bool>(OutFile, this->IsActor1Hero);
31  WriteValue<bool>(OutFile, this->IsActor2Hero);
32 }
34 {
35  return (this->DatabaseId1 == Other.DatabaseId1 &&
36  this->DatabaseId2 == Other.DatabaseId2);
37 }
38 //---------------------------------------------
39 
41 {
42  Collisions.clear();
43 }
44 
46 {
47  Collisions.insert(std::move(Collision));
48 }
49 
50 void CarlaRecorderCollisions::Write(std::ostream &OutFile)
51 {
52  // write the packet id
53  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::Collision));
54 
55  // write the packet size
56  uint32_t Total = 2 + Collisions.size() * sizeof(CarlaRecorderCollision);
57  WriteValue<uint32_t>(OutFile, Total);
58 
59  // write total records
60  Total = Collisions.size();
61  WriteValue<uint16_t>(OutFile, Total);
62 
63  // for (uint16_t i=0; i<Total; ++i)
64  for (auto &Coll : Collisions)
65  {
66  Coll.Write(OutFile);
67  }
68 }
bool operator==(const CarlaRecorderCollision &Other) const
void Add(const CarlaRecorderCollision &Collision)
void Write(std::ostream &OutFile) const
void Write(std::ostream &OutFile)
void Read(std::istream &InFile)