Coverage Report

Created: 2023-03-26 06:57

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