File indexing completed on 2025-01-18 09:38:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_JSON_DETAIL_IMPL_STACK_IPP
0011 #define BOOST_JSON_DETAIL_IMPL_STACK_IPP
0012
0013 #include <boost/json/detail/stack.hpp>
0014
0015 namespace boost {
0016 namespace json {
0017 namespace detail {
0018
0019 stack::
0020 ~stack()
0021 {
0022 if(base_ != buf_)
0023 sp_->deallocate(
0024 base_, cap_);
0025 }
0026
0027 stack::
0028 stack(
0029 storage_ptr sp,
0030 unsigned char* buf,
0031 std::size_t buf_size) noexcept
0032 : sp_(std::move(sp))
0033 , cap_(buf_size)
0034 , base_(buf)
0035 , buf_(buf)
0036 {
0037 }
0038
0039 void
0040 stack::
0041 reserve(std::size_t n)
0042 {
0043 if(cap_ >= n)
0044 return;
0045 auto const base = static_cast<
0046 unsigned char*>(sp_->allocate(n));
0047 if(base_)
0048 {
0049 if(size_ > 0)
0050 std::memcpy(base, base_, size_);
0051 if(base_ != buf_)
0052 sp_->deallocate(base_, cap_);
0053 }
0054 base_ = base;
0055 cap_ = n;
0056 }
0057
0058 }
0059 }
0060 }
0061
0062 #endif