File indexing completed on 2025-07-05 08:36:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_JSON_STATIC_RESOURCE_HPP
0011 #define BOOST_JSON_STATIC_RESOURCE_HPP
0012
0013 #include <boost/container/pmr/memory_resource.hpp>
0014 #include <boost/json/detail/config.hpp>
0015 #include <boost/json/is_deallocate_trivial.hpp>
0016 #include <boost/json/memory_resource.hpp>
0017 #include <cstddef>
0018
0019 namespace boost {
0020 namespace json {
0021
0022 #ifdef _MSC_VER
0023 #pragma warning(push)
0024 #pragma warning(disable: 4275)
0025 #endif
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 class
0069 BOOST_JSON_DECL
0070 BOOST_SYMBOL_VISIBLE
0071 static_resource final
0072 : public container::pmr::memory_resource
0073 {
0074 void* p_;
0075 std::size_t n_;
0076 std::size_t size_;
0077
0078 public:
0079
0080 static_resource(
0081 static_resource const&) = delete;
0082
0083
0084 static_resource& operator=(
0085 static_resource const&) = delete;
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 static_resource(
0110 unsigned char* buffer,
0111 std::size_t size) noexcept;
0112
0113 #if defined(__cpp_lib_byte) || defined(BOOST_JSON_DOCS)
0114 static_resource(
0115 std::byte* buffer,
0116 std::size_t size) noexcept
0117 : static_resource(reinterpret_cast<
0118 unsigned char*>(buffer), size)
0119 {
0120 }
0121 #endif
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143 template<std::size_t N>
0144 explicit
0145 static_resource(
0146 unsigned char(&buffer)[N]) noexcept
0147 : static_resource(&buffer[0], N)
0148 {
0149 }
0150
0151 #if defined(__cpp_lib_byte) || defined(BOOST_JSON_DOCS)
0152 template<std::size_t N>
0153 explicit
0154 static_resource(
0155 std::byte(&buffer)[N]) noexcept
0156 : static_resource(&buffer[0], N)
0157 {
0158 }
0159 #endif
0160
0161
0162 #ifndef BOOST_JSON_DOCS
0163
0164 template<std::size_t N>
0165 static_resource(
0166 unsigned char(&buffer)[N], std::size_t n) noexcept
0167 : static_resource(&buffer[0], n)
0168 {
0169
0170
0171
0172 BOOST_ASSERT(n <= N);
0173 }
0174
0175 #ifdef __cpp_lib_byte
0176
0177 template<std::size_t N>
0178 static_resource(
0179 std::byte(&buffer)[N], std::size_t n) noexcept
0180 : static_resource(&buffer[0], n)
0181 {
0182
0183
0184
0185 BOOST_ASSERT(n <= N);
0186 }
0187 #endif
0188 #endif
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202 void
0203 release() noexcept;
0204
0205 protected:
0206 #ifndef BOOST_JSON_DOCS
0207 void*
0208 do_allocate(
0209 std::size_t n,
0210 std::size_t align) override;
0211
0212 void
0213 do_deallocate(
0214 void* p,
0215 std::size_t n,
0216 std::size_t align) override;
0217
0218 bool
0219 do_is_equal(
0220 memory_resource const& mr
0221 ) const noexcept override;
0222 #endif
0223 };
0224
0225 #ifdef _MSC_VER
0226 #pragma warning(pop)
0227 #endif
0228
0229 template<>
0230 struct is_deallocate_trivial<
0231 static_resource>
0232 {
0233 static constexpr bool value = true;
0234 };
0235
0236 }
0237 }
0238
0239 #endif