File indexing completed on 2025-09-15 08:38:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_JSON_DETAIL_STACK_HPP
0011 #define BOOST_JSON_DETAIL_STACK_HPP
0012
0013 #include <boost/json/detail/config.hpp>
0014 #include <boost/json/storage_ptr.hpp>
0015 #include <boost/mp11/integral.hpp>
0016 #include <cstring>
0017 #include <type_traits>
0018
0019 namespace boost {
0020 namespace json {
0021 namespace detail {
0022
0023 #if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000
0024
0025 template<class T>
0026 struct is_trivially_copy_assignable
0027 : mp11::mp_bool<
0028 std::is_copy_assignable<T>::value &&
0029 std::has_trivial_copy_assign<T>::value >
0030 {};
0031
0032 #else
0033
0034 using std::is_trivially_copy_assignable;
0035
0036 #endif
0037
0038 class stack
0039 {
0040 template< class T = void >
0041 struct non_trivial;
0042
0043 storage_ptr sp_;
0044 std::size_t cap_ = 0;
0045 std::size_t size_ = 0;
0046 non_trivial<>* head_ = nullptr;
0047 unsigned char* base_ = nullptr;
0048 unsigned char* buf_ = nullptr;
0049
0050 public:
0051 BOOST_JSON_DECL
0052 ~stack();
0053
0054 stack() = default;
0055
0056 stack(
0057 storage_ptr sp,
0058 unsigned char* buf,
0059 std::size_t buf_size) noexcept;
0060
0061 bool
0062 empty() const noexcept
0063 {
0064 return size_ == 0;
0065 }
0066
0067 BOOST_JSON_DECL
0068 void
0069 clear() noexcept;
0070
0071 void
0072 reserve(std::size_t n)
0073 {
0074 if(n > cap_)
0075 reserve_impl(n);
0076 }
0077
0078 template<class T>
0079 void
0080 push(T&& t)
0081 {
0082 using U = remove_cvref<T>;
0083 push( static_cast<T&&>(t), is_trivially_copy_assignable<U>() );
0084 }
0085
0086 template<class T>
0087 void
0088 push_unchecked(
0089 T const& t);
0090
0091 template<class T>
0092 void
0093 peek(T& t);
0094
0095 template<class T>
0096 void
0097 pop(T& t)
0098 {
0099 using U = remove_cvref<T>;
0100 pop( t, is_trivially_copy_assignable<U>() );
0101 }
0102
0103 private:
0104 template<class T> void push(
0105 T const& t, std::true_type);
0106 template<class T> void push(
0107 T&& t, std::false_type);
0108 template<class T> void pop(
0109 T& t, std::true_type);
0110 template<class T> void pop(
0111 T& t, std::false_type);
0112
0113 BOOST_JSON_DECL
0114 void
0115 reserve_impl(
0116 std::size_t n);
0117 };
0118
0119 }
0120 }
0121 }
0122
0123 #include <boost/json/detail/impl/stack.hpp>
0124
0125 #endif