96.00% Lines (72/75)
90.91% Functions (10/11)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // | 3 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 6 | // | 6 | // | |||||
| 7 | // Official repository: https://github.com/boostorg/json | 7 | // Official repository: https://github.com/boostorg/json | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #ifndef BOOST_JSON_IMPL_VALUE_REF_IPP | 10 | #ifndef BOOST_JSON_IMPL_VALUE_REF_IPP | |||||
| 11 | #define BOOST_JSON_IMPL_VALUE_REF_IPP | 11 | #define BOOST_JSON_IMPL_VALUE_REF_IPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/json/value_ref.hpp> | 13 | #include <boost/json/value_ref.hpp> | |||||
| 14 | #include <boost/json/array.hpp> | 14 | #include <boost/json/array.hpp> | |||||
| 15 | #include <boost/json/value.hpp> | 15 | #include <boost/json/value.hpp> | |||||
| 16 | 16 | |||||||
| 17 | namespace boost { | 17 | namespace boost { | |||||
| 18 | namespace json { | 18 | namespace json { | |||||
| 19 | 19 | |||||||
| HITCBC | 20 | 3236 | value_ref:: | 20 | 3236 | value_ref:: | ||
| 21 | operator | 21 | operator | |||||
| 22 | value() const | 22 | value() const | |||||
| 23 | { | 23 | { | |||||
| HITCBC | 24 | 3236 | return make_value({}); | 24 | 3236 | return make_value({}); | ||
| 25 | } | 25 | } | |||||
| 26 | 26 | |||||||
| 27 | value | 27 | value | |||||
| MISUBC | 28 | ✗ | value_ref:: | 28 | ✗ | value_ref:: | ||
| 29 | from_init_list( | 29 | from_init_list( | |||||
| 30 | void const* p, | 30 | void const* p, | |||||
| 31 | storage_ptr sp) | 31 | storage_ptr sp) | |||||
| 32 | { | 32 | { | |||||
| 33 | return make_value( | 33 | return make_value( | |||||
| 34 | *reinterpret_cast< | 34 | *reinterpret_cast< | |||||
| 35 | init_list const*>(p), | 35 | init_list const*>(p), | |||||
| MISUBC | 36 | ✗ | std::move(sp)); | 36 | ✗ | std::move(sp)); | ||
| 37 | } | 37 | } | |||||
| 38 | 38 | |||||||
| 39 | bool | 39 | bool | |||||
| HITCBC | 40 | 855 | value_ref:: | 40 | 855 | value_ref:: | ||
| 41 | is_key_value_pair() const noexcept | 41 | is_key_value_pair() const noexcept | |||||
| 42 | { | 42 | { | |||||
| HITCBC | 43 | 855 | if(what_ != what::ini) | 43 | 855 | if(what_ != what::ini) | ||
| HITCBC | 44 | 347 | return false; | 44 | 347 | return false; | ||
| HITCBC | 45 | 508 | if(arg_.init_list_.size() != 2) | 45 | 508 | if(arg_.init_list_.size() != 2) | ||
| HITCBC | 46 | 5 | return false; | 46 | 5 | return false; | ||
| 47 | auto const& e = | 47 | auto const& e = | |||||
| HITCBC | 48 | 503 | *arg_.init_list_.begin(); | 48 | 503 | *arg_.init_list_.begin(); | ||
| HITCBC | 49 | 503 | if( e.what_ != what::str && | 49 | 503 | if( e.what_ != what::str && | ||
| HITCBC | 50 | 25 | e.what_ != what::strfunc) | 50 | 25 | e.what_ != what::strfunc) | ||
| HITCBC | 51 | 23 | return false; | 51 | 23 | return false; | ||
| HITCBC | 52 | 480 | return true; | 52 | 480 | return true; | ||
| 53 | } | 53 | } | |||||
| 54 | 54 | |||||||
| 55 | bool | 55 | bool | |||||
| HITCBC | 56 | 508 | value_ref:: | 56 | 508 | value_ref:: | ||
| 57 | maybe_object( | 57 | maybe_object( | |||||
| 58 | std::initializer_list< | 58 | std::initializer_list< | |||||
| 59 | value_ref> init) noexcept | 59 | value_ref> init) noexcept | |||||
| 60 | { | 60 | { | |||||
| HITCBC | 61 | 988 | for(auto const& e : init) | 61 | 988 | for(auto const& e : init) | ||
| HITCBC | 62 | 855 | if(! e.is_key_value_pair()) | 62 | 855 | if(! e.is_key_value_pair()) | ||
| HITCBC | 63 | 375 | return false; | 63 | 375 | return false; | ||
| HITCBC | 64 | 133 | return true; | 64 | 133 | return true; | ||
| 65 | } | 65 | } | |||||
| 66 | 66 | |||||||
| 67 | string_view | 67 | string_view | |||||
| HITCBC | 68 | 475 | value_ref:: | 68 | 475 | value_ref:: | ||
| 69 | get_string() const noexcept | 69 | get_string() const noexcept | |||||
| 70 | { | 70 | { | |||||
| HITCBC | 71 | 475 | BOOST_ASSERT( | 71 | 475 | BOOST_ASSERT( | ||
| 72 | what_ == what::str || | 72 | what_ == what::str || | |||||
| 73 | what_ == what::strfunc); | 73 | what_ == what::strfunc); | |||||
| HITCBC | 74 | 475 | if (what_ == what::strfunc) | 74 | 475 | if (what_ == what::strfunc) | ||
| HITCBC | 75 | 2 | return *static_cast<const string*>(f_.p); | 75 | 2 | return *static_cast<const string*>(f_.p); | ||
| HITCBC | 76 | 473 | return arg_.str_; | 76 | 473 | return arg_.str_; | ||
| 77 | } | 77 | } | |||||
| 78 | 78 | |||||||
| 79 | value | 79 | value | |||||
| HITCBC | 80 | 9088 | value_ref:: | 80 | 9088 | value_ref:: | ||
| 81 | make_value( | 81 | make_value( | |||||
| 82 | storage_ptr sp) const | 82 | storage_ptr sp) const | |||||
| 83 | { | 83 | { | |||||
| HITCBC | 84 | 9088 | switch(what_) | 84 | 9088 | switch(what_) | ||
| 85 | { | 85 | { | |||||
| HITCBC | 86 | 403 | default: | 86 | 403 | default: | ||
| 87 | case what::str: | 87 | case what::str: | |||||
| HITCBC | 88 | 806 | return string( | 88 | 806 | return string( | ||
| 89 | arg_.str_, | 89 | arg_.str_, | |||||
| HITCBC | 90 | 790 | std::move(sp)); | 90 | 790 | std::move(sp)); | ||
| 91 | 91 | |||||||
| HITCBC | 92 | 170 | case what::ini: | 92 | 170 | case what::ini: | ||
| 93 | return make_value( | 93 | return make_value( | |||||
| 94 | arg_.init_list_, | 94 | arg_.init_list_, | |||||
| HITCBC | 95 | 173 | std::move(sp)); | 95 | 173 | std::move(sp)); | ||
| 96 | 96 | |||||||
| HITCBC | 97 | 61 | case what::func: | 97 | 61 | case what::func: | ||
| HITCBC | 98 | 122 | return f_.f(f_.p, | 98 | 122 | return f_.f(f_.p, | ||
| HITCBC | 99 | 61 | std::move(sp)); | 99 | 61 | std::move(sp)); | ||
| 100 | 100 | |||||||
| HITCBC | 101 | 5 | case what::strfunc: | 101 | 5 | case what::strfunc: | ||
| HITCBC | 102 | 10 | return f_.f(f_.p, | 102 | 10 | return f_.f(f_.p, | ||
| HITCBC | 103 | 5 | std::move(sp)); | 103 | 5 | std::move(sp)); | ||
| 104 | 104 | |||||||
| HITCBC | 105 | 8449 | case what::cfunc: | 105 | 8449 | case what::cfunc: | ||
| HITCBC | 106 | 16898 | return cf_.f(cf_.p, | 106 | 16898 | return cf_.f(cf_.p, | ||
| HITCBC | 107 | 8449 | std::move(sp)); | 107 | 8449 | std::move(sp)); | ||
| 108 | } | 108 | } | |||||
| 109 | } | 109 | } | |||||
| 110 | 110 | |||||||
| 111 | value | 111 | value | |||||
| HITCBC | 112 | 172 | value_ref:: | 112 | 172 | value_ref:: | ||
| 113 | make_value( | 113 | make_value( | |||||
| 114 | std::initializer_list< | 114 | std::initializer_list< | |||||
| 115 | value_ref> init, | 115 | value_ref> init, | |||||
| 116 | storage_ptr sp) | 116 | storage_ptr sp) | |||||
| 117 | { | 117 | { | |||||
| HITCBC | 118 | 172 | if(maybe_object(init)) | 118 | 172 | if(maybe_object(init)) | ||
| HITCBC | 119 | 60 | return make_object( | 119 | 60 | return make_object( | ||
| HITCBC | 120 | 60 | init, std::move(sp)); | 120 | 60 | init, std::move(sp)); | ||
| HITCBC | 121 | 284 | return make_array( | 121 | 284 | return make_array( | ||
| HITCBC | 122 | 281 | init, std::move(sp)); | 122 | 281 | init, std::move(sp)); | ||
| 123 | } | 123 | } | |||||
| 124 | 124 | |||||||
| 125 | object | 125 | object | |||||
| HITCBC | 126 | 133 | value_ref:: | 126 | 133 | value_ref:: | ||
| 127 | make_object( | 127 | make_object( | |||||
| 128 | std::initializer_list<value_ref> init, | 128 | std::initializer_list<value_ref> init, | |||||
| 129 | storage_ptr sp) | 129 | storage_ptr sp) | |||||
| 130 | { | 130 | { | |||||
| HITCBC | 131 | 133 | object obj(std::move(sp)); | 131 | 133 | object obj(std::move(sp)); | ||
| HITCBC | 132 | 133 | obj.reserve(init.size()); | 132 | 133 | obj.reserve(init.size()); | ||
| HITCBC | 133 | 608 | for(auto const& e : init) | 133 | 608 | for(auto const& e : init) | ||
| HITCBC | 134 | 475 | obj.emplace( | 134 | 475 | obj.emplace( | ||
| 135 | e.arg_.init_list_.begin()[0].get_string(), | 135 | e.arg_.init_list_.begin()[0].get_string(), | |||||
| HITCBC | 136 | 950 | e.arg_.init_list_.begin()[1].make_value( | 136 | 950 | e.arg_.init_list_.begin()[1].make_value( | ||
| 137 | obj.storage())); | 137 | obj.storage())); | |||||
| HITCBC | 138 | 133 | return obj; | 138 | 133 | return obj; | ||
| MISUBC | 139 | ✗ | } | 139 | ✗ | } | ||
| 140 | 140 | |||||||
| 141 | array | 141 | array | |||||
| HITCBC | 142 | 362 | value_ref:: | 142 | 362 | value_ref:: | ||
| 143 | make_array( | 143 | make_array( | |||||
| 144 | std::initializer_list< | 144 | std::initializer_list< | |||||
| 145 | value_ref> init, | 145 | value_ref> init, | |||||
| 146 | storage_ptr sp) | 146 | storage_ptr sp) | |||||
| 147 | { | 147 | { | |||||
| HITCBC | 148 | 362 | array arr(std::move(sp)); | 148 | 362 | array arr(std::move(sp)); | ||
| HITCBC | 149 | 362 | arr.reserve(init.size()); | 149 | 362 | arr.reserve(init.size()); | ||
| HITCBC | 150 | 1366 | for(auto const& e : init) | 150 | 1366 | for(auto const& e : init) | ||
| HITCBC | 151 | 1007 | arr.emplace_back( | 151 | 1007 | arr.emplace_back( | ||
| HITCBC | 152 | 2014 | e.make_value( | 152 | 2014 | e.make_value( | ||
| 153 | arr.storage())); | 153 | arr.storage())); | |||||
| HITCBC | 154 | 359 | return arr; | 154 | 359 | return arr; | ||
| HITCBC | 155 | 3 | } | 155 | 3 | } | ||
| 156 | 156 | |||||||
| 157 | void | 157 | void | |||||
| HITCBC | 158 | 217 | value_ref:: | 158 | 217 | value_ref:: | ||
| 159 | write_array( | 159 | write_array( | |||||
| 160 | value* dest, | 160 | value* dest, | |||||
| 161 | std::initializer_list< | 161 | std::initializer_list< | |||||
| 162 | value_ref> init, | 162 | value_ref> init, | |||||
| 163 | storage_ptr const& sp) | 163 | storage_ptr const& sp) | |||||
| 164 | { | 164 | { | |||||
| 165 | struct undo | 165 | struct undo | |||||
| 166 | { | 166 | { | |||||
| 167 | value* const base; | 167 | value* const base; | |||||
| 168 | value* pos; | 168 | value* pos; | |||||
| HITCBC | 169 | 217 | ~undo() | 169 | 217 | ~undo() | ||
| 170 | { | 170 | { | |||||
| HITCBC | 171 | 217 | if(pos) | 171 | 217 | if(pos) | ||
| HITCBC | 172 | 36 | while(pos > base) | 172 | 36 | while(pos > base) | ||
| HITCBC | 173 | 20 | (--pos)->~value(); | 173 | 20 | (--pos)->~value(); | ||
| HITCBC | 174 | 217 | } | 174 | 217 | } | ||
| 175 | }; | 175 | }; | |||||
| HITCBC | 176 | 217 | undo u{dest, dest}; | 176 | 217 | undo u{dest, dest}; | ||
| HITCBC | 177 | 744 | for(auto const& e : init) | 177 | 744 | for(auto const& e : init) | ||
| 178 | { | 178 | { | |||||
| HITCBC | 179 | 16 | ::new(u.pos) value( | 179 | 16 | ::new(u.pos) value( | ||
| HITCBC | 180 | 575 | e.make_value(sp)); | 180 | 575 | e.make_value(sp)); | ||
| HITCBC | 181 | 527 | ++u.pos; | 181 | 527 | ++u.pos; | ||
| 182 | } | 182 | } | |||||
| HITCBC | 183 | 201 | u.pos = nullptr; | 183 | 201 | u.pos = nullptr; | ||
| HITCBC | 184 | 217 | } | 184 | 217 | } | ||
| 185 | 185 | |||||||
| 186 | } // namespace json | 186 | } // namespace json | |||||
| 187 | } // namespace boost | 187 | } // namespace boost | |||||
| 188 | 188 | |||||||
| 189 | #endif | 189 | #endif | |||||