LCOV - code coverage report
Current view: top level - src/zerocopy - occupancy_grid.cc (source / functions) Hit Total Coverage
Test: vlink Lines: 272 278 97.8 %
Date: 2026-06-27 19:56:04 Functions: 60 60 100.0 %
Branches: 105 138 76.1 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2026 by Thun Lu. All rights reserved.
       3                 :            :  * Author: Thun Lu <thun.lu@zohomail.cn>
       4                 :            :  * Repo:   https://github.com/thun-res/vlink
       5                 :            :  *  _    __   __      _           __
       6                 :            :  * | |  / /  / /     (_) ____    / /__
       7                 :            :  * | | / /  / /     / / / __ \  / //_/
       8                 :            :  * | |/ /  / /___  / / / / / / / ,<
       9                 :            :  * |___/  /_____/ /_/ /_/ /_/ /_/|_|
      10                 :            :  *
      11                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
      12                 :            :  * you may not use this file except in compliance with the License.
      13                 :            :  * You may obtain a copy of the License at
      14                 :            :  *
      15                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
      16                 :            :  *
      17                 :            :  * Unless required by applicable law or agreed to in writing, software
      18                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      19                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      20                 :            :  * See the License for the specific language governing permissions and
      21                 :            :  * limitations under the License.
      22                 :            :  */
      23                 :            : 
      24                 :            : #include "./zerocopy/occupancy_grid.h"
      25                 :            : 
      26                 :            : #include <cstdint>
      27                 :            : 
      28                 :            : namespace vlink {
      29                 :            : 
      30                 :            : namespace zerocopy {
      31                 :            : 
      32                 :            : // OccupancyGrid
      33                 :         53 : OccupancyGrid::OccupancyGrid() noexcept {
      34                 :            : #if defined(__arm__) || defined(__x86__) || defined(__i386__)
      35                 :            : #ifndef __ANDROID__
      36                 :            : #warning "[OccupancyGrid] No support for 32-bit architecture."
      37                 :            : #endif
      38                 :            : #else
      39                 :            :   static_assert(sizeof(OccupancyGrid) == 152, "Sizeof must be 152 bytes.");
      40                 :            : #endif
      41                 :         53 : }
      42                 :            : 
      43                 :         55 : OccupancyGrid::~OccupancyGrid() noexcept {
      44   [ +  +  +  -  :         55 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
      45                 :         30 :     Bytes::bytes_free(data_, size_);
      46                 :            :   }
      47                 :         55 : }
      48                 :            : 
      49                 :          1 : OccupancyGrid::OccupancyGrid(const OccupancyGrid& target) noexcept { deep_copy(target); }
      50                 :            : 
      51                 :          1 : OccupancyGrid::OccupancyGrid(OccupancyGrid&& target) noexcept { move_copy(target); }
      52                 :            : 
      53                 :          1 : OccupancyGrid& OccupancyGrid::operator=(const OccupancyGrid& target) noexcept {
      54         [ -  + ]:          1 :   if VUNLIKELY (this == &target) {
      55                 :          0 :     return *this;
      56                 :            :   }
      57                 :            : 
      58                 :          1 :   deep_copy(target);
      59                 :            : 
      60                 :          1 :   return *this;
      61                 :            : }
      62                 :            : 
      63                 :          1 : OccupancyGrid& OccupancyGrid::operator=(OccupancyGrid&& target) noexcept {
      64         [ -  + ]:          1 :   if VUNLIKELY (this == &target) {
      65                 :          0 :     return *this;
      66                 :            :   }
      67                 :            : 
      68                 :          1 :   move_copy(target);
      69                 :            : 
      70                 :          1 :   return *this;
      71                 :            : }
      72                 :            : 
      73                 :          7 : bool OccupancyGrid::operator<<(const Bytes& bytes) noexcept {
      74                 :            :   static constexpr size_t kMagicNumberBeginSize = sizeof(kMagicNumberBegin);
      75                 :            :   static constexpr size_t kVersionSize = sizeof(kWireVersion);
      76                 :            :   // static constexpr size_t kMagicNumberEndSize = sizeof(kMagicNumberEnd);
      77                 :            : 
      78         [ +  + ]:          7 :   if VUNLIKELY (bytes.empty()) {
      79                 :          1 :     return false;
      80                 :            :   }
      81                 :            : 
      82         [ +  + ]:          6 :   if VUNLIKELY (!check_valid(bytes)) {
      83                 :          2 :     return false;
      84                 :            :   }
      85                 :            : 
      86                 :          4 :   uint32_t wire_version = 0;
      87                 :          4 :   std::memcpy(&wire_version, bytes.data() + kMagicNumberBeginSize, kVersionSize);
      88                 :            : 
      89         [ -  + ]:          4 :   if VUNLIKELY (version_major(wire_version) != version_major(kWireVersion)) {
      90                 :          0 :     return false;
      91                 :            :   }
      92                 :            : 
      93   [ +  +  +  -  :          4 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
      94                 :          1 :     Bytes::bytes_free(data_, size_);
      95                 :            :   }
      96                 :            : 
      97                 :            : #if defined(__GNUC__) && !defined(__clang__)
      98                 :            : #pragma GCC diagnostic push
      99                 :            : #pragma GCC diagnostic ignored "-Wclass-memaccess"
     100                 :            : #if __GNUC__ >= 11
     101                 :            : #pragma GCC diagnostic ignored "-Wstringop-overread"
     102                 :            : #endif
     103                 :            : #endif
     104                 :            : 
     105                 :          4 :   auto* target_ptr = reinterpret_cast<uint8_t*>(this);
     106                 :            : 
     107                 :          4 :   std::memcpy(target_ptr, bytes.data() + kMagicNumberBeginSize + kVersionSize, sizeof(OccupancyGrid));
     108                 :            : 
     109                 :            : #if defined(__GNUC__) && !defined(__clang__)
     110                 :            : #pragma GCC diagnostic pop
     111                 :            : #endif
     112                 :            : 
     113                 :          4 :   data_ = const_cast<uint8_t*>(bytes.data() + kMagicNumberBeginSize + kVersionSize + sizeof(OccupancyGrid));
     114                 :          4 :   is_owner_ = false;
     115                 :            : 
     116         [ +  + ]:          4 :   if VUNLIKELY (bytes.size() != get_serialized_size()) {
     117                 :          1 :     clear();
     118                 :          1 :     return false;
     119                 :            :   }
     120                 :            : 
     121                 :          3 :   return true;
     122                 :            : }
     123                 :            : 
     124                 :          7 : bool OccupancyGrid::operator>>(Bytes& bytes) const noexcept {
     125                 :            :   static constexpr size_t kMagicNumberBeginSize = sizeof(kMagicNumberBegin);
     126                 :            :   static constexpr size_t kVersionSize = sizeof(kWireVersion);
     127                 :            :   static constexpr size_t kMagicNumberEndSize = sizeof(kMagicNumberEnd);
     128                 :            : 
     129   [ +  +  -  +  :          7 :   if (bytes.empty() || bytes.size() != get_serialized_size()) {
                   +  + ]
     130                 :          6 :     bytes = Bytes::create(get_serialized_size());
     131                 :            :   }
     132                 :            : 
     133                 :          7 :   std::memcpy(bytes.data(), &kMagicNumberBegin, kMagicNumberBeginSize);
     134                 :            : 
     135                 :          7 :   std::memcpy(bytes.data() + kMagicNumberBeginSize, &kWireVersion, kVersionSize);
     136                 :            : 
     137                 :            :   // NOLINTNEXTLINE(bugprone-undefined-memory-manipulation)
     138                 :          7 :   std::memcpy(bytes.data() + kMagicNumberBeginSize + kVersionSize, this, sizeof(OccupancyGrid));
     139                 :            : 
     140   [ +  +  +  -  :          7 :   if VLIKELY (data_ != nullptr && size_ != 0) {
                   +  + ]
     141                 :          6 :     std::memcpy(bytes.data() + kMagicNumberBeginSize + kVersionSize + sizeof(OccupancyGrid), data_, size_);
     142                 :            :   }
     143                 :            : 
     144                 :          7 :   std::memcpy(bytes.data() + kMagicNumberBeginSize + kVersionSize + sizeof(OccupancyGrid) + size_, &kMagicNumberEnd,
     145                 :            :               kMagicNumberEndSize);
     146                 :            : 
     147                 :          7 :   return true;
     148                 :            : }
     149                 :            : 
     150                 :         13 : bool OccupancyGrid::check_valid(const Bytes& bytes) noexcept {
     151                 :            :   static constexpr size_t kMagicNumberBeginSize = sizeof(kMagicNumberBegin);
     152                 :            :   static constexpr size_t kVersionSize = sizeof(kWireVersion);
     153                 :            :   static constexpr size_t kMagicNumberEndSize = sizeof(kMagicNumberEnd);
     154                 :            : 
     155         [ +  + ]:         13 :   if VUNLIKELY (bytes.size() < kMagicNumberBeginSize + kVersionSize + sizeof(OccupancyGrid) + kMagicNumberEndSize) {
     156                 :          2 :     return false;
     157                 :            :   }
     158                 :            : 
     159                 :         11 :   uint32_t check_magic = 0;
     160                 :            : 
     161                 :         11 :   std::memcpy(&check_magic, bytes.begin(), kMagicNumberBeginSize);
     162                 :            : 
     163         [ +  + ]:         11 :   if VUNLIKELY (check_magic != kMagicNumberBegin) {
     164                 :          1 :     return false;
     165                 :            :   }
     166                 :            : 
     167                 :         10 :   uint32_t wire_version = 0;
     168                 :         10 :   std::memcpy(&wire_version, bytes.data() + kMagicNumberBeginSize, kVersionSize);
     169                 :            : 
     170         [ +  + ]:         10 :   if VUNLIKELY (version_major(wire_version) != version_major(kWireVersion)) {
     171                 :          2 :     return false;
     172                 :            :   }
     173                 :            : 
     174                 :          8 :   std::memcpy(&check_magic, bytes.end() - kMagicNumberEndSize, kMagicNumberEndSize);
     175                 :            : 
     176         [ +  + ]:          8 :   if VUNLIKELY (check_magic != kMagicNumberEnd) {
     177                 :          1 :     return false;
     178                 :            :   }
     179                 :            : 
     180                 :          7 :   return true;
     181                 :            : }
     182                 :            : 
     183                 :         15 : size_t OccupancyGrid::get_serialized_size() const noexcept {
     184                 :            :   static constexpr size_t kMagicNumberBeginSize = sizeof(kMagicNumberBegin);
     185                 :            :   static constexpr size_t kVersionSize = sizeof(kWireVersion);
     186                 :            :   static constexpr size_t kMagicNumberEndSize = sizeof(kMagicNumberEnd);
     187                 :            : 
     188                 :         15 :   return kMagicNumberBeginSize + kVersionSize + sizeof(OccupancyGrid) + size_ + kMagicNumberEndSize;
     189                 :            : }
     190                 :            : 
     191   [ +  +  +  - ]:         21 : bool OccupancyGrid::is_valid() const noexcept { return data_ != nullptr && size_ != 0; }
     192                 :            : 
     193                 :          9 : bool OccupancyGrid::shallow_copy(const OccupancyGrid& target) noexcept {
     194         [ +  + ]:          9 :   if VUNLIKELY (this == &target) {
     195                 :          2 :     return false;
     196                 :            :   }
     197                 :            : 
     198   [ -  +  -  -  :          7 :   if (is_owner_ && data_ && size_ != 0) {
                   -  - ]
     199                 :          0 :     Bytes::bytes_free(data_, size_);
     200                 :            :   }
     201                 :            : 
     202                 :          7 :   header = target.header;
     203                 :            : 
     204                 :          7 :   update_time_ns_ = target.update_time_ns_;
     205                 :          7 :   std::memcpy(map_id_, target.map_id_, sizeof(map_id_));
     206                 :          7 :   channel_ = target.channel_;
     207                 :          7 :   freq_ = target.freq_;
     208                 :          7 :   width_ = target.width_;
     209                 :          7 :   height_ = target.height_;
     210                 :          7 :   valid_cell_count_ = target.valid_cell_count_;
     211                 :          7 :   resolution_ = target.resolution_;
     212                 :          7 :   origin_x_ = target.origin_x_;
     213                 :          7 :   origin_y_ = target.origin_y_;
     214                 :          7 :   origin_z_ = target.origin_z_;
     215                 :          7 :   origin_yaw_ = target.origin_yaw_;
     216                 :          7 :   value_min_ = target.value_min_;
     217                 :          7 :   value_max_ = target.value_max_;
     218                 :          7 :   default_value_ = target.default_value_;
     219                 :          7 :   occupied_threshold_ = target.occupied_threshold_;
     220                 :          7 :   free_threshold_ = target.free_threshold_;
     221                 :          7 :   cell_type_ = target.cell_type_;
     222                 :          7 :   reserved_buf_ = target.reserved_buf_;
     223                 :          7 :   reserved_buf2_ = target.reserved_buf2_;
     224                 :          7 :   reserved_buf3_ = target.reserved_buf3_;
     225                 :          7 :   is_owner_ = false;
     226                 :          7 :   data_ = target.data_;
     227                 :          7 :   size_ = target.size_;
     228                 :            : 
     229                 :          7 :   return true;
     230                 :            : }
     231                 :            : 
     232                 :          5 : bool OccupancyGrid::deep_copy(const OccupancyGrid& target) noexcept {
     233   [ +  +  +  -  :          5 :   if VLIKELY (data_ && is_owner_ && target.data_ && size_ != 0 && size_ == target.size_) {
          +  +  +  -  +  
          +  +  -  +  +  
             +  -  +  + ]
     234         [ +  + ]:          2 :     if VUNLIKELY (this == &target) {
     235                 :          1 :       return false;
     236                 :            :     }
     237                 :            : 
     238                 :          1 :     header = target.header;
     239                 :            : 
     240                 :          1 :     update_time_ns_ = target.update_time_ns_;
     241                 :          1 :     std::memcpy(map_id_, target.map_id_, sizeof(map_id_));
     242                 :          1 :     channel_ = target.channel_;
     243                 :          1 :     freq_ = target.freq_;
     244                 :          1 :     width_ = target.width_;
     245                 :          1 :     height_ = target.height_;
     246                 :          1 :     valid_cell_count_ = target.valid_cell_count_;
     247                 :          1 :     resolution_ = target.resolution_;
     248                 :          1 :     origin_x_ = target.origin_x_;
     249                 :          1 :     origin_y_ = target.origin_y_;
     250                 :          1 :     origin_z_ = target.origin_z_;
     251                 :          1 :     origin_yaw_ = target.origin_yaw_;
     252                 :          1 :     value_min_ = target.value_min_;
     253                 :          1 :     value_max_ = target.value_max_;
     254                 :          1 :     default_value_ = target.default_value_;
     255                 :          1 :     occupied_threshold_ = target.occupied_threshold_;
     256                 :          1 :     free_threshold_ = target.free_threshold_;
     257                 :          1 :     cell_type_ = target.cell_type_;
     258                 :          1 :     reserved_buf_ = target.reserved_buf_;
     259                 :          1 :     reserved_buf2_ = target.reserved_buf2_;
     260                 :          1 :     reserved_buf3_ = target.reserved_buf3_;
     261                 :            : 
     262                 :          1 :     std::memcpy(data_, target.data_, size_);
     263                 :            : 
     264                 :          1 :     return true;
     265                 :            :   }
     266                 :            : 
     267         [ -  + ]:          3 :   if VUNLIKELY (!shallow_copy(target)) {
     268                 :          0 :     return false;
     269                 :            :   }
     270                 :            : 
     271   [ +  -  +  - ]:          3 :   if (data_ && size_ != 0) {
     272                 :          3 :     data_ = Bytes::bytes_malloc(size_);
     273                 :            : 
     274                 :          3 :     std::memcpy(data_, target.data_, size_);
     275                 :            : 
     276                 :          3 :     is_owner_ = true;
     277                 :            :   }
     278                 :            : 
     279                 :          3 :   return true;
     280                 :            : }
     281                 :            : 
     282                 :          4 : bool OccupancyGrid::move_copy(OccupancyGrid& target) noexcept {
     283         [ +  + ]:          4 :   if VUNLIKELY (!shallow_copy(target)) {
     284                 :          1 :     return false;
     285                 :            :   }
     286                 :            : 
     287                 :          3 :   is_owner_ = target.is_owner_;
     288                 :            : 
     289                 :          3 :   target.update_time_ns_ = 0;
     290                 :          3 :   std::memset(target.map_id_, 0, sizeof(target.map_id_));
     291                 :          3 :   target.channel_ = 0;
     292                 :          3 :   target.freq_ = 0;
     293                 :          3 :   target.width_ = 0;
     294                 :          3 :   target.height_ = 0;
     295                 :          3 :   target.valid_cell_count_ = 0;
     296                 :          3 :   target.resolution_ = 0;
     297                 :          3 :   target.origin_x_ = 0;
     298                 :          3 :   target.origin_y_ = 0;
     299                 :          3 :   target.origin_z_ = 0;
     300                 :          3 :   target.origin_yaw_ = 0;
     301                 :          3 :   target.value_min_ = 0;
     302                 :          3 :   target.value_max_ = 0;
     303                 :          3 :   target.default_value_ = 0;
     304                 :          3 :   target.occupied_threshold_ = 0;
     305                 :          3 :   target.free_threshold_ = 0;
     306                 :          3 :   target.cell_type_ = kCellUnknown;
     307                 :          3 :   target.reserved_buf_ = 0;
     308                 :          3 :   target.reserved_buf2_ = 0;
     309                 :          3 :   target.reserved_buf3_ = 0;
     310                 :          3 :   target.is_owner_ = false;
     311                 :          3 :   target.data_ = nullptr;
     312                 :          3 :   target.size_ = 0;
     313                 :            : 
     314                 :            : #if defined(__GNUC__) && !defined(__clang__)
     315                 :            : #pragma GCC diagnostic push
     316                 :            : #pragma GCC diagnostic ignored "-Wclass-memaccess"
     317                 :            : #if __GNUC__ >= 11
     318                 :            : #pragma GCC diagnostic ignored "-Wstringop-overread"
     319                 :            : #endif
     320                 :            : #endif
     321                 :            : 
     322                 :          3 :   std::memset(&target.header, 0, sizeof(header));
     323                 :            : 
     324                 :            : #if defined(__GNUC__) && !defined(__clang__)
     325                 :            : #pragma GCC diagnostic pop
     326                 :            : #endif
     327                 :            : 
     328                 :          3 :   return true;
     329                 :            : }
     330                 :            : 
     331                 :         35 : bool OccupancyGrid::create(size_t _size) noexcept {
     332         [ +  + ]:         35 :   if VUNLIKELY (_size == 0) {
     333                 :          1 :     return false;
     334                 :            :   }
     335                 :            : 
     336   [ +  +  +  -  :         34 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
     337                 :          2 :     Bytes::bytes_free(data_, size_);
     338                 :            :   }
     339                 :            : 
     340                 :         34 :   size_ = _size;
     341                 :            : 
     342                 :         34 :   data_ = Bytes::bytes_malloc(size_);
     343                 :            : 
     344                 :         34 :   is_owner_ = true;
     345                 :            : 
     346                 :         34 :   return true;
     347                 :            : }
     348                 :            : 
     349                 :          5 : void OccupancyGrid::clear() noexcept {
     350   [ +  +  +  -  :          5 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
     351                 :          4 :     Bytes::bytes_free(data_, size_);
     352                 :            :   }
     353                 :            : 
     354                 :          5 :   update_time_ns_ = 0;
     355                 :          5 :   std::memset(map_id_, 0, sizeof(map_id_));
     356                 :          5 :   channel_ = 0;
     357                 :          5 :   freq_ = 0;
     358                 :          5 :   width_ = 0;
     359                 :          5 :   height_ = 0;
     360                 :          5 :   valid_cell_count_ = 0;
     361                 :          5 :   resolution_ = 0;
     362                 :          5 :   origin_x_ = 0;
     363                 :          5 :   origin_y_ = 0;
     364                 :          5 :   origin_z_ = 0;
     365                 :          5 :   origin_yaw_ = 0;
     366                 :          5 :   value_min_ = 0;
     367                 :          5 :   value_max_ = 0;
     368                 :          5 :   default_value_ = 0;
     369                 :          5 :   occupied_threshold_ = 0;
     370                 :          5 :   free_threshold_ = 0;
     371                 :          5 :   cell_type_ = kCellUnknown;
     372                 :          5 :   is_owner_ = false;
     373                 :          5 :   data_ = nullptr;
     374                 :          5 :   size_ = 0;
     375                 :            : 
     376                 :            : #if defined(__GNUC__) && !defined(__clang__)
     377                 :            : #pragma GCC diagnostic push
     378                 :            : #pragma GCC diagnostic ignored "-Wclass-memaccess"
     379                 :            : #if __GNUC__ >= 11
     380                 :            : #pragma GCC diagnostic ignored "-Wstringop-overread"
     381                 :            : #endif
     382                 :            : #endif
     383                 :            : 
     384                 :          5 :   std::memset(&header, 0, sizeof(header));
     385                 :            : 
     386                 :            : #if defined(__GNUC__) && !defined(__clang__)
     387                 :            : #pragma GCC diagnostic pop
     388                 :            : #endif
     389                 :          5 : }
     390                 :            : 
     391                 :          5 : bool OccupancyGrid::shallow_copy(uint8_t* data, size_t size) noexcept {
     392   [ +  +  +  +  :          5 :   if VUNLIKELY (!data || size == 0) {
                   +  + ]
     393                 :          2 :     return false;
     394                 :            :   }
     395                 :            : 
     396         [ +  + ]:          3 :   if VUNLIKELY (data_ == data) {
     397                 :          1 :     return false;
     398                 :            :   }
     399                 :            : 
     400   [ -  +  -  -  :          2 :   if (is_owner_ && data_ && size_ != 0) {
                   -  - ]
     401                 :          0 :     Bytes::bytes_free(data_, size_);
     402                 :            :   }
     403                 :            : 
     404                 :          2 :   is_owner_ = false;
     405                 :            : 
     406                 :          2 :   data_ = data;
     407                 :          2 :   size_ = size;
     408                 :            : 
     409                 :          2 :   return true;
     410                 :            : }
     411                 :            : 
     412                 :          8 : bool OccupancyGrid::deep_copy(uint8_t* data, size_t size) noexcept {
     413   [ +  +  +  +  :          8 :   if VUNLIKELY (!data || size == 0) {
                   +  + ]
     414                 :          4 :     return false;
     415                 :            :   }
     416                 :            : 
     417         [ +  + ]:          4 :   if (is_owner_) {
     418         [ -  + ]:          2 :     if VUNLIKELY (!data_) {
     419                 :            :       return false;  // LCOV_EXCL_LINE GCOVR_EXCL_LINE
     420                 :            :     }
     421                 :            : 
     422         [ +  + ]:          2 :     if VUNLIKELY (data_ == data) {
     423                 :          1 :       return false;
     424                 :            :     }
     425                 :            : 
     426         [ +  - ]:          1 :     if VUNLIKELY (size_ != size) {
     427                 :          1 :       create(size);
     428                 :            :     }
     429                 :            :   } else {
     430                 :          2 :     create(size);
     431                 :            :   }
     432                 :            : 
     433                 :          3 :   std::memcpy(data_, data, size);
     434                 :            : 
     435                 :          3 :   return true;
     436                 :            : }
     437                 :            : 
     438                 :          3 : bool OccupancyGrid::fill_data(uint8_t* data, size_t size) noexcept { return deep_copy(data, size); }
     439                 :            : 
     440                 :          4 : uint64_t OccupancyGrid::update_time_ns() const noexcept { return update_time_ns_; }
     441                 :            : 
     442                 :          9 : std::string_view OccupancyGrid::map_id() const noexcept { return {map_id_, ::strnlen(map_id_, sizeof(map_id_))}; }
     443                 :            : 
     444                 :          3 : uint32_t OccupancyGrid::channel() const noexcept { return channel_; }
     445                 :            : 
     446                 :          3 : uint32_t OccupancyGrid::freq() const noexcept { return freq_; }
     447                 :            : 
     448                 :         11 : uint32_t OccupancyGrid::width() const noexcept { return width_; }
     449                 :            : 
     450                 :          9 : uint32_t OccupancyGrid::height() const noexcept { return height_; }
     451                 :            : 
     452                 :          3 : uint32_t OccupancyGrid::valid_cell_count() const noexcept { return valid_cell_count_; }
     453                 :            : 
     454                 :          4 : float OccupancyGrid::resolution() const noexcept { return resolution_; }
     455                 :            : 
     456                 :          3 : float OccupancyGrid::origin_x() const noexcept { return origin_x_; }
     457                 :            : 
     458                 :          3 : float OccupancyGrid::origin_y() const noexcept { return origin_y_; }
     459                 :            : 
     460                 :          3 : float OccupancyGrid::origin_z() const noexcept { return origin_z_; }
     461                 :            : 
     462                 :          3 : float OccupancyGrid::origin_yaw() const noexcept { return origin_yaw_; }
     463                 :            : 
     464                 :          3 : float OccupancyGrid::value_min() const noexcept { return value_min_; }
     465                 :            : 
     466                 :          3 : float OccupancyGrid::value_max() const noexcept { return value_max_; }
     467                 :            : 
     468                 :          4 : int32_t OccupancyGrid::default_value() const noexcept { return default_value_; }
     469                 :            : 
     470                 :          4 : float OccupancyGrid::occupied_threshold() const noexcept { return occupied_threshold_; }
     471                 :            : 
     472                 :          4 : float OccupancyGrid::free_threshold() const noexcept { return free_threshold_; }
     473                 :            : 
     474                 :          9 : OccupancyGrid::CellType OccupancyGrid::cell_type() const noexcept { return cell_type_; }
     475                 :            : 
     476                 :          5 : uint8_t OccupancyGrid::cell_size() const noexcept { return cell_size_of(cell_type_); }
     477                 :            : 
     478                 :         39 : const uint8_t* OccupancyGrid::data() const noexcept { return data_; }
     479                 :            : 
     480                 :         28 : size_t OccupancyGrid::size() const noexcept { return size_; }
     481                 :            : 
     482                 :         22 : bool OccupancyGrid::is_owner() const noexcept { return is_owner_; }
     483                 :            : 
     484                 :          3 : void OccupancyGrid::set_update_time_ns(uint64_t update_time_ns) noexcept { update_time_ns_ = update_time_ns; }
     485                 :            : 
     486                 :          8 : void OccupancyGrid::set_map_id(std::string_view map_id) noexcept {
     487                 :          8 :   std::memset(map_id_, 0, sizeof(map_id_));
     488                 :            : 
     489                 :          8 :   size_t copy_size = map_id.size();
     490                 :            : 
     491         [ +  + ]:          8 :   if (copy_size >= sizeof(map_id_)) {
     492                 :          1 :     copy_size = sizeof(map_id_) - 1;
     493                 :            :   }
     494                 :            : 
     495         [ +  + ]:          8 :   if VLIKELY (copy_size != 0) {
     496                 :          7 :     std::memcpy(map_id_, map_id.data(), copy_size);
     497                 :            :   }
     498                 :          8 : }
     499                 :            : 
     500                 :          2 : void OccupancyGrid::set_channel(uint32_t channel) noexcept { channel_ = channel; }
     501                 :            : 
     502                 :          2 : void OccupancyGrid::set_freq(uint32_t freq) noexcept { freq_ = freq; }
     503                 :            : 
     504                 :          8 : void OccupancyGrid::set_width(uint32_t width) noexcept { width_ = width; }
     505                 :            : 
     506                 :          8 : void OccupancyGrid::set_height(uint32_t height) noexcept { height_ = height; }
     507                 :            : 
     508                 :          2 : void OccupancyGrid::set_valid_cell_count(uint32_t valid_cell_count) noexcept { valid_cell_count_ = valid_cell_count; }
     509                 :            : 
     510                 :          3 : void OccupancyGrid::set_resolution(float resolution) noexcept { resolution_ = resolution; }
     511                 :            : 
     512                 :          3 : void OccupancyGrid::set_origin_x(float origin_x) noexcept { origin_x_ = origin_x; }
     513                 :            : 
     514                 :          3 : void OccupancyGrid::set_origin_y(float origin_y) noexcept { origin_y_ = origin_y; }
     515                 :            : 
     516                 :          2 : void OccupancyGrid::set_origin_z(float origin_z) noexcept { origin_z_ = origin_z; }
     517                 :            : 
     518                 :          3 : void OccupancyGrid::set_origin_yaw(float origin_yaw) noexcept { origin_yaw_ = origin_yaw; }
     519                 :            : 
     520                 :          3 : void OccupancyGrid::set_value_min(float value_min) noexcept { value_min_ = value_min; }
     521                 :            : 
     522                 :          3 : void OccupancyGrid::set_value_max(float value_max) noexcept { value_max_ = value_max; }
     523                 :            : 
     524                 :          3 : void OccupancyGrid::set_default_value(int32_t default_value) noexcept { default_value_ = default_value; }
     525                 :            : 
     526                 :          3 : void OccupancyGrid::set_occupied_threshold(float occupied_threshold) noexcept {
     527                 :          3 :   occupied_threshold_ = occupied_threshold;
     528                 :          3 : }
     529                 :            : 
     530                 :          3 : void OccupancyGrid::set_free_threshold(float free_threshold) noexcept { free_threshold_ = free_threshold; }
     531                 :            : 
     532                 :         12 : void OccupancyGrid::set_cell_type(CellType cell_type) noexcept { cell_type_ = cell_type; }
     533                 :            : 
     534                 :         10 : uint8_t OccupancyGrid::cell_size_of(CellType type) noexcept {
     535                 :         10 :   uint8_t target_size = 0;
     536                 :            : 
     537   [ +  +  +  + ]:         10 :   if (type == kCellInt8 || type == kCellUint8) {
     538                 :          3 :     target_size = 1;
     539         [ +  + ]:          7 :   } else if (type == kCellUint16) {
     540                 :          2 :     target_size = 2;
     541         [ +  + ]:          5 :   } else if (type == kCellFloat32) {
     542                 :          2 :     target_size = 4;
     543                 :            :   }
     544                 :            : 
     545                 :         10 :   return target_size;
     546                 :            : }
     547                 :            : 
     548                 :            : }  // namespace zerocopy
     549                 :            : 
     550                 :            : }  // namespace vlink

Generated by: LCOV version 1.14