Line data Source code
1 : //
2 : // Copyright (c) 2025 Mohammad Nejati
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_STATIC_FIELDS_HPP
11 : #define BOOST_HTTP_PROTO_STATIC_FIELDS_HPP
12 :
13 : #include <boost/http_proto/detail/config.hpp>
14 : #include <boost/http_proto/fields_base.hpp>
15 : #include <boost/http_proto/fields_view.hpp>
16 : #include <boost/core/detail/string_view.hpp>
17 :
18 : namespace boost {
19 : namespace http_proto {
20 :
21 : /** A modifiable static container of HTTP fields
22 : */
23 : template<std::size_t Capacity>
24 : class static_fields final
25 : : public fields_base
26 : {
27 : alignas(entry)
28 : char buf_[Capacity];
29 :
30 : public:
31 :
32 : //--------------------------------------------
33 : //
34 : // Special Members
35 : //
36 : //--------------------------------------------
37 :
38 : /** Constructor
39 :
40 : Default-constructed fields have no
41 : name-value pairs.
42 : */
43 11 : static_fields() noexcept
44 : : fields_view_base(
45 11 : &this->fields_base::h_)
46 : , fields_base(
47 : detail::kind::fields,
48 11 : buf_,
49 11 : Capacity)
50 : {
51 11 : }
52 :
53 : /** Constructor
54 : */
55 12 : explicit static_fields(
56 : core::string_view s)
57 : : fields_view_base(
58 12 : &this->fields_base::h_)
59 : , fields_base(
60 : detail::kind::fields,
61 12 : buf_,
62 : Capacity,
63 12 : s)
64 : {
65 12 : }
66 :
67 : /** Constructor
68 : */
69 2 : static_fields(
70 : static_fields const& other) noexcept
71 : : fields_view_base(
72 2 : &this->fields_base::h_)
73 : , fields_base(
74 2 : *other.ph_,
75 2 : buf_,
76 2 : Capacity)
77 : {
78 2 : }
79 :
80 : /** Constructor
81 : */
82 2 : static_fields(
83 : fields_view const& other)
84 : : fields_view_base(
85 2 : &this->fields_base::h_)
86 : , fields_base(
87 2 : *other.ph_,
88 2 : buf_,
89 2 : Capacity)
90 : {
91 2 : }
92 :
93 : /** Assignment
94 : */
95 : static_fields&
96 3 : operator=(static_fields const& f) noexcept
97 : {
98 3 : copy_impl(*f.ph_);
99 3 : return *this;
100 : }
101 :
102 : /** Assignment
103 : */
104 : static_fields&
105 4 : operator=(fields_view const& f)
106 : {
107 4 : copy_impl(*f.ph_);
108 4 : return *this;
109 : }
110 :
111 : /** Conversion
112 : */
113 4 : operator fields_view() const noexcept
114 : {
115 4 : return fields_view(ph_);
116 : }
117 : };
118 :
119 : } // http_proto
120 : } // boost
121 :
122 : #endif
|