detail/value.hpp
100.0% Lines (58 / 58)
82.0% Functions (50 / 61)
Functions (61)
Function
Calls
Lines
Blocks
boost::json::detail::to_number_limit<unsigned char>::max1(std::integral_constant<bool, false>)
:35
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned int>::max1(std::integral_constant<bool, false>)
:35
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned long long>::max1(std::integral_constant<bool, false>)
:35
0
0.0%
0.0%
boost::json::detail::to_number_limit<unsigned long>::max1(std::integral_constant<bool, false>)
:35
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned short>::max1(std::integral_constant<bool, false>)
:35
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned char>::max2u(std::integral_constant<bool, false>)
:43
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned int>::max2u(std::integral_constant<bool, false>)
:43
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned short>::max2u(std::integral_constant<bool, false>)
:43
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned long long>::max2u(std::integral_constant<bool, true>)
:50
0
0.0%
0.0%
boost::json::detail::to_number_limit<unsigned long>::max2u(std::integral_constant<bool, true>)
:50
4x
100.0%
100.0%
boost::json::detail::to_number_limit<char>::max1(std::integral_constant<bool, true>)
:59
0
0.0%
0.0%
boost::json::detail::to_number_limit<int>::max1(std::integral_constant<bool, true>)
:59
13x
100.0%
100.0%
boost::json::detail::to_number_limit<long long>::max1(std::integral_constant<bool, true>)
:59
0
0.0%
0.0%
boost::json::detail::to_number_limit<long>::max1(std::integral_constant<bool, true>)
:59
6x
100.0%
100.0%
boost::json::detail::to_number_limit<short>::max1(std::integral_constant<bool, true>)
:59
5x
100.0%
100.0%
boost::json::detail::to_number_limit<signed char>::max1(std::integral_constant<bool, true>)
:59
5x
100.0%
100.0%
boost::json::detail::to_number_limit<char>::max2s(std::integral_constant<bool, false>)
:67
0
0.0%
0.0%
boost::json::detail::to_number_limit<int>::max2s(std::integral_constant<bool, false>)
:67
13x
100.0%
100.0%
boost::json::detail::to_number_limit<short>::max2s(std::integral_constant<bool, false>)
:67
5x
100.0%
100.0%
boost::json::detail::to_number_limit<signed char>::max2s(std::integral_constant<bool, false>)
:67
5x
100.0%
100.0%
boost::json::detail::to_number_limit<long long>::max2s(std::integral_constant<bool, true>)
:74
0
0.0%
0.0%
boost::json::detail::to_number_limit<long>::max2s(std::integral_constant<bool, true>)
:74
6x
100.0%
100.0%
boost::json::detail::to_number_limit<char>::min()
:82
0
0.0%
0.0%
boost::json::detail::to_number_limit<int>::min()
:82
14x
100.0%
100.0%
boost::json::detail::to_number_limit<long long>::min()
:82
0
0.0%
0.0%
boost::json::detail::to_number_limit<long>::min()
:82
6x
100.0%
100.0%
boost::json::detail::to_number_limit<short>::min()
:82
6x
100.0%
100.0%
boost::json::detail::to_number_limit<signed char>::min()
:82
6x
100.0%
100.0%
boost::json::detail::to_number_limit<char>::max()
:88
0
0.0%
0.0%
boost::json::detail::to_number_limit<int>::max()
:88
13x
100.0%
100.0%
boost::json::detail::to_number_limit<long long>::max()
:88
0
0.0%
0.0%
boost::json::detail::to_number_limit<long>::max()
:88
6x
100.0%
100.0%
boost::json::detail::to_number_limit<short>::max()
:88
5x
100.0%
100.0%
boost::json::detail::to_number_limit<signed char>::max()
:88
5x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned char>::max()
:88
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned int>::max()
:88
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned long long>::max()
:88
0
0.0%
0.0%
boost::json::detail::to_number_limit<unsigned long>::max()
:88
4x
100.0%
100.0%
boost::json::detail::to_number_limit<unsigned short>::max()
:88
4x
100.0%
100.0%
boost::json::detail::scalar::scalar(boost::json::storage_ptr)
:107
2152210x
100.0%
100.0%
boost::json::detail::scalar::scalar(bool, boost::json::storage_ptr)
:114
1107x
100.0%
100.0%
boost::json::detail::scalar::scalar(long, boost::json::storage_ptr)
:123
34780x
100.0%
100.0%
boost::json::detail::scalar::scalar(unsigned long, boost::json::storage_ptr)
:132
406x
100.0%
100.0%
boost::json::detail::scalar::scalar(double, boost::json::storage_ptr)
:141
2039974x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, bool&, boost::json::storage_ptr&>(boost::json::value*, bool&, boost::json::storage_ptr&)
:155
400x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, boost::core::basic_string_view<char>&, boost::json::storage_ptr&>(boost::json::value*, boost::core::basic_string_view<char>&, boost::json::storage_ptr&)
:155
17148x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, boost::core::basic_string_view<char>&, boost::json::storage_ptr>(boost::json::value*, boost::core::basic_string_view<char>&, boost::json::storage_ptr&&)
:155
1x
100.0%
64.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, boost::json::detail::key_t, boost::core::basic_string_view<char>&, boost::core::basic_string_view<char>&, boost::json::storage_ptr&>(boost::json::value*, boost::json::detail::key_t&&, boost::core::basic_string_view<char>&, boost::core::basic_string_view<char>&, boost::json::storage_ptr&)
:155
8061x
100.0%
69.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, boost::json::detail::key_t, boost::core::basic_string_view<char>&, boost::json::storage_ptr&>(boost::json::value*, boost::json::detail::key_t&&, boost::core::basic_string_view<char>&, boost::json::storage_ptr&)
:155
30297x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, boost::json::detail::unchecked_array>(boost::json::value*, boost::json::detail::unchecked_array&&)
:155
2120x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, boost::json::detail::unchecked_object>(boost::json::value*, boost::json::detail::unchecked_object&&)
:155
34880x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, boost::json::string_kind_t const&, boost::json::storage_ptr&>(boost::json::value*, boost::json::string_kind_t const&, boost::json::storage_ptr&)
:155
8960x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, decltype(nullptr), boost::json::storage_ptr&>(boost::json::value*, decltype(nullptr)&&, boost::json::storage_ptr&)
:155
9369x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, double&, boost::json::storage_ptr&>(boost::json::value*, double&, boost::json::storage_ptr&)
:155
2039830x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, long&, boost::json::storage_ptr&>(boost::json::value*, long&, boost::json::storage_ptr&)
:155
5816x
100.0%
100.0%
boost::json::value& boost::json::detail::access::construct_value<boost::json::value, unsigned long&, boost::json::storage_ptr&>(boost::json::value*, unsigned long&, boost::json::storage_ptr&)
:155
70x
100.0%
100.0%
boost::json::key_value_pair& boost::json::detail::access::construct_key_value_pair<boost::json::key_value_pair, boost::json::pilfered<boost::json::value>, boost::json::pilfered<boost::json::value> >(boost::json::key_value_pair*, boost::json::pilfered<boost::json::value>&&, boost::json::pilfered<boost::json::value>&&)
:165
38151x
100.0%
100.0%
char const* boost::json::detail::access::release_key<boost::json::value>(boost::json::value&, unsigned long&)
:177
38151x
100.0%
83.0%
unsigned int& boost::json::detail::access::next<boost::json::key_value_pair>(boost::json::key_value_pair&)
:191
11464x
100.0%
100.0%
boost::json::detail::scalar& boost::json::detail::access::get_scalar<boost::json::value>(boost::json::value&)
:207
12x
100.0%
100.0%
boost::json::detail::scalar const& boost::json::detail::access::get_scalar<boost::json::value>(boost::json::value const&)
:215
264x
100.0%
100.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 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_VALUE_HPP | ||
| 11 | #define BOOST_JSON_DETAIL_VALUE_HPP | ||
| 12 | |||
| 13 | #include <boost/json/fwd.hpp> | ||
| 14 | #include <boost/json/kind.hpp> | ||
| 15 | #include <boost/json/storage_ptr.hpp> | ||
| 16 | #include <cstdint> | ||
| 17 | #include <limits> | ||
| 18 | #include <new> | ||
| 19 | #include <utility> | ||
| 20 | |||
| 21 | namespace boost { | ||
| 22 | namespace json { | ||
| 23 | namespace detail { | ||
| 24 | |||
| 25 | struct key_t | ||
| 26 | { | ||
| 27 | }; | ||
| 28 | |||
| 29 | template<class T> | ||
| 30 | class to_number_limit | ||
| 31 | { | ||
| 32 | // unsigned | ||
| 33 | |||
| 34 | static constexpr | ||
| 35 | 16x | double max1(std::false_type) | |
| 36 | { | ||
| 37 | 16x | return max2u(std::integral_constant< | |
| 38 | bool, (std::numeric_limits<T>::max)() == | ||
| 39 | 16x | UINT64_MAX>{}); | |
| 40 | } | ||
| 41 | |||
| 42 | static constexpr | ||
| 43 | 12x | double max2u(std::false_type) | |
| 44 | { | ||
| 45 | return static_cast<double>( | ||
| 46 | 12x | (std::numeric_limits<T>::max)()); | |
| 47 | } | ||
| 48 | |||
| 49 | static constexpr | ||
| 50 | 4x | double max2u(std::true_type) | |
| 51 | { | ||
| 52 | // largest uint64_t value exactly representable as double | ||
| 53 | 4x | return 18446744073709549568.0; | |
| 54 | } | ||
| 55 | |||
| 56 | // signed | ||
| 57 | |||
| 58 | static constexpr | ||
| 59 | 29x | double max1(std::true_type) | |
| 60 | { | ||
| 61 | 29x | return max2s(std::integral_constant< | |
| 62 | bool, (std::numeric_limits<T>::max)() == | ||
| 63 | 29x | INT64_MAX>{}); | |
| 64 | } | ||
| 65 | |||
| 66 | static constexpr | ||
| 67 | 23x | double max2s(std::false_type) | |
| 68 | { | ||
| 69 | return static_cast<double>( | ||
| 70 | 23x | (std::numeric_limits<T>::max)()); | |
| 71 | } | ||
| 72 | |||
| 73 | static constexpr | ||
| 74 | 6x | double max2s(std::true_type) | |
| 75 | { | ||
| 76 | // largest int64_t value exactly representable as double | ||
| 77 | 6x | return 9223372036854774784.0; | |
| 78 | } | ||
| 79 | |||
| 80 | public: | ||
| 81 | static constexpr | ||
| 82 | 32x | double (min)() noexcept | |
| 83 | { | ||
| 84 | 32x | return static_cast<double>( (std::numeric_limits<T>::min)() ); | |
| 85 | } | ||
| 86 | |||
| 87 | static constexpr | ||
| 88 | 45x | double (max)() noexcept | |
| 89 | { | ||
| 90 | 45x | return max1(std::is_signed<T>{}); | |
| 91 | } | ||
| 92 | }; | ||
| 93 | |||
| 94 | struct scalar | ||
| 95 | { | ||
| 96 | storage_ptr sp; // must come first | ||
| 97 | kind k; // must come second | ||
| 98 | union | ||
| 99 | { | ||
| 100 | bool b; | ||
| 101 | std::int64_t i; | ||
| 102 | std::uint64_t u; | ||
| 103 | double d; | ||
| 104 | }; | ||
| 105 | |||
| 106 | explicit | ||
| 107 | 2152210x | scalar(storage_ptr sp_ = {}) noexcept | |
| 108 | 2152210x | : sp(std::move(sp_)) | |
| 109 | 2152210x | , k(json::kind::null) | |
| 110 | { | ||
| 111 | 2152210x | } | |
| 112 | |||
| 113 | explicit | ||
| 114 | 1107x | scalar(bool b_, | |
| 115 | storage_ptr sp_ = {}) noexcept | ||
| 116 | 1107x | : sp(std::move(sp_)) | |
| 117 | 1107x | , k(json::kind::bool_) | |
| 118 | 1107x | , b(b_) | |
| 119 | { | ||
| 120 | 1107x | } | |
| 121 | |||
| 122 | explicit | ||
| 123 | 34780x | scalar(std::int64_t i_, | |
| 124 | storage_ptr sp_ = {}) noexcept | ||
| 125 | 34780x | : sp(std::move(sp_)) | |
| 126 | 34780x | , k(json::kind::int64) | |
| 127 | 34780x | , i(i_) | |
| 128 | { | ||
| 129 | 34780x | } | |
| 130 | |||
| 131 | explicit | ||
| 132 | 406x | scalar(std::uint64_t u_, | |
| 133 | storage_ptr sp_ = {}) noexcept | ||
| 134 | 406x | : sp(std::move(sp_)) | |
| 135 | 406x | , k(json::kind::uint64) | |
| 136 | 406x | , u(u_) | |
| 137 | { | ||
| 138 | 406x | } | |
| 139 | |||
| 140 | explicit | ||
| 141 | 2039974x | scalar(double d_, | |
| 142 | storage_ptr sp_ = {}) noexcept | ||
| 143 | 2039974x | : sp(std::move(sp_)) | |
| 144 | 2039974x | , k(json::kind::double_) | |
| 145 | 2039974x | , d(d_) | |
| 146 | { | ||
| 147 | 2039974x | } | |
| 148 | }; | ||
| 149 | |||
| 150 | struct access | ||
| 151 | { | ||
| 152 | template<class Value, class... Args> | ||
| 153 | static | ||
| 154 | Value& | ||
| 155 | 2156952x | construct_value(Value* p, Args&&... args) | |
| 156 | { | ||
| 157 | return *reinterpret_cast< | ||
| 158 | 6396997x | Value*>(::new(p) Value( | |
| 159 | 6489299x | std::forward<Args>(args)...)); | |
| 160 | } | ||
| 161 | |||
| 162 | template<class KeyValuePair, class... Args> | ||
| 163 | static | ||
| 164 | KeyValuePair& | ||
| 165 | 38151x | construct_key_value_pair( | |
| 166 | KeyValuePair* p, Args&&... args) | ||
| 167 | { | ||
| 168 | return *reinterpret_cast< | ||
| 169 | 38151x | KeyValuePair*>(::new(p) | |
| 170 | KeyValuePair( | ||
| 171 | 76302x | std::forward<Args>(args)...)); | |
| 172 | } | ||
| 173 | |||
| 174 | template<class Value> | ||
| 175 | static | ||
| 176 | char const* | ||
| 177 | 38151x | release_key( | |
| 178 | Value& jv, | ||
| 179 | std::size_t& len) noexcept | ||
| 180 | { | ||
| 181 | 38151x | BOOST_ASSERT(jv.is_string()); | |
| 182 | 38151x | jv.str_.sp_.~storage_ptr(); | |
| 183 | 38151x | return jv.str_.impl_.release_key(len); | |
| 184 | } | ||
| 185 | |||
| 186 | using index_t = std::uint32_t; | ||
| 187 | |||
| 188 | template<class KeyValuePair> | ||
| 189 | static | ||
| 190 | index_t& | ||
| 191 | 11464x | next(KeyValuePair& e) noexcept | |
| 192 | { | ||
| 193 | 11464x | return e.next_; | |
| 194 | } | ||
| 195 | |||
| 196 | template<class KeyValuePair> | ||
| 197 | static | ||
| 198 | index_t const& | ||
| 199 | next(KeyValuePair const& e) noexcept | ||
| 200 | { | ||
| 201 | return e.next_; | ||
| 202 | } | ||
| 203 | |||
| 204 | template<class Value> | ||
| 205 | static | ||
| 206 | auto | ||
| 207 | 12x | get_scalar(Value& jv) -> scalar& | |
| 208 | { | ||
| 209 | 12x | return jv.sca_; | |
| 210 | } | ||
| 211 | |||
| 212 | template<class Value> | ||
| 213 | static | ||
| 214 | auto | ||
| 215 | 264x | get_scalar(Value const& jv) -> scalar const& | |
| 216 | { | ||
| 217 | 264x | return jv.sca_; | |
| 218 | } | ||
| 219 | }; | ||
| 220 | |||
| 221 | BOOST_JSON_DECL | ||
| 222 | std::size_t | ||
| 223 | hash_value_impl( value const& jv ) noexcept; | ||
| 224 | |||
| 225 | } // detail | ||
| 226 | } // namespace json | ||
| 227 | } // namespace boost | ||
| 228 | |||
| 229 | #endif | ||
| 230 |