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_DETAIL_IMPL_WORKSPACE_IPP 11 : #define BOOST_HTTP_PROTO_DETAIL_IMPL_WORKSPACE_IPP 12 : 13 : #include <boost/http_proto/detail/workspace.hpp> 14 : #include <boost/http_proto/detail/except.hpp> 15 : 16 : namespace boost { 17 : namespace http_proto { 18 : namespace detail { 19 : 20 : workspace:: 21 : any:: 22 : ~any() = default; 23 : 24 : void 25 36 : workspace:: 26 : clear() noexcept 27 : { 28 36 : auto const end = 29 : reinterpret_cast< 30 : any const*>(end_); 31 36 : auto p = 32 : reinterpret_cast< 33 : any const*>(head_); 34 74 : while(p != end) 35 : { 36 38 : auto next = p->next; 37 38 : p->~any(); 38 38 : p = next; 39 : } 40 36 : head_ = end_; 41 36 : } 42 : 43 : void* 44 0 : workspace:: 45 : reserve(std::size_t n) 46 : { 47 : // Requested n exceeds available space 48 0 : if(n > size()) 49 0 : detail::throw_length_error(); 50 : 51 : struct empty : any 52 : { 53 : }; 54 : 55 : using U = empty; 56 0 : auto p = ::new(bump_down( 57 : sizeof(U) + n, alignof( 58 0 : ::max_align_t))) U; 59 0 : p->next = reinterpret_cast< 60 0 : any*>(head_); 61 0 : head_ = reinterpret_cast< 62 : unsigned char*>(p); 63 0 : return p + 1; 64 : } 65 : 66 : } // detail 67 : } // http_proto 68 : } // boost 69 : 70 : #endif