]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/json/impl/null_resource.ipp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / json / impl / null_resource.ipp
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/json/detail/except.hpp>
15
16 BOOST_JSON_NS_BEGIN
17
18 namespace detail {
19
20 /** A resource which always fails.
21
22 This memory resource always throws the exception
23 `std::bad_alloc` in calls to `allocate`.
24 */
25 class null_resource final
26 : public memory_resource
27 {
28 public:
29 /// Copy constructor (deleted)
30 null_resource(
31 null_resource const&) = delete;
32
33 /// Copy assignment (deleted)
34 null_resource& operator=(
35 null_resource const&) = delete;
36
37 /** Destructor
38
39 This destroys the resource.
40
41 @par Complexity
42 Constant.
43
44 @part Exception Safety
45 No-throw guarantee.
46 */
47 ~null_resource() noexcept = default;
48
49 /** Constructor
50
51 This constructs the resource.
52
53 @par Complexity
54 Constant.
55
56 @par Exception Safety
57 No-throw guarantee.
58 */
59 /** @{ */
60 null_resource() noexcept = default;
61
62 protected:
63 void*
64 do_allocate(
65 std::size_t,
66 std::size_t) override
67 {
68 detail::throw_bad_alloc(
69 BOOST_CURRENT_LOCATION);
70 }
71
72 void
73 do_deallocate(
74 void*,
75 std::size_t,
76 std::size_t) override
77 {
78 // do nothing
79 }
80
81 bool
82 do_is_equal(
83 memory_resource const& mr
84 ) const noexcept override
85 {
86 return this == &mr;
87 }
88 };
89
90 } // detail
91
92 memory_resource*
93 get_null_resource() noexcept
94 {
95 static detail::null_resource mr;
96 return &mr;
97 }
98
99 BOOST_JSON_NS_END
100
101 #endif