Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:02

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_IMPL_STATIC_RESOURCE_IPP
0011 #define BOOST_JSON_IMPL_STATIC_RESOURCE_IPP
0012 
0013 #include <boost/json/static_resource.hpp>
0014 #include <boost/throw_exception.hpp>
0015 #include <boost/align/align.hpp>
0016 #include <memory>
0017 
0018 namespace boost {
0019 namespace json {
0020 
0021 static_resource::
0022 static_resource(
0023     unsigned char* buffer,
0024     std::size_t size) noexcept
0025     : p_(buffer)
0026     , n_(size)
0027     , size_(size)
0028 {
0029 }
0030 
0031 void
0032 static_resource::
0033 release() noexcept
0034 {
0035     p_ = reinterpret_cast<
0036         char*>(p_) - (size_ - n_);
0037     n_ = size_;
0038 }
0039 
0040 void*
0041 static_resource::
0042 do_allocate(
0043     std::size_t n,
0044     std::size_t align)
0045 {
0046     auto p = alignment::align(
0047         align, n, p_, n_);
0048     if(! p)
0049         throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION );
0050     p_ = reinterpret_cast<char*>(p) + n;
0051     n_ -= n;
0052     return p;
0053 }
0054 
0055 void
0056 static_resource::
0057 do_deallocate(
0058     void*,
0059     std::size_t,
0060     std::size_t)
0061 {
0062     // do nothing
0063 }
0064 
0065 bool
0066 static_resource::
0067 do_is_equal(
0068     memory_resource const& mr) const noexcept
0069 {
0070     return this == &mr;
0071 }
0072 
0073 } // namespace json
0074 } // namespace boost
0075 
0076 #endif