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_.emplace< 56 : buffers::any_dynamic_buffer_impl<typename 57 : std::decay<ElasticBuffer>::type, 58 : 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 288 : 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 288 : if(how_ != how::in_place) 77 0 : detail::throw_logic_error(); 78 : 79 : // headers must be complete 80 288 : if(! got_header()) 81 0 : detail::throw_logic_error(); 82 : 83 288 : auto& dyn = ws_.emplace< 84 : buffers::any_dynamic_buffer_impl<typename 85 : std::decay<ElasticBuffer>::type&, 86 : buffers_N>>(eb); 87 288 : eb_ = &dyn; 88 288 : how_ = how::elastic; 89 288 : on_set_body(); 90 288 : } 91 : 92 : //------------------------------------------------ 93 : 94 : template<class Sink> 95 : typename std::enable_if< 96 : is_sink<Sink>::value, 97 : typename std::decay<Sink>::type 98 : >::type& 99 : parser:: 100 : set_body( 101 : Sink&& sink) 102 : { 103 : // body must not be set already 104 : if(how_ != how::in_place) 105 : detail::throw_logic_error(); 106 : 107 : // headers must be complete 108 : if(! got_header()) 109 : detail::throw_logic_error(); 110 : 111 : auto& s = ws_.emplace<Sink>( 112 : std::forward<Sink>(sink)); 113 : sink_ = &s; 114 : how_ = how::sink; 115 : on_set_body(); 116 : return s; 117 : } 118 : 119 : } // http_proto 120 : } // boost 121 : 122 : #endif