File indexing completed on 2025-01-18 09:38:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_JSON_DEFAULT_RESOURCE_HPP
0011 #define BOOST_JSON_DEFAULT_RESOURCE_HPP
0012
0013 #include <boost/json/detail/config.hpp>
0014 #include <new>
0015
0016 namespace boost {
0017 namespace json {
0018 namespace detail {
0019
0020 #ifdef _MSC_VER
0021 #pragma warning(push)
0022 #pragma warning(disable: 4251)
0023 #pragma warning(disable: 4275)
0024 #endif
0025
0026
0027 class
0028 BOOST_SYMBOL_VISIBLE
0029 BOOST_JSON_DECL
0030 default_resource final
0031 : public memory_resource
0032 {
0033 union holder;
0034
0035 #ifndef BOOST_JSON_WEAK_CONSTINIT
0036 # ifndef BOOST_JSON_NO_DESTROY
0037 static holder instance_;
0038 # else
0039 BOOST_JSON_NO_DESTROY
0040 static default_resource instance_;
0041 # endif
0042 #endif
0043
0044 public:
0045 static
0046 memory_resource*
0047 get() noexcept
0048 {
0049 #ifdef BOOST_JSON_WEAK_CONSTINIT
0050 static default_resource instance_;
0051 #endif
0052 return reinterpret_cast<memory_resource*>(
0053 reinterpret_cast<std::uintptr_t*>(
0054 &instance_));
0055 }
0056
0057 ~default_resource();
0058
0059 void*
0060 do_allocate(
0061 std::size_t n,
0062 std::size_t) override;
0063
0064 void
0065 do_deallocate(
0066 void* p,
0067 std::size_t,
0068 std::size_t) override;
0069
0070 bool
0071 do_is_equal(
0072 memory_resource const& mr) const noexcept override;
0073 };
0074
0075 #ifdef _MSC_VER
0076 #pragma warning(pop)
0077 #endif
0078
0079 union default_resource::
0080 holder
0081 {
0082 #ifndef BOOST_JSON_WEAK_CONSTINIT
0083 constexpr
0084 #endif
0085 holder()
0086 : mr()
0087 {
0088 }
0089
0090 ~holder()
0091 {
0092 }
0093
0094 default_resource mr;
0095 };
0096
0097 }
0098 }
0099 }
0100
0101 #endif