]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/beast/core/detail/char_buffer.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / beast / core / detail / char_buffer.hpp
CommitLineData
92f5a8d4
TL
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_CORE_DETAIL_CHAR_BUFFER_HPP
11#define BOOST_BEAST_CORE_DETAIL_CHAR_BUFFER_HPP
12
13#include <boost/config.hpp>
14#include <cstddef>
15#include <cstring>
16#include <cstdint>
17
18namespace boost {
19namespace beast {
20namespace detail {
21
22template <std::size_t N>
23class char_buffer
24{
25public:
26 bool try_push_back(char c)
27 {
28 if (size_ == N)
29 return false;
30 buf_[size_++] = c;
31 return true;
32 }
33
34 bool try_append(char const* first, char const* last)
35 {
36 std::size_t const n = last - first;
37 if (n > N - size_)
38 return false;
39 std::memmove(&buf_[size_], first, n);
40 size_ += n;
41 return true;
42 }
43
44 void clear() noexcept
45 {
46 size_ = 0;
47 }
48
49 char* data() noexcept
50 {
51 return buf_;
52 }
53
54 char const* data() const noexcept
55 {
56 return buf_;
57 }
58
59 std::size_t size() const noexcept
60 {
61 return size_;
62 }
63
64 bool empty() const noexcept
65 {
66 return size_ == 0;
67 }
68
69private:
70 std::size_t size_= 0;
71 char buf_[N];
72};
73
74} // detail
75} // beast
76} // boost
77
78#endif