Back to home page

EIC code displayed by LXR

 
 

    


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

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_NULL_RESOURCE_IPP
0011 #define BOOST_JSON_IMPL_NULL_RESOURCE_IPP
0012 
0013 #include <boost/json/null_resource.hpp>
0014 #include <boost/throw_exception.hpp>
0015 
0016 namespace boost {
0017 namespace json {
0018 
0019 namespace detail {
0020 
0021 /** A resource which always fails.
0022 
0023     This memory resource always throws the exception
0024     `std::bad_alloc` in calls to `allocate`.
0025 */
0026 class null_resource final
0027     : public memory_resource
0028 {
0029 public:
0030     /// Copy constructor (deleted)
0031     null_resource(
0032         null_resource const&) = delete;
0033 
0034     /// Copy assignment (deleted)
0035     null_resource& operator=(
0036         null_resource const&) = delete;
0037 
0038     /** Constructor
0039 
0040         This constructs the resource.
0041 
0042         @par Complexity
0043         Constant.
0044 
0045         @par Exception Safety
0046         No-throw guarantee.
0047     */
0048     /** @{ */
0049     null_resource() noexcept = default;
0050 
0051 protected:
0052     void*
0053     do_allocate(
0054         std::size_t,
0055         std::size_t) override
0056     {
0057         throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION );
0058     }
0059 
0060     void
0061     do_deallocate(
0062         void*,
0063         std::size_t,
0064         std::size_t) override
0065     {
0066         // do nothing
0067     }
0068 
0069     bool
0070     do_is_equal(
0071         memory_resource const& mr
0072             ) const noexcept override
0073     {
0074         return this == &mr;
0075     }
0076 };
0077 
0078 } // detail
0079 
0080 memory_resource*
0081 get_null_resource() noexcept
0082 {
0083     static detail::null_resource mr;
0084     return &mr;
0085 }
0086 
0087 } // namespace json
0088 } // namespace boost
0089 
0090 #endif