CARLA
RawData.h
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 #pragma once
8 
9 #include "carla/Buffer.h"
11 
12 #include <cstdint>
13 #include <iterator>
14 
15 namespace carla {
16 namespace sensor {
17 
18  /// Wrapper around the raw data generated by a sensor plus some useful
19  /// meta-information.
20  class RawData {
22  private:
23 
24  const auto &GetHeader() const {
26  }
27 
28  public:
29 
30  /// Type-id of the sensor that generated the data.
31  uint64_t GetSensorTypeId() const {
32  return GetHeader().sensor_type;
33  }
34 
35  /// Frame count when the data was generated.
36  uint64_t GetFrame() const {
37  return GetHeader().frame;
38  }
39 
40  /// Timestamp when the data was generated.
41  double GetTimestamp() const {
42  return GetHeader().timestamp;
43  }
44 
45  /// Sensor's transform when the data was generated.
47  return GetHeader().sensor_transform;
48  }
49 
50  /// Begin iterator to the data generated by the sensor.
51  auto begin() noexcept {
53  }
54 
55  /// @copydoc begin()
56  auto begin() const noexcept {
58  }
59 
60  /// Past-the-end iterator to the data generated by the sensor.
61  auto end() noexcept {
62  return _buffer.end();
63  }
64 
65  /// @copydoc end()
66  auto end() const noexcept {
67  return _buffer.end();
68  }
69 
70  /// Retrieve a pointer to the memory containing the data generated by the
71  /// sensor.
72  auto data() noexcept {
73  return begin();
74  }
75 
76  /// @copydoc data()
77  auto data() const noexcept {
78  return begin();
79  }
80 
81  /// Size in bytes of the data generated by the sensor.
82  size_t size() const {
83  DEBUG_ASSERT(std::distance(begin(), end()) >= 0);
84  return static_cast<size_t>(std::distance(begin(), end()));
85  }
86 
87  private:
88 
89  template <typename... Items>
90  friend class CompositeSerializer;
91 
92  RawData(Buffer &&buffer) : _buffer(std::move(buffer)) {}
93 
95  };
96 
97 } // namespace sensor
98 } // namespace carla
const auto & GetHeader() const
Definition: RawData.h:24
Serializes the meta-information (header) sent with all the sensor data.
auto end() const noexcept
Past-the-end iterator to the data generated by the sensor.
Definition: RawData.h:66
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
auto begin() noexcept
Begin iterator to the data generated by the sensor.
Definition: RawData.h:51
auto begin() const noexcept
Begin iterator to the data generated by the sensor.
Definition: RawData.h:56
size_t size() const
Size in bytes of the data generated by the sensor.
Definition: RawData.h:82
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
Compile-time map for mapping sensor objects to serializers.
auto end() noexcept
Past-the-end iterator to the data generated by the sensor.
Definition: RawData.h:61
const_iterator end() const noexcept
Definition: carla/Buffer.h:230
const_iterator begin() const noexcept
Definition: carla/Buffer.h:218
auto data() const noexcept
Retrieve a pointer to the memory containing the data generated by the sensor.
Definition: RawData.h:77
static const Header & Deserialize(const Buffer &message)
auto data() noexcept
Retrieve a pointer to the memory containing the data generated by the sensor.
Definition: RawData.h:72
uint64_t GetSensorTypeId() const
Type-id of the sensor that generated the data.
Definition: RawData.h:31
const rpc::Transform & GetSensorTransform() const
Sensor&#39;s transform when the data was generated.
Definition: RawData.h:46
double GetTimestamp() const
Timestamp when the data was generated.
Definition: RawData.h:41
A piece of raw data.
Definition: carla/Buffer.h:39
RawData(Buffer &&buffer)
Definition: RawData.h:92
uint64_t GetFrame() const
Frame count when the data was generated.
Definition: RawData.h:36
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition: RawData.h:20