CARLA
CarlaRecorderState.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"
8 #include "CarlaRecorderState.h"
9 #include "CarlaRecorderHelpers.h"
10 
11 void CarlaRecorderStateTrafficLight::Write(std::ostream &OutFile)
12 {
13  WriteValue<uint32_t>(OutFile, this->DatabaseId);
14  WriteValue<bool>(OutFile, this->IsFrozen);
15  WriteValue<float>(OutFile, this->ElapsedTime);
16  WriteValue<char>(OutFile, this->State);
17 }
18 
19 void CarlaRecorderStateTrafficLight::Read(std::istream &InFile)
20 {
21  ReadValue<uint32_t>(InFile, this->DatabaseId);
22  ReadValue<bool>(InFile, this->IsFrozen);
23  ReadValue<float>(InFile, this->ElapsedTime);
24  ReadValue<char>(InFile, this->State);
25 }
26 
27 // ---------------------------------------------
28 
30 {
31  StatesTrafficLights.clear();
32 }
33 
35 {
36  StatesTrafficLights.push_back(std::move(State));
37 }
38 
39 void CarlaRecorderStates::Write(std::ostream &OutFile)
40 {
41  // write the packet id
42  WriteValue<char>(OutFile, static_cast<char>(CarlaRecorderPacketId::State));
43 
44  // write the packet size
45  uint32_t Total = 2 + StatesTrafficLights.size() * sizeof(CarlaRecorderStateTrafficLight);
46  WriteValue<uint32_t>(OutFile, Total);
47 
48  // write total records
49  Total = StatesTrafficLights.size();
50  WriteValue<uint16_t>(OutFile, Total);
51 
52  for (uint16_t i = 0; i < Total; ++i)
53  {
54  StatesTrafficLights[i].Write(OutFile);
55  }
56 }
57 
58 void CarlaRecorderStates::Read(std::istream &InFile)
59 {
60  uint16_t i, Total;
61  CarlaRecorderStateTrafficLight StateTrafficLight;
62 
63  // read Total traffic light states
64  ReadValue<uint16_t>(InFile, Total);
65  for (i = 0; i < Total; ++i)
66  {
67  StateTrafficLight.Read(InFile);
68  Add(StateTrafficLight);
69  }
70 }
71 
72 const std::vector<CarlaRecorderStateTrafficLight>& CarlaRecorderStates::GetStates()
73 {
74  return StatesTrafficLights;
75 }
void Read(std::istream &InFile)
void Add(const CarlaRecorderStateTrafficLight &State)
void Write(std::ostream &OutFile)
const std::vector< CarlaRecorderStateTrafficLight > & GetStates()
void Read(std::istream &InFile)
void Write(std::ostream &OutFile)