GCC Code Coverage Report


Directory: libs/json/include/boost/json/
File: detail/stack.hpp
Date: 2025-12-23 17:20:53
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 100 169 59.2%
Branches: 4 4 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_DETAIL_STACK_HPP
11 #define BOOST_JSON_DETAIL_STACK_HPP
12
13 #include <boost/json/detail/config.hpp>
14 #include <boost/json/storage_ptr.hpp>
15 #include <boost/mp11/integral.hpp>
16 #include <cstring>
17 #include <type_traits>
18
19 namespace boost {
20 namespace json {
21 namespace detail {
22
23 #if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000
24
25 template<class T>
26 struct is_trivially_copy_assignable
27 : mp11::mp_bool<
28 std::is_copy_assignable<T>::value &&
29 std::has_trivial_copy_assign<T>::value >
30 {};
31
32 #else
33
34 using std::is_trivially_copy_assignable;
35
36 #endif
37
38 class stack
39 {
40 template< class T = void >
41 struct non_trivial;
42
43 storage_ptr sp_;
44 std::size_t cap_ = 0;
45 std::size_t size_ = 0;
46 non_trivial<>* head_ = nullptr;
47 unsigned char* base_ = nullptr;
48 unsigned char* buf_ = nullptr;
49
50 public:
51 BOOST_JSON_DECL
52 ~stack();
53
54 2164640 stack() = default;
55
56 stack(
57 storage_ptr sp,
58 unsigned char* buf,
59 std::size_t buf_size) noexcept;
60
61 bool
62 3262230 empty() const noexcept
63 {
64 3262230 return size_ == 0;
65 }
66
67 BOOST_JSON_DECL
68 void
69 clear() noexcept;
70
71 void
72 173315 reserve(std::size_t n)
73 {
74
2/2
✓ Branch 0 taken 115816 times.
✓ Branch 1 taken 57499 times.
173315 if(n > cap_)
75 115816 reserve_impl(n);
76 173315 }
77
78 template<class T>
79 void
80 95792 push(T&& t)
81 {
82 using U = remove_cvref<T>;
83
1/1
✓ Branch 1 taken 47894 times.
95792 push( static_cast<T&&>(t), is_trivially_copy_assignable<U>() );
84 95788 }
85
86 template<class T>
87 void
88 push_unchecked(
89 T const& t);
90
91 template<class T>
92 void
93 peek(T& t);
94
95 template<class T>
96 void
97 658386 pop(T& t)
98 {
99 using U = remove_cvref<T>;
100
1/1
✓ Branch 1 taken 120725 times.
658386 pop( t, is_trivially_copy_assignable<U>() );
101 658386 }
102
103 private:
104 template<class T> void push(
105 T const& t, std::true_type);
106 template<class T> void push(
107 T&& t, std::false_type);
108 template<class T> void pop(
109 T& t, std::true_type);
110 template<class T> void pop(
111 T& t, std::false_type);
112
113 BOOST_JSON_DECL
114 void
115 reserve_impl(
116 std::size_t n);
117 };
118
119 } // detail
120 } // namespace json
121 } // namespace boost
122
123 #include <boost/json/detail/impl/stack.hpp>
124
125 #endif
126