CARLA
CarlaRecorderAnimBiker.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 CarlaRecorderAnimBiker::Write(std::ostream &OutFile) const
12 {
13  WriteValue<uint32_t>(OutFile, DatabaseId);
14  WriteValue<float>(OutFile, ForwardSpeed);
15  WriteValue<float>(OutFile, EngineRotation);
16 }
17 
18 void CarlaRecorderAnimBiker::Read(std::istream &InFile)
19 {
20  ReadValue<uint32_t>(InFile, DatabaseId);
21  ReadValue<float>(InFile, ForwardSpeed);
22  ReadValue<float>(InFile, EngineRotation);
23 }
24 
25 // ---------------------------------------------
26 
28 {
29  Bikers.clear();
30 }
31 
33 {
34  Bikers.push_back(Biker);
35 }
36 
37 void CarlaRecorderAnimBikers::Write(std::ostream &OutFile) const
38 {
39  // write the packet id
40  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::AnimBiker));
41 
42  // write the packet size
43  uint32_t Total = 2 + Bikers.size() * sizeof(CarlaRecorderAnimBiker);
44  WriteValue<uint32_t>(OutFile, Total);
45 
46  // write total records
47  Total = Bikers.size();
48  WriteValue<uint16_t>(OutFile, Total);
49 
50  // write records
51  if (Total > 0)
52  {
53  OutFile.write(reinterpret_cast<const char *>(Bikers.data()),
54  Bikers.size() * sizeof(CarlaRecorderAnimBiker));
55  }
56 }
57 
58 void CarlaRecorderAnimBikers::Read(std::istream &InFile)
59 {
60  uint16_t i, Total;
62 
63  // read Total Bikers
64  ReadValue<uint16_t>(InFile, Total);
65  for (i = 0; i < Total; ++i)
66  {
67  Biker.Read(InFile);
68  Add(Biker);
69  }
70 }
71 
72 const std::vector<CarlaRecorderAnimBiker>& CarlaRecorderAnimBikers::GetBikers()
73 {
74  return Bikers;
75 }
void Read(std::istream &InFile)
void Add(const CarlaRecorderAnimBiker &InObj)
const std::vector< CarlaRecorderAnimBiker > & GetBikers()
void Write(std::ostream &OutFile) const
void Read(std::istream &InFile)
void Write(std::ostream &OutFile) const