LCOV - code coverage report
Current view: top level - boost/http_proto/detail/impl/array_of_buffers.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 97.4 % 38 37
Test Date: 2024-08-30 20:13:35 Functions: 100.0 % 9 9

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
       3              : //
       4              : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       5              : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       6              : //
       7              : // Official repository: https://github.com/cppalliance/http_proto
       8              : //
       9              : 
      10              : #ifndef BOOST_HTTP_PROTO_DETAIL_IMPL_ARRAY_OF_BUFFERS_HPP
      11              : #define BOOST_HTTP_PROTO_DETAIL_IMPL_ARRAY_OF_BUFFERS_HPP
      12              : 
      13              : #include <boost/http_proto/detail/except.hpp>
      14              : #include <boost/assert.hpp>
      15              : 
      16              : namespace boost {
      17              : namespace http_proto {
      18              : namespace detail {
      19              : 
      20              : template<bool isConst>
      21           96 : array_of_buffers<isConst>::
      22              : array_of_buffers(
      23              :     value_type* p,
      24              :     std::size_t n) noexcept
      25           96 :     : o_(p)
      26           96 :     , p_(p)
      27           96 :     , n_(n)
      28           96 :     , c_(n)
      29              : {
      30           96 : }
      31              : 
      32              : template<bool isConst>
      33              : bool
      34              : array_of_buffers<isConst>::
      35              : empty() const noexcept
      36              : {
      37              :     return n_ == 0;
      38              : }
      39              : 
      40              : template<bool isConst>
      41              : auto
      42        15828 : array_of_buffers<isConst>::
      43              : data() const noexcept ->
      44              :     value_type*
      45              : {
      46        15828 :     return p_;
      47              : }
      48              : 
      49              : template<bool isConst>
      50              : std::size_t
      51        12582 : array_of_buffers<isConst>::
      52              : size() const noexcept
      53              : {
      54        12582 :     return n_;
      55              : }
      56              : 
      57              : template<bool isConst>
      58              : std::size_t
      59        25004 : array_of_buffers<isConst>::
      60              : capacity() const noexcept
      61              : {
      62        25004 :     return c_;
      63              : }
      64              : 
      65              : template<bool isConst>
      66              : auto
      67        31937 : array_of_buffers<isConst>::
      68              : begin() const noexcept ->
      69              :     iterator
      70              : {
      71        31937 :     return p_;
      72              : }
      73              : 
      74              : template<bool isConst>
      75              : auto
      76        31937 : array_of_buffers<isConst>::
      77              : end() const noexcept ->
      78              :     iterator
      79              : {
      80        31937 :     return p_ + n_;
      81              : }
      82              : 
      83              : template<bool isConst>
      84              : auto
      85        37934 : array_of_buffers<isConst>::
      86              : operator[](
      87              :     std::size_t i) const noexcept ->
      88              :         value_type&
      89              : {
      90        37934 :     BOOST_ASSERT(i < n_);
      91        37934 :     return p_[i];
      92              : }
      93              : 
      94              : template<bool isConst>
      95              : void
      96        16148 : array_of_buffers<isConst>::
      97              : consume(std::size_t n)
      98              : {
      99        35019 :     while(n_ > 0)
     100              :     {
     101        34968 :         if(n < p_->size())
     102              :         {
     103         3040 :             *p_ += n;
     104         3040 :             return;
     105              :         }
     106        31928 :         n -= p_->size();
     107        31928 :         ++p_;
     108        31928 :         --n_;
     109        31928 :         if(n == 0)
     110        13057 :             return;
     111              :     }
     112              : 
     113              :     // n exceeded available size
     114           51 :     if(n > 0)
     115            0 :         detail::throw_logic_error();
     116              : }
     117              : 
     118              : template<bool isConst>
     119              : void
     120        12502 : array_of_buffers<isConst>::
     121              : reset(std::size_t n)
     122              : {
     123        12502 :     BOOST_ASSERT(n <= capacity());
     124        12502 :     p_ = o_;
     125        12502 :     n_ = n;
     126        68815 :     for( auto p = p_; p < p_ + n; ++p )
     127        56313 :         *p = value_type();
     128        12502 : }
     129              : 
     130              : } // detail
     131              : } // http_proto
     132              : } // boost
     133              : 
     134              : #endif
        

Generated by: LCOV version 2.1