Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:58

0001 //
0002 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/json
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 } // detail
0059 } // namespace json
0060 } // namespace boost
0061 
0062 #endif