LCOV - code coverage report
Current view: top level - wirestead/wrapper - fanout_result.hpp (source / functions) Coverage Total Hit
Test: Wirestead Coverage Report Lines: 100.0 % 13 13
Test Date: 2026-10-29 11:36:05 Functions: 100.0 % 7 7
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 100.0 % 2 2

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright 2025 Jinwoo Sung
       3                 :             :  *
       4                 :             :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :             :  * you may not use this file except in compliance with the License.
       6                 :             :  * You may obtain a copy of the License at
       7                 :             :  *
       8                 :             :  *     http://www.apache.org/licenses/LICENSE-2.0
       9                 :             :  *
      10                 :             :  * Unless required by applicable law or agreed to in writing, software
      11                 :             :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :             :  * See the License for the specific language governing permissions and
      14                 :             :  * limitations under the License.
      15                 :             :  */
      16                 :             : 
      17                 :             : #pragma once
      18                 :             : 
      19                 :             : #include <array>
      20                 :             : #include <cstddef>
      21                 :             : 
      22                 :             : #include "wirestead/wrapper/send_result.hpp"
      23                 :             : 
      24                 :             : namespace wirestead::wrapper {
      25                 :             : 
      26                 :             : // Local admission over one fixed target set, never delivery confirmation.
      27                 :             : // An empty result means no targets; it is neither acceptance nor rejection.
      28                 :             : class [[nodiscard]] FanoutResult {
      29                 :             :  public:
      30                 :         149 :   constexpr std::size_t target_count() const noexcept { return accepted_ + rejected_; }
      31                 :          74 :   constexpr std::size_t accepted_count() const noexcept { return accepted_; }
      32                 :          29 :   constexpr std::size_t rejected_count() const noexcept { return rejected_; }
      33                 :         134 :   constexpr std::size_t rejected_count(SendRejection reason) const noexcept {
      34                 :         134 :     return reasons_[static_cast<std::size_t>(reason)];
      35                 :             :   }
      36                 :          59 :   constexpr bool empty() const noexcept { return target_count() == 0; }
      37                 :        1273 :   constexpr explicit operator bool() const noexcept { return accepted_ != 0; }
      38                 :             : 
      39                 :             :   // Add exactly one admission decision for each selected target.
      40                 :        1787 :   constexpr void add(SendResult result) noexcept {
      41         [ +  + ]:        1787 :     if (result.accepted()) {
      42                 :        1339 :       ++accepted_;
      43                 :             :     } else {
      44                 :         448 :       ++rejected_;
      45                 :         448 :       ++reasons_[static_cast<std::size_t>(result.reason())];
      46                 :             :     }
      47                 :        1787 :   }
      48                 :             : 
      49                 :             :  private:
      50                 :             :   std::size_t accepted_ = 0;
      51                 :             :   std::size_t rejected_ = 0;
      52                 :             :   std::array<std::size_t, static_cast<std::size_t>(SendRejection::CancelledWhileWaiting) + 1> reasons_{};
      53                 :             : };
      54                 :             : 
      55                 :             : }  // namespace wirestead::wrapper
        

Generated by: LCOV version 2.0-1