LCOV - code coverage report
Current view: top level - core - value_descriptions.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 8 8
Test Date: 2026-10-20 13:34:58 Functions: 100.0 % 2 2
Branches: 87.5 % 8 7

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: MIT
       2                 :             : #ifndef VALUE_DESCRIPTIONS_H
       3                 :             : #define VALUE_DESCRIPTIONS_H
       4                 :             : 
       5                 :             : #include <cstdint>
       6                 :             : #include <map>
       7                 :             : #include <string>
       8                 :             : #include <variant>
       9                 :             : 
      10                 :             : using RawSignalValue = std::variant<std::int64_t, std::uint64_t>;
      11                 :             : 
      12                 :             : /** Canonical keys: negative int64_t, nonnegative uint64_t. */
      13                 :          87 : inline RawSignalValue NormalizeValueKey(const RawSignalValue &value) {
      14         [ +  + ]:          87 :     if (const std::int64_t *number = std::get_if<std::int64_t>(&value)) {
      15         [ +  + ]:          31 :         if (*number >= 0)
      16                 :          11 :             return static_cast<std::uint64_t>(*number);
      17                 :             :     }
      18                 :          76 :     return value;
      19                 :             : }
      20                 :             : 
      21                 :             : using ValueDescriptions = std::map<RawSignalValue, std::string>;
      22                 :             : 
      23                 :             : /** Returns a borrowed string, or nullptr; never converts integers to double. */
      24                 :          71 : inline const std::string *FindValueDescription(const ValueDescriptions &descriptions,
      25                 :             :                                                const RawSignalValue &rawValue) {
      26         [ +  - ]:          71 :     const ValueDescriptions::const_iterator found = descriptions.find(NormalizeValueKey(rawValue));
      27         [ +  + ]:          71 :     return found == descriptions.end() ? nullptr : &found->second;
      28                 :             : }
      29                 :             : 
      30                 :             : #endif
        

Generated by: LCOV version 2.0-1