Coverage Report

Created: 2025-11-08 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/boost/boost/json/impl/null_resource.ipp
Line
Count
Source
1
//
2
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3
//
4
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
//
7
// Official repository: https://github.com/boostorg/json
8
//
9
10
#ifndef BOOST_JSON_IMPL_NULL_RESOURCE_IPP
11
#define BOOST_JSON_IMPL_NULL_RESOURCE_IPP
12
13
#include <boost/json/null_resource.hpp>
14
#include <boost/throw_exception.hpp>
15
16
namespace boost {
17
namespace json {
18
19
namespace detail {
20
21
/** A resource which always fails.
22
23
    This memory resource always throws the exception
24
    `std::bad_alloc` in calls to `allocate`.
25
*/
26
class null_resource final
27
    : public container::pmr::memory_resource
28
{
29
public:
30
    /// Copy constructor (deleted)
31
    null_resource(
32
        null_resource const&) = delete;
33
34
    /// Copy assignment (deleted)
35
    null_resource& operator=(
36
        null_resource const&) = delete;
37
38
    /** Constructor
39
40
        This constructs the resource.
41
42
        @par Complexity
43
        Constant.
44
45
        @par Exception Safety
46
        No-throw guarantee.
47
    */
48
    /** @{ */
49
    null_resource() noexcept = default;
50
51
protected:
52
    void*
53
    do_allocate(
54
        std::size_t,
55
        std::size_t) override
56
135
    {
57
135
        throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION );
58
135
    }
59
60
    void
61
    do_deallocate(
62
        void*,
63
        std::size_t,
64
        std::size_t) override
65
0
    {
66
        // do nothing
67
0
    }
68
69
    bool
70
    do_is_equal(
71
        memory_resource const& mr
72
            ) const noexcept override
73
0
    {
74
0
        return this == &mr;
75
0
    }
76
};
77
78
} // detail
79
80
container::pmr::memory_resource*
81
get_null_resource() noexcept
82
2.92k
{
83
2.92k
    static detail::null_resource mr;
84
2.92k
    return &mr;
85
2.92k
}
86
87
} // namespace json
88
} // namespace boost
89
90
#endif