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-03-18 23:12:48 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             : // 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          11 :     auto& dyn = ws_.push(
      56             :         buffers::any_dynamic_buffer_impl<typename
      57             :             std::decay<ElasticBuffer>::type,
      58             :                 buffers_N>(std::forward<
      59             :                     ElasticBuffer>(eb)));
      60          11 :     eb_ = &dyn;
      61          11 :     how_ = how::elastic;
      62          11 :     on_set_body();
      63          11 : }
      64             : 
      65             : template<class ElasticBuffer>
      66             : void
      67         288 : parser::
      68             : set_body(
      69             :     std::reference_wrapper<ElasticBuffer> eb)
      70             : {
      71             :     // Check ElasticBuffer type requirements
      72             :     static_assert(
      73             :         buffers::is_dynamic_buffer<ElasticBuffer>::value,
      74             :         "Type requirements not met.");
      75             : 
      76             :     // body must not be set already
      77         288 :     if(how_ != how::in_place)
      78           0 :         detail::throw_logic_error();
      79             : 
      80             :     // headers must be complete
      81         288 :     if(! got_header())
      82           0 :         detail::throw_logic_error();
      83             : 
      84         288 :     auto& dyn = ws_.push(
      85             :         buffers::any_dynamic_buffer_impl<typename
      86             :             std::decay<ElasticBuffer>::type&,
      87             :                 buffers_N>(eb));
      88         288 :     eb_ = &dyn;
      89         288 :     how_ = how::elastic;
      90         288 :     on_set_body();
      91         288 : }
      92             : 
      93             : //------------------------------------------------
      94             : 
      95             : template<class Sink>
      96             : typename std::enable_if<
      97             :     is_sink<Sink>::value,
      98             :     typename std::decay<Sink>::type
      99             :         >::type&
     100             : parser::
     101             : set_body(
     102             :     Sink&& sink)
     103             : {
     104             :     // body must not be set already
     105             :     if(how_ != how::in_place)
     106             :         detail::throw_logic_error();
     107             : 
     108             :     // headers must be complete
     109             :     if(! got_header())
     110             :         detail::throw_logic_error();
     111             : 
     112             :     auto& s = ws_.push(
     113             :         std::forward<Sink>(sink));
     114             :     sink_ = &s;
     115             :     how_ = how::sink;
     116             :     on_set_body();
     117             :     return s;
     118             : }
     119             : 
     120             : } // http_proto
     121             : } // boost
     122             : 
     123             : #endif

Generated by: LCOV version 1.15