LCOV - code coverage report
Current view: top level - libs/http_proto/src/buffered_base.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 26 26
Test Date: 2024-09-13 19:44:06 Functions: 83.3 % 6 5

            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              : #include <boost/http_proto/buffered_base.hpp>
      11              : #include <boost/http_proto/detail/except.hpp>
      12              : 
      13              : namespace boost {
      14              : namespace http_proto {
      15              : 
      16           27 : buffered_base::
      17              : ~buffered_base() = default;
      18              : 
      19              : void
      20            2 : buffered_base::
      21              : on_init(allocator&)
      22              : {
      23            2 : }
      24              : 
      25              : void
      26            8 : buffered_base::
      27              : init(
      28              :     allocator& a,
      29              :     std::size_t max_size)
      30              : {
      31              :     // max_size exceeds limit
      32            8 :     if(max_size > a.max_size())
      33            1 :         detail::throw_invalid_argument();
      34              : 
      35              :     struct restorer
      36              :     {
      37              :         allocator& a;
      38              :         std::size_t n;
      39              : 
      40            7 :         ~restorer()
      41              :         {
      42            7 :             a.restore(n);
      43            7 :         }
      44              :     };
      45              : 
      46              :     auto const n =
      47            7 :         a.max_size() - max_size;
      48            7 :     a.remove(n);
      49            7 :     restorer r{a, n};
      50            7 :     init(a);
      51            7 : }
      52              : 
      53              : //------------------------------------------------
      54              : 
      55              : void*
      56           10 : buffered_base::
      57              : allocator::
      58              : allocate(
      59              :     std::size_t n)
      60              : {
      61              :     // n exceeds available space
      62           10 :     if(n > size_)
      63            3 :         detail::throw_invalid_argument();
      64              : 
      65            7 :     size_used_ += n;
      66            7 :     if(down_)
      67              :     {
      68            3 :         auto p = base_ + size_ - n;
      69            3 :         size_ -= n;
      70            3 :         return p;
      71              :     }
      72            4 :     auto p = base_;
      73            4 :     base_ += n;
      74            4 :     size_ -= n;
      75            4 :     return p;
      76              : }
      77              : 
      78              : } // http_proto
      79              : } // boost
        

Generated by: LCOV version 2.1