LCOV - code coverage report
Current view: top level - boost/buffers/const_buffer_span.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 16 16
Test Date: 2024-07-24 21:34:17 Functions: 100.0 % 6 6

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2023 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/buffers
       8              : //
       9              : 
      10              : #ifndef BOOST_BUFFERS_CONST_BUFFER_SPAN_HPP
      11              : #define BOOST_BUFFERS_CONST_BUFFER_SPAN_HPP
      12              : 
      13              : #include <boost/buffers/detail/config.hpp>
      14              : #include <boost/buffers/const_buffer.hpp>
      15              : #include <boost/buffers/const_buffer_subspan.hpp>
      16              : #include <boost/buffers/type_traits.hpp>
      17              : 
      18              : namespace boost {
      19              : namespace buffers {
      20              : 
      21              : /** Holds a span of buffers that cannot be modified.
      22              : 
      23              :     Objects of this type meet the requirements
      24              :     of <em>ConstBufferSequence</em>.
      25              : */
      26              : class const_buffer_span
      27              : {
      28              :     const_buffer const* p_ = nullptr;
      29              :     std::size_t n_ = 0;
      30              : 
      31              :     friend class const_buffer_subspan;
      32              : 
      33              : public:
      34              :     /** The type of buffer.
      35              :     */
      36              :     using value_type = const_buffer;
      37              : 
      38              :     /** The type of iterators returned.
      39              :     */
      40              :     using const_iterator = value_type const*;
      41              : 
      42              :     /** Constructor.
      43              :     */
      44              :     const_buffer_span() = default;
      45              : 
      46              :     /** Constructor.
      47              :     */
      48        16673 :     const_buffer_span(
      49              :         const_buffer const* p,
      50              :         std::size_t n) noexcept
      51        16673 :         : p_(p)
      52        16673 :         , n_(n)
      53              :     {
      54        16673 :     }
      55              : 
      56              :     /** Constructor.
      57              :     */
      58              :     template<
      59              :         class ConstBufferSequence
      60              :         , class = typename std::enable_if<
      61              :             ! std::is_same<
      62              :                 ConstBufferSequence,
      63              :                 const_buffer_span>::value &&
      64              :             is_const_buffer_sequence<
      65              :                 ConstBufferSequence>::value &&
      66              :             std::is_same<decltype(
      67              :                 std::declval<ConstBufferSequence
      68              :                     const&>().begin()),
      69              :                 const_buffer const*>::value
      70              :             >::type
      71              :     >
      72              :     explicit
      73            1 :     const_buffer_span(
      74              :         ConstBufferSequence const& bs) noexcept
      75            1 :         : p_(bs.begin())
      76            1 :         , n_(bs.end() - bs.begin())
      77              :     {
      78            1 :     }
      79              : 
      80              :     /** Constructor.
      81              :     */
      82              :     const_buffer_span(
      83              :         const_buffer_span const&) = default;
      84              : 
      85              :     /** Assignment.
      86              :     */
      87              :     const_buffer_span& operator=(
      88              :         const_buffer_span const&) = default;
      89              : 
      90              :     /** Return an iterator to the beginning.
      91              :     */
      92              :     const_iterator
      93        54087 :     begin() const noexcept
      94              :     {
      95        54087 :         return p_;
      96              :     }
      97              : 
      98              :     /** Return an iterator to the end.
      99              :     */
     100              :     const_iterator
     101        54087 :     end() const noexcept
     102              :     {
     103        54087 :         return p_ + n_;
     104              :     }
     105              : 
     106              :     friend
     107              :     const_buffer_subspan
     108       139638 :     tag_invoke(
     109              :         prefix_tag const&,
     110              :         const_buffer_span const& s,
     111              :         std::size_t n) noexcept
     112              :     {
     113       139638 :         return s.prefix_impl(n);
     114              :     }
     115              : 
     116              :     friend
     117              :     const_buffer_subspan
     118       139638 :     tag_invoke(
     119              :         suffix_tag const&,
     120              :         const_buffer_span const& s,
     121              :         std::size_t n) noexcept
     122              :     {
     123       139638 :         return s.suffix_impl(n);
     124              :     }
     125              : 
     126              : private:
     127              :     inline
     128              :     const_buffer_subspan
     129              :     prefix_impl(std::size_t n) const noexcept;
     130              : 
     131              :     inline
     132              :     const_buffer_subspan
     133              :     suffix_impl(std::size_t n) const noexcept;
     134              : };
     135              : 
     136              : //-----------------------------------------------
     137              : 
     138              : } // buffers
     139              : } // boost
     140              : 
     141              : #include <boost/buffers/impl/const_buffer_span.hpp>
     142              : 
     143              : #endif
        

Generated by: LCOV version 2.1