GCC Code Coverage Report


Directory: libs/json/include/boost/json/
File: impl/static_resource.ipp
Date: 2026-01-02 17:31:41
Exec Total Coverage
Lines: 18 22 81.8%
Functions: 3 5 60.0%
Branches: 2 2 100.0%

Line Branch Exec 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_STATIC_RESOURCE_IPP
11 #define BOOST_JSON_IMPL_STATIC_RESOURCE_IPP
12
13 #include <boost/json/static_resource.hpp>
14 #include <boost/throw_exception.hpp>
15 #include <memory>
16
17 namespace boost {
18 namespace json {
19
20 7 static_resource::
21 static_resource(
22 unsigned char* buffer,
23 7 std::size_t size) noexcept
24 7 : p_(buffer)
25 7 , n_(size)
26 7 , size_(size)
27 {
28 7 }
29
30 void
31 1 static_resource::
32 release() noexcept
33 {
34 1 p_ = reinterpret_cast<
35 1 char*>(p_) - (size_ - n_);
36 1 n_ = size_;
37 1 }
38
39 void*
40 10 static_resource::
41 do_allocate(
42 std::size_t n,
43 std::size_t align)
44 {
45 10 auto p = std::align(align, n, p_, n_);
46
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8 times.
10 if(! p)
47 4 throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION );
48 8 p_ = reinterpret_cast<char*>(p) + n;
49 8 n_ -= n;
50 8 return p;
51 }
52
53 void
54 static_resource::
55 do_deallocate(
56 void*,
57 std::size_t,
58 std::size_t)
59 {
60 // do nothing
61 }
62
63 bool
64 static_resource::
65 do_is_equal(
66 memory_resource const& mr) const noexcept
67 {
68 return this == &mr;
69 }
70
71 } // namespace json
72 } // namespace boost
73
74 #endif
75