File indexing completed on 2025-01-18 09:29:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_CORE_DETAIL_CHAR_BUFFER_HPP
0011 #define BOOST_BEAST_CORE_DETAIL_CHAR_BUFFER_HPP
0012
0013 #include <boost/config.hpp>
0014 #include <cstddef>
0015 #include <cstring>
0016 #include <cstdint>
0017
0018 namespace boost {
0019 namespace beast {
0020 namespace detail {
0021
0022 template <std::size_t N>
0023 class char_buffer
0024 {
0025 public:
0026 bool try_push_back(char c)
0027 {
0028 if (size_ == N)
0029 return false;
0030 buf_[size_++] = c;
0031 return true;
0032 }
0033
0034 bool try_append(char const* first, char const* last)
0035 {
0036 std::size_t const n = last - first;
0037 if (n > N - size_)
0038 return false;
0039 std::memmove(&buf_[size_], first, n);
0040 size_ += n;
0041 return true;
0042 }
0043
0044 void clear() noexcept
0045 {
0046 size_ = 0;
0047 }
0048
0049 char* data() noexcept
0050 {
0051 return buf_;
0052 }
0053
0054 char const* data() const noexcept
0055 {
0056 return buf_;
0057 }
0058
0059 std::size_t size() const noexcept
0060 {
0061 return size_;
0062 }
0063
0064 bool empty() const noexcept
0065 {
0066 return size_ == 0;
0067 }
0068
0069 private:
0070 std::size_t size_= 0;
0071 char buf_[N];
0072 };
0073
0074 }
0075 }
0076 }
0077
0078 #endif