]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/json/detail/default_resource.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / json / detail / default_resource.hpp
CommitLineData
20effc67
TL
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_DEFAULT_RESOURCE_HPP
11#define BOOST_JSON_DEFAULT_RESOURCE_HPP
12
13#include <boost/json/detail/config.hpp>
14#include <new>
15
16BOOST_JSON_NS_BEGIN
17namespace detail {
18
19#ifdef _MSC_VER
20#pragma warning(push)
21#pragma warning(disable: 4251) // class needs to have dll-interface to be used by clients of class
22#pragma warning(disable: 4275) // non dll-interface class used as base for dll-interface class
23#endif
24
25// A simple memory resource that uses operator new and delete.
26class
27 BOOST_SYMBOL_VISIBLE
28 BOOST_JSON_CLASS_DECL
29 default_resource final
30 : public memory_resource
31{
32 union holder;
33
34#ifndef BOOST_JSON_WEAK_CONSTINIT
35# ifndef BOOST_JSON_NO_DESTROY
36 static holder instance_;
37# else
38 BOOST_JSON_NO_DESTROY
39 static default_resource instance_;
40# endif
41#endif
42
43public:
44 static
45 memory_resource*
46 get() noexcept
47 {
48 #ifdef BOOST_JSON_WEAK_CONSTINIT
49 static default_resource instance_;
50 #endif
51 return reinterpret_cast<memory_resource*>(
52 reinterpret_cast<std::uintptr_t*>(
53 &instance_));
54 }
55
56 ~default_resource();
57
58 void*
59 do_allocate(
60 std::size_t n,
61 std::size_t) override;
62
63 void
64 do_deallocate(
65 void* p,
66 std::size_t,
67 std::size_t) override;
68
69 bool
70 do_is_equal(
71 memory_resource const& mr) const noexcept override;
72};
73
74#ifdef _MSC_VER
75#pragma warning(pop)
76#endif
77
78union default_resource::
79 holder
80{
81#ifndef BOOST_JSON_WEAK_CONSTINIT
82 constexpr
83#endif
84 holder()
85 : mr()
86 {
87 }
88
89 ~holder()
90 {
91 }
92
93 default_resource mr;
94};
95
96} // detail
97BOOST_JSON_NS_END
98
99#endif