detail/value.hpp
81.8% Lines (157/192)
79.5% List of functions (58/73)
Functions (73)
Function
Calls
Lines
Branches
Blocks
boost::json::detail::to_number_limit<unsigned char>::max1(std::integral_constant<bool, false>)
:85
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned int>::max1(std::integral_constant<bool, false>)
:85
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned long long>::max1(std::integral_constant<bool, false>)
:85
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<unsigned long>::max1(std::integral_constant<bool, false>)
:85
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned short>::max1(std::integral_constant<bool, false>)
:85
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned char>::max2u(std::integral_constant<bool, false>)
:93
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned int>::max2u(std::integral_constant<bool, false>)
:93
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned short>::max2u(std::integral_constant<bool, false>)
:93
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned long long>::max2u(std::integral_constant<bool, true>)
:100
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<unsigned long>::max2u(std::integral_constant<bool, true>)
:100
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<char>::min1(std::integral_constant<bool, true>)
:108
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<int>::min1(std::integral_constant<bool, true>)
:108
11x
100.0%
–
100.0%
boost::json::detail::to_number_limit<long long>::min1(std::integral_constant<bool, true>)
:108
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<long>::min1(std::integral_constant<bool, true>)
:108
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<short>::min1(std::integral_constant<bool, true>)
:108
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<signed char>::min1(std::integral_constant<bool, true>)
:108
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<char>::min2s(std::integral_constant<bool, false>)
:116
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<int>::min2s(std::integral_constant<bool, false>)
:116
11x
100.0%
–
100.0%
boost::json::detail::to_number_limit<short>::min2s(std::integral_constant<bool, false>)
:116
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<signed char>::min2s(std::integral_constant<bool, false>)
:116
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<long long>::min2s(std::integral_constant<bool, true>)
:123
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<long>::min2s(std::integral_constant<bool, true>)
:123
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<char>::max1(std::integral_constant<bool, true>)
:129
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<int>::max1(std::integral_constant<bool, true>)
:129
11x
100.0%
–
100.0%
boost::json::detail::to_number_limit<long long>::max1(std::integral_constant<bool, true>)
:129
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<long>::max1(std::integral_constant<bool, true>)
:129
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<short>::max1(std::integral_constant<bool, true>)
:129
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<signed char>::max1(std::integral_constant<bool, true>)
:129
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<char>::max2s(std::integral_constant<bool, false>)
:137
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<int>::max2s(std::integral_constant<bool, false>)
:137
11x
100.0%
–
100.0%
boost::json::detail::to_number_limit<short>::max2s(std::integral_constant<bool, false>)
:137
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<signed char>::max2s(std::integral_constant<bool, false>)
:137
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<long long>::max2s(std::integral_constant<bool, true>)
:144
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<long>::max2s(std::integral_constant<bool, true>)
:144
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<char>::min()
:151
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<int>::min()
:151
11x
100.0%
–
100.0%
boost::json::detail::to_number_limit<long long>::min()
:151
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<long>::min()
:151
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<short>::min()
:151
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<signed char>::min()
:151
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<char>::max()
:157
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<int>::max()
:157
11x
100.0%
–
100.0%
boost::json::detail::to_number_limit<long long>::max()
:157
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<long>::max()
:157
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<short>::max()
:157
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<signed char>::max()
:157
3x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned char>::max()
:157
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned int>::max()
:157
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned long long>::max()
:157
0
0.0%
–
0.0%
boost::json::detail::to_number_limit<unsigned long>::max()
:157
2x
100.0%
–
100.0%
boost::json::detail::to_number_limit<unsigned short>::max()
:157
2x
100.0%
–
100.0%
boost::json::detail::scalar::scalar(boost::json::storage_ptr)
:178
2152100x
100.0%
–
100.0%
boost::json::detail::scalar::scalar(bool, boost::json::storage_ptr)
:185
1088x
100.0%
–
100.0%
boost::json::detail::scalar::scalar(long, boost::json::storage_ptr)
:194
34593x
100.0%
–
100.0%
boost::json::detail::scalar::scalar(unsigned long, boost::json::storage_ptr)
:203
406x
100.0%
–
100.0%
boost::json::detail::scalar::scalar(double, boost::json::storage_ptr)
:212
2040002x
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&)
:226
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&)
:226
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&&)
:226
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&)
:226
8060x
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&)
:226
30296x
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&&)
:226
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&&)
:226
34879x
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&)
:226
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&)
:226
9368x
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&)
:226
2039817x
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&)
:226
5815x
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&)
:226
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>&&)
:236
38150x
100.0%
–
100.0%
char const* boost::json::detail::access::release_key<boost::json::value>(boost::json::value&, unsigned long&)
:248
38150x
100.0%
–
83.0%
unsigned int& boost::json::detail::access::next<boost::json::key_value_pair>(boost::json::key_value_pair&)
:262
10454x
100.0%
–
100.0%
boost::json::detail::scalar& boost::json::detail::access::get_scalar<boost::json::value>(boost::json::value&)
:278
12x
100.0%
–
100.0%
boost::json::detail::scalar const& boost::json::detail::access::get_scalar<boost::json::value>(boost::json::value const&)
:286
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 | #if 0 | ||
| 30 | template<class T> | ||
| 31 | struct to_number_limit | ||
| 32 | : std::numeric_limits<T> | ||
| 33 | { | ||
| 34 | }; | ||
| 35 | |||
| 36 | template<class T> | ||
| 37 | struct to_number_limit<T const> | ||
| 38 | : to_number_limit<T> | ||
| 39 | { | ||
| 40 | }; | ||
| 41 | |||
| 42 | template<> | ||
| 43 | struct to_number_limit<long long> | ||
| 44 | { | ||
| 45 | static constexpr long long (min)() noexcept | ||
| 46 | { | ||
| 47 | return -9223372036854774784; | ||
| 48 | } | ||
| 49 | |||
| 50 | static constexpr long long (max)() noexcept | ||
| 51 | { | ||
| 52 | return 9223372036854774784; | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | |||
| 56 | template<> | ||
| 57 | struct to_number_limit<unsigned long long> | ||
| 58 | { | ||
| 59 | static constexpr | ||
| 60 | unsigned long long (min)() noexcept | ||
| 61 | { | ||
| 62 | return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | static constexpr | ||
| 66 | unsigned long long (max)() noexcept | ||
| 67 | { | ||
| 68 | return 18446744073709549568ULL; | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | #else | ||
| 72 | |||
| 73 | template<class T> | ||
| 74 | class to_number_limit | ||
| 75 | { | ||
| 76 | // unsigned | ||
| 77 | |||
| 78 | static constexpr | ||
| 79 | double min1(std::false_type) | ||
| 80 | { | ||
| 81 | return 0.0; | ||
| 82 | } | ||
| 83 | |||
| 84 | static constexpr | ||
| 85 | 8x | double max1(std::false_type) | |
| 86 | { | ||
| 87 | 8x | return max2u(std::integral_constant< | |
| 88 | bool, (std::numeric_limits<T>::max)() == | ||
| 89 | 8x | UINT64_MAX>{}); | |
| 90 | } | ||
| 91 | |||
| 92 | static constexpr | ||
| 93 | 6x | double max2u(std::false_type) | |
| 94 | { | ||
| 95 | return static_cast<double>( | ||
| 96 | 6x | (std::numeric_limits<T>::max)()); | |
| 97 | } | ||
| 98 | |||
| 99 | static constexpr | ||
| 100 | 2x | double max2u(std::true_type) | |
| 101 | { | ||
| 102 | 2x | return 18446744073709549568.0; | |
| 103 | } | ||
| 104 | |||
| 105 | // signed | ||
| 106 | |||
| 107 | static constexpr | ||
| 108 | 20x | double min1(std::true_type) | |
| 109 | { | ||
| 110 | 20x | return min2s(std::integral_constant< | |
| 111 | bool, (std::numeric_limits<T>::max)() == | ||
| 112 | 20x | INT64_MAX>{}); | |
| 113 | } | ||
| 114 | |||
| 115 | static constexpr | ||
| 116 | 17x | double min2s(std::false_type) | |
| 117 | { | ||
| 118 | return static_cast<double>( | ||
| 119 | 17x | (std::numeric_limits<T>::min)()); | |
| 120 | } | ||
| 121 | |||
| 122 | static constexpr | ||
| 123 | 3x | double min2s(std::true_type) | |
| 124 | { | ||
| 125 | 3x | return -9223372036854774784.0; | |
| 126 | } | ||
| 127 | |||
| 128 | static constexpr | ||
| 129 | 20x | double max1(std::true_type) | |
| 130 | { | ||
| 131 | 20x | return max2s(std::integral_constant< | |
| 132 | bool, (std::numeric_limits<T>::max)() == | ||
| 133 | 20x | INT64_MAX>{}); | |
| 134 | } | ||
| 135 | |||
| 136 | static constexpr | ||
| 137 | 17x | double max2s(std::false_type) | |
| 138 | { | ||
| 139 | return static_cast<double>( | ||
| 140 | 17x | (std::numeric_limits<T>::max)()); | |
| 141 | } | ||
| 142 | |||
| 143 | static constexpr | ||
| 144 | 3x | double max2s(std::true_type) | |
| 145 | { | ||
| 146 | 3x | return 9223372036854774784.0; | |
| 147 | } | ||
| 148 | |||
| 149 | public: | ||
| 150 | static constexpr | ||
| 151 | 20x | double (min)() noexcept | |
| 152 | { | ||
| 153 | 20x | return min1(std::is_signed<T>{}); | |
| 154 | } | ||
| 155 | |||
| 156 | static constexpr | ||
| 157 | 28x | double (max)() noexcept | |
| 158 | { | ||
| 159 | 28x | return max1(std::is_signed<T>{}); | |
| 160 | } | ||
| 161 | }; | ||
| 162 | |||
| 163 | #endif | ||
| 164 | |||
| 165 | struct scalar | ||
| 166 | { | ||
| 167 | storage_ptr sp; // must come first | ||
| 168 | kind k; // must come second | ||
| 169 | union | ||
| 170 | { | ||
| 171 | bool b; | ||
| 172 | std::int64_t i; | ||
| 173 | std::uint64_t u; | ||
| 174 | double d; | ||
| 175 | }; | ||
| 176 | |||
| 177 | explicit | ||
| 178 | 2152100x | scalar(storage_ptr sp_ = {}) noexcept | |
| 179 | 2152100x | : sp(std::move(sp_)) | |
| 180 | 2152100x | , k(json::kind::null) | |
| 181 | { | ||
| 182 | 2152100x | } | |
| 183 | |||
| 184 | explicit | ||
| 185 | 1088x | scalar(bool b_, | |
| 186 | storage_ptr sp_ = {}) noexcept | ||
| 187 | 1088x | : sp(std::move(sp_)) | |
| 188 | 1088x | , k(json::kind::bool_) | |
| 189 | 1088x | , b(b_) | |
| 190 | { | ||
| 191 | 1088x | } | |
| 192 | |||
| 193 | explicit | ||
| 194 | 34593x | scalar(std::int64_t i_, | |
| 195 | storage_ptr sp_ = {}) noexcept | ||
| 196 | 34593x | : sp(std::move(sp_)) | |
| 197 | 34593x | , k(json::kind::int64) | |
| 198 | 34593x | , i(i_) | |
| 199 | { | ||
| 200 | 34593x | } | |
| 201 | |||
| 202 | explicit | ||
| 203 | 406x | scalar(std::uint64_t u_, | |
| 204 | storage_ptr sp_ = {}) noexcept | ||
| 205 | 406x | : sp(std::move(sp_)) | |
| 206 | 406x | , k(json::kind::uint64) | |
| 207 | 406x | , u(u_) | |
| 208 | { | ||
| 209 | 406x | } | |
| 210 | |||
| 211 | explicit | ||
| 212 | 2040002x | scalar(double d_, | |
| 213 | storage_ptr sp_ = {}) noexcept | ||
| 214 | 2040002x | : sp(std::move(sp_)) | |
| 215 | 2040002x | , k(json::kind::double_) | |
| 216 | 2040002x | , d(d_) | |
| 217 | { | ||
| 218 | 2040002x | } | |
| 219 | }; | ||
| 220 | |||
| 221 | struct access | ||
| 222 | { | ||
| 223 | template<class Value, class... Args> | ||
| 224 | static | ||
| 225 | Value& | ||
| 226 | 2156934x | construct_value(Value* p, Args&&... args) | |
| 227 | { | ||
| 228 | return *reinterpret_cast< | ||
| 229 | 6396945x | Value*>(::new(p) Value( | |
| 230 | 6489244x | std::forward<Args>(args)...)); | |
| 231 | } | ||
| 232 | |||
| 233 | template<class KeyValuePair, class... Args> | ||
| 234 | static | ||
| 235 | KeyValuePair& | ||
| 236 | 38150x | construct_key_value_pair( | |
| 237 | KeyValuePair* p, Args&&... args) | ||
| 238 | { | ||
| 239 | return *reinterpret_cast< | ||
| 240 | 38150x | KeyValuePair*>(::new(p) | |
| 241 | KeyValuePair( | ||
| 242 | 76300x | std::forward<Args>(args)...)); | |
| 243 | } | ||
| 244 | |||
| 245 | template<class Value> | ||
| 246 | static | ||
| 247 | char const* | ||
| 248 | 38150x | release_key( | |
| 249 | Value& jv, | ||
| 250 | std::size_t& len) noexcept | ||
| 251 | { | ||
| 252 | 38150x | BOOST_ASSERT(jv.is_string()); | |
| 253 | 38150x | jv.str_.sp_.~storage_ptr(); | |
| 254 | 38150x | return jv.str_.impl_.release_key(len); | |
| 255 | } | ||
| 256 | |||
| 257 | using index_t = std::uint32_t; | ||
| 258 | |||
| 259 | template<class KeyValuePair> | ||
| 260 | static | ||
| 261 | index_t& | ||
| 262 | 10454x | next(KeyValuePair& e) noexcept | |
| 263 | { | ||
| 264 | 10454x | return e.next_; | |
| 265 | } | ||
| 266 | |||
| 267 | template<class KeyValuePair> | ||
| 268 | static | ||
| 269 | index_t const& | ||
| 270 | next(KeyValuePair const& e) noexcept | ||
| 271 | { | ||
| 272 | return e.next_; | ||
| 273 | } | ||
| 274 | |||
| 275 | template<class Value> | ||
| 276 | static | ||
| 277 | auto | ||
| 278 | 12x | get_scalar(Value& jv) -> scalar& | |
| 279 | { | ||
| 280 | 12x | return jv.sca_; | |
| 281 | } | ||
| 282 | |||
| 283 | template<class Value> | ||
| 284 | static | ||
| 285 | auto | ||
| 286 | 264x | get_scalar(Value const& jv) -> scalar const& | |
| 287 | { | ||
| 288 | 264x | return jv.sca_; | |
| 289 | } | ||
| 290 | }; | ||
| 291 | |||
| 292 | BOOST_JSON_DECL | ||
| 293 | std::size_t | ||
| 294 | hash_value_impl( value const& jv ) noexcept; | ||
| 295 | |||
| 296 | } // detail | ||
| 297 | } // namespace json | ||
| 298 | } // namespace boost | ||
| 299 | |||
| 300 | #endif | ||
| 301 |