LCOV - code coverage report
Current view: top level - boost/http_proto/impl/parser.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 80.0 % 30 24
Test Date: 2025-05-26 06:53:20 Functions: 100.0 % 5 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              : // we need a pragma once for the circular includes required
      11              : // clangd's intellisense
      12              : #pragma once
      13              : 
      14              : #ifndef BOOST_HTTP_PROTO_IMPL_PARSER_HPP
      15              : #define BOOST_HTTP_PROTO_IMPL_PARSER_HPP
      16              : 
      17              : #include <boost/http_proto/parser.hpp>
      18              : #include <boost/http_proto/sink.hpp>
      19              : #include <boost/http_proto/detail/type_traits.hpp>
      20              : 
      21              : namespace boost {
      22              : namespace http_proto {
      23              : 
      24              : //------------------------------------------------
      25              : 
      26              : template<class ElasticBuffer>
      27              : typename std::enable_if<
      28              :     ! detail::is_reference_wrapper<
      29              :         ElasticBuffer>::value &&
      30              :     ! is_sink<ElasticBuffer>::value>::type
      31           11 : parser::
      32              : set_body(
      33              :     ElasticBuffer&& eb)
      34              : {
      35              :     // If this goes off it means you are trying
      36              :     // to pass by lvalue reference. Use std::ref
      37              :     // instead.
      38              :     static_assert(
      39              :         ! std::is_reference<ElasticBuffer>::value,
      40              :         "Use std::ref instead of pass-by-reference");
      41              : 
      42              :     // Check ElasticBuffer type requirements
      43              :     static_assert(
      44              :         buffers::is_dynamic_buffer<ElasticBuffer>::value,
      45              :         "Type requirements not met.");
      46              : 
      47              :     // body must not be set already
      48           11 :     if(how_ != how::in_place)
      49            0 :         detail::throw_logic_error();
      50              : 
      51              :     // headers must be complete
      52           11 :     if(! got_header())
      53            0 :         detail::throw_logic_error();
      54              : 
      55              :     auto& dyn = ws_.emplace<
      56              :         buffers::any_dynamic_buffer_impl<typename
      57              :             std::decay<ElasticBuffer>::type,
      58           11 :                 buffers_N>>(std::forward<ElasticBuffer>(eb));
      59           11 :     eb_ = &dyn;
      60           11 :     how_ = how::elastic;
      61           11 :     on_set_body();
      62           11 : }
      63              : 
      64              : template<class ElasticBuffer>
      65              : void
      66          372 : parser::
      67              : set_body(
      68              :     std::reference_wrapper<ElasticBuffer> eb)
      69              : {
      70              :     // Check ElasticBuffer type requirements
      71              :     static_assert(
      72              :         buffers::is_dynamic_buffer<ElasticBuffer>::value,
      73              :         "Type requirements not met.");
      74              : 
      75              :     // body must not be set already
      76          372 :     if(how_ != how::in_place)
      77            0 :         detail::throw_logic_error();
      78              : 
      79              :     // headers must be complete
      80          372 :     if(! got_header())
      81            0 :         detail::throw_logic_error();
      82              : 
      83              :     auto& dyn = ws_.emplace<
      84              :         buffers::any_dynamic_buffer_impl<typename
      85              :             std::decay<ElasticBuffer>::type&,
      86          372 :                 buffers_N>>(eb);
      87          372 :     eb_ = &dyn;
      88          372 :     how_ = how::elastic;
      89          372 :     on_set_body();
      90          372 : }
      91              : 
      92              : //------------------------------------------------
      93              : 
      94              : template<
      95              :     class Sink,
      96              :     class... Args,
      97              :     class>
      98              : Sink&
      99          372 : parser::
     100              : set_body(Args&&... args)
     101              : {
     102              :     // body must not be set already
     103          372 :     if(how_ != how::in_place)
     104            0 :         detail::throw_logic_error();
     105              : 
     106              :     // headers must be complete
     107          372 :     if(! got_header())
     108            0 :         detail::throw_logic_error();
     109              : 
     110          372 :     auto& s = ws_.emplace<Sink>(
     111              :         std::forward<Args>(args)...);
     112          372 :     sink_ = &s;
     113          372 :     how_ = how::sink;
     114          372 :     on_set_body();
     115          372 :     return s;
     116              : }
     117              : 
     118              : } // http_proto
     119              : } // boost
     120              : 
     121              : #endif
        

Generated by: LCOV version 2.1