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

Generated by: LCOV version 1.15