/src/boost/boost/json/detail/stack.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_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 | 39.3k | stack() = default; |
55 | | |
56 | | stack( |
57 | | storage_ptr sp, |
58 | | unsigned char* buf, |
59 | | std::size_t buf_size) noexcept; |
60 | | |
61 | | bool |
62 | | empty() const noexcept |
63 | 9.31M | { |
64 | 9.31M | return size_ == 0; |
65 | 9.31M | } |
66 | | |
67 | | BOOST_JSON_DECL |
68 | | void |
69 | | clear() noexcept; |
70 | | |
71 | | void |
72 | | reserve(std::size_t n) |
73 | 11.1k | { |
74 | 11.1k | if(n > cap_) |
75 | 11.1k | reserve_impl(n); |
76 | 11.1k | } |
77 | | |
78 | | template<class T> |
79 | | void |
80 | | push(T&& t) |
81 | 29.1k | { |
82 | 29.1k | using U = remove_cvref<T>; |
83 | 29.1k | push( static_cast<T&&>(t), is_trivially_copy_assignable<U>() ); |
84 | 29.1k | } void boost::json::detail::stack::push<boost::json::detail::writer::state&>(boost::json::detail::writer::state&) Line | Count | Source | 81 | 11.3k | { | 82 | 11.3k | using U = remove_cvref<T>; | 83 | 11.3k | push( static_cast<T&&>(t), is_trivially_copy_assignable<U>() ); | 84 | 11.3k | } |
Unexecuted instantiation: void boost::json::detail::stack::push<boost::json::basic_parser<boost::json::detail::handler>::state>(boost::json::basic_parser<boost::json::detail::handler>::state&&) void boost::json::detail::stack::push<boost::json::array const*&>(boost::json::array const*&) Line | Count | Source | 81 | 7.07k | { | 82 | 7.07k | using U = remove_cvref<T>; | 83 | 7.07k | push( static_cast<T&&>(t), is_trivially_copy_assignable<U>() ); | 84 | 7.07k | } |
void boost::json::detail::stack::push<boost::json::value const*&>(boost::json::value const*&) Line | Count | Source | 81 | 7.07k | { | 82 | 7.07k | using U = remove_cvref<T>; | 83 | 7.07k | push( static_cast<T&&>(t), is_trivially_copy_assignable<U>() ); | 84 | 7.07k | } |
void boost::json::detail::stack::push<boost::json::object const*&>(boost::json::object const*&) Line | Count | Source | 81 | 1.87k | { | 82 | 1.87k | using U = remove_cvref<T>; | 83 | 1.87k | push( static_cast<T&&>(t), is_trivially_copy_assignable<U>() ); | 84 | 1.87k | } |
void boost::json::detail::stack::push<boost::json::key_value_pair const*&>(boost::json::key_value_pair const*&) Line | Count | Source | 81 | 1.87k | { | 82 | 1.87k | using U = remove_cvref<T>; | 83 | 1.87k | push( static_cast<T&&>(t), is_trivially_copy_assignable<U>() ); | 84 | 1.87k | } |
|
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 | | pop(T& t) |
98 | 48.0k | { |
99 | 48.0k | using U = remove_cvref<T>; |
100 | 48.0k | pop( t, is_trivially_copy_assignable<U>() ); |
101 | 48.0k | } void boost::json::detail::stack::pop<boost::json::basic_parser<boost::json::detail::handler>::state>(boost::json::basic_parser<boost::json::detail::handler>::state&) Line | Count | Source | 98 | 14.2k | { | 99 | 14.2k | using U = remove_cvref<T>; | 100 | 14.2k | pop( t, is_trivially_copy_assignable<U>() ); | 101 | 14.2k | } |
void boost::json::detail::stack::pop<unsigned long>(unsigned long&) Line | Count | Source | 98 | 4.60k | { | 99 | 4.60k | using U = remove_cvref<T>; | 100 | 4.60k | pop( t, is_trivially_copy_assignable<U>() ); | 101 | 4.60k | } |
void boost::json::detail::stack::pop<boost::json::detail::writer::state>(boost::json::detail::writer::state&) Line | Count | Source | 98 | 11.3k | { | 99 | 11.3k | using U = remove_cvref<T>; | 100 | 11.3k | pop( t, is_trivially_copy_assignable<U>() ); | 101 | 11.3k | } |
void boost::json::detail::stack::pop<boost::json::value const*>(boost::json::value const*&) Line | Count | Source | 98 | 7.07k | { | 99 | 7.07k | using U = remove_cvref<T>; | 100 | 7.07k | pop( t, is_trivially_copy_assignable<U>() ); | 101 | 7.07k | } |
void boost::json::detail::stack::pop<boost::json::array const*>(boost::json::array const*&) Line | Count | Source | 98 | 7.07k | { | 99 | 7.07k | using U = remove_cvref<T>; | 100 | 7.07k | pop( t, is_trivially_copy_assignable<U>() ); | 101 | 7.07k | } |
void boost::json::detail::stack::pop<boost::json::key_value_pair const*>(boost::json::key_value_pair const*&) Line | Count | Source | 98 | 1.87k | { | 99 | 1.87k | using U = remove_cvref<T>; | 100 | 1.87k | pop( t, is_trivially_copy_assignable<U>() ); | 101 | 1.87k | } |
void boost::json::detail::stack::pop<boost::json::object const*>(boost::json::object const*&) Line | Count | Source | 98 | 1.87k | { | 99 | 1.87k | using U = remove_cvref<T>; | 100 | 1.87k | pop( t, is_trivially_copy_assignable<U>() ); | 101 | 1.87k | } |
|
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 |