1 // 2 // Copyright (c) 2019 Damian Jarek(damian.jarek93@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/boostorg/beast 8 // 9 10 #ifndef BOOST_BEAST_DETAIL_TEMPORARY_BUFFER_HPP 11 #define BOOST_BEAST_DETAIL_TEMPORARY_BUFFER_HPP 12 13 #include <boost/beast/core/detail/config.hpp> 14 #include <boost/beast/core/string.hpp> 15 16 #include <memory> 17 18 namespace boost { 19 namespace beast { 20 namespace detail { 21 22 struct temporary_buffer 23 { 24 temporary_buffer() = default; 25 temporary_buffer(temporary_buffer const&) = delete; 26 temporary_buffer& operator=(temporary_buffer const&) = delete; 27 ~temporary_bufferboost::beast::detail::temporary_buffer28 ~temporary_buffer() noexcept 29 { 30 deallocate(data_); 31 } 32 33 BOOST_BEAST_DECL 34 void 35 append(string_view s); 36 37 BOOST_BEAST_DECL 38 void 39 append(string_view s1, string_view s2); 40 41 string_view viewboost::beast::detail::temporary_buffer42 view() const noexcept 43 { 44 return {data_, size_}; 45 } 46 47 bool emptyboost::beast::detail::temporary_buffer48 empty() const noexcept 49 { 50 return size_ == 0; 51 } 52 53 private: 54 BOOST_BEAST_DECL 55 void 56 unchecked_append(string_view s); 57 58 BOOST_BEAST_DECL 59 void 60 grow(std::size_t n); 61 62 void deallocateboost::beast::detail::temporary_buffer63 deallocate(char* data) noexcept 64 { 65 if (data != buffer_) 66 delete[] data; 67 } 68 69 char buffer_[4096]; 70 char* data_ = buffer_; 71 std::size_t capacity_ = sizeof(buffer_); 72 std::size_t size_ = 0; 73 }; 74 75 } // detail 76 } // beast 77 } // boost 78 79 #ifdef BOOST_BEAST_HEADER_ONLY 80 #include <boost/beast/core/detail/impl/temporary_buffer.ipp> 81 #endif 82 83 #endif 84