123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- #ifndef BOOST_JSON_STATIC_RESOURCE_HPP
- #define BOOST_JSON_STATIC_RESOURCE_HPP
- #include <boost/container/pmr/memory_resource.hpp>
- #include <boost/json/detail/config.hpp>
- #include <boost/json/is_deallocate_trivial.hpp>
- #include <boost/json/memory_resource.hpp>
- #include <cstddef>
- namespace boost {
- namespace json {
- #ifdef _MSC_VER
- #pragma warning(push)
- #pragma warning(disable: 4275)
- #endif
- class
- BOOST_JSON_DECL
- BOOST_SYMBOL_VISIBLE
- static_resource final
- : public container::pmr::memory_resource
- {
- void* p_;
- std::size_t n_;
- std::size_t size_;
- public:
-
- static_resource(
- static_resource const&) = delete;
-
- static_resource& operator=(
- static_resource const&) = delete;
-
-
- static_resource(
- unsigned char* buffer,
- std::size_t size) noexcept;
- #if defined(__cpp_lib_byte) || defined(BOOST_JSON_DOCS)
- static_resource(
- std::byte* buffer,
- std::size_t size) noexcept
- : static_resource(reinterpret_cast<
- unsigned char*>(buffer), size)
- {
- }
- #endif
-
-
-
- template<std::size_t N>
- explicit
- static_resource(
- unsigned char(&buffer)[N]) noexcept
- : static_resource(&buffer[0], N)
- {
- }
- #if defined(__cpp_lib_byte) || defined(BOOST_JSON_DOCS)
- template<std::size_t N>
- explicit
- static_resource(
- std::byte(&buffer)[N]) noexcept
- : static_resource(&buffer[0], N)
- {
- }
- #endif
-
- #ifndef BOOST_JSON_DOCS
-
- template<std::size_t N>
- static_resource(
- unsigned char(&buffer)[N], std::size_t n) noexcept
- : static_resource(&buffer[0], n)
- {
-
-
-
- BOOST_ASSERT(n <= N);
- }
- #ifdef __cpp_lib_byte
-
- template<std::size_t N>
- static_resource(
- std::byte(&buffer)[N], std::size_t n) noexcept
- : static_resource(&buffer[0], n)
- {
-
-
-
- BOOST_ASSERT(n <= N);
- }
- #endif
- #endif
-
- void
- release() noexcept;
- protected:
- #ifndef BOOST_JSON_DOCS
- void*
- do_allocate(
- std::size_t n,
- std::size_t align) override;
- void
- do_deallocate(
- void* p,
- std::size_t n,
- std::size_t align) override;
- bool
- do_is_equal(
- memory_resource const& mr
- ) const noexcept override;
- #endif
- };
- #ifdef _MSC_VER
- #pragma warning(pop)
- #endif
- template<>
- struct is_deallocate_trivial<
- static_resource>
- {
- static constexpr bool value = true;
- };
- }
- }
- #endif
|