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

Generated by: LCOV version 1.15