File indexing completed on 2025-09-16 08:37:29
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::non_trivial<>*
0020 stack::non_trivial<>::destroy() noexcept
0021 {
0022 non_trivial* const result = next;
0023 rel(this, nullptr);
0024 return result;
0025 }
0026
0027 stack::non_trivial<>*
0028 stack::non_trivial<>::relocate(void* dst) noexcept
0029 {
0030 return rel(this, dst);
0031 }
0032
0033
0034 stack::
0035 ~stack()
0036 {
0037 clear();
0038 if(base_ != buf_)
0039 sp_->deallocate(
0040 base_, cap_);
0041 }
0042
0043 stack::
0044 stack(
0045 storage_ptr sp,
0046 unsigned char* buf,
0047 std::size_t buf_size) noexcept
0048 : sp_(std::move(sp))
0049 , cap_(buf_size)
0050 , base_(buf)
0051 , buf_(buf)
0052 {
0053 }
0054
0055 void
0056 stack::
0057 clear() noexcept
0058 {
0059 while(head_)
0060 head_ = head_->destroy();
0061 size_ = 0;
0062 }
0063
0064 void
0065 stack::
0066 reserve_impl(std::size_t n)
0067 {
0068
0069 BOOST_ASSERT(n > cap_);
0070
0071 auto const base = static_cast<unsigned char*>( sp_->allocate(n) );
0072 if(base_)
0073 {
0074
0075 std::memcpy(base, base_, size_);
0076
0077
0078 non_trivial<>* src = head_;
0079 non_trivial<>** prev = &head_;
0080 while(src)
0081 {
0082 std::size_t const buf_offset =
0083 reinterpret_cast<unsigned char*>(src) - base_;
0084 non_trivial<>* dest = src->relocate(base + buf_offset);
0085 *prev = dest;
0086 prev = &dest->next;
0087 src = dest->next;
0088 }
0089
0090 if(base_ != buf_)
0091 sp_->deallocate(base_, cap_);
0092 }
0093 base_ = base;
0094 cap_ = n;
0095 }
0096
0097 }
0098 }
0099 }
0100
0101 #endif