LCOV - code coverage report
Current view: top level - boost/http_proto/detail/impl - array_of_buffers.hpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 25 28 89.3 %
Date: 2024-03-22 16:56:24 Functions: 8 8 100.0 %

          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          26 : array_of_buffers<isConst>::
      22             : array_of_buffers(
      23             :     value_type* p,
      24             :     std::size_t n) noexcept
      25             :     : p_(p)
      26          26 :     , n_(n)
      27             : {
      28          26 : }
      29             : 
      30             : template<bool isConst>
      31             : bool
      32           6 : array_of_buffers<isConst>::
      33             : empty() const noexcept
      34             : {
      35           6 :     return n_ == 0;
      36             : }
      37             : 
      38             : template<bool isConst>
      39             : auto
      40          96 : array_of_buffers<isConst>::
      41             : data() const noexcept ->
      42             :     value_type*
      43             : {
      44          96 :     return p_;
      45             : }
      46             : 
      47             : template<bool isConst>
      48             : std::size_t
      49          43 : array_of_buffers<isConst>::
      50             : size() const noexcept
      51             : {
      52          43 :     return n_;
      53             : }
      54             : 
      55             : template<bool isConst>
      56             : auto
      57           1 : array_of_buffers<isConst>::
      58             : begin() const noexcept ->
      59             :     iterator
      60             : {
      61           1 :     return p_;
      62             : }
      63             : 
      64             : template<bool isConst>
      65             : auto
      66           1 : array_of_buffers<isConst>::
      67             : end() const noexcept ->
      68             :     iterator
      69             : {
      70           1 :     return p_ + n_;
      71             : }
      72             : 
      73             : template<bool isConst>
      74             : auto
      75          73 : array_of_buffers<isConst>::
      76             : operator[](
      77             :     std::size_t i) const noexcept ->
      78             :         value_type& 
      79             : {
      80          73 :     BOOST_ASSERT(i < n_);
      81          73 :     return p_[i];
      82             : }
      83             : 
      84             : template<bool isConst>
      85             : void
      86          20 : array_of_buffers<isConst>::
      87             : consume(std::size_t n)
      88             : {
      89          20 :     while(n_ > 0)
      90             :     {
      91          18 :         if(n < p_->size())
      92             :         {
      93           0 :             *p_ += n;
      94           0 :             return;
      95             :         }
      96          18 :         n -= p_->size();
      97          18 :         ++p_;
      98          18 :         --n_;
      99          18 :         if(n == 0)
     100          16 :             return;
     101             :     }
     102             : 
     103             :     // n exceeded available size
     104           2 :     if(n > 0)
     105           0 :         detail::throw_logic_error();
     106             : }
     107             : 
     108             : } // detail
     109             : } // http_proto
     110             : } // boost
     111             : 
     112             : #endif

Generated by: LCOV version 1.15