98.63% Lines (72/73) 100.00% Functions (10/10)
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   3241 value_ref:: 20   3241 value_ref::
21   operator 21   operator
22   value() const 22   value() const
23   { 23   {
HITCBC 24   3241 return make_value({}); 24   3241 return make_value({});
25   } 25   }
26 - value  
27 - value_ref::  
DUB 28 - ✗ from_init_list(  
29 - void const* p,  
30 - storage_ptr sp)  
31 - {  
32 - return make_value(  
33 - *reinterpret_cast<  
34 - init_list const*>(p),  
35 - std::move(sp));  
DUB 36 - ✗ }  
37 -  
38   26  
39   bool 27   bool
HITCBC 40   860 value_ref:: 28   860 value_ref::
41   is_key_value_pair() const noexcept 29   is_key_value_pair() const noexcept
42   { 30   {
HITCBC 43   860 if(what_ != what::ini) 31   860 if(what_ != what::ini)
HITCBC 44   351 return false; 32   351 return false;
HITCBC 45   509 if(arg_.init_list_.size() != 2) 33   509 if(arg_.init_list_.size() != 2)
HITCBC 46   6 return false; 34   6 return false;
47   auto const& e = 35   auto const& e =
HITCBC 48   503 *arg_.init_list_.begin(); 36   503 *arg_.init_list_.begin();
HITCBC 49   503 if( e.what_ != what::str && 37   503 if( e.what_ != what::str &&
HITCBC 50   25 e.what_ != what::strfunc) 38   25 e.what_ != what::strfunc)
HITCBC 51   23 return false; 39   23 return false;
HITCBC 52   480 return true; 40   480 return true;
53   } 41   }
54   42  
55   bool 43   bool
HITCBC 56   513 value_ref:: 44   513 value_ref::
57   maybe_object( 45   maybe_object(
58   std::initializer_list< 46   std::initializer_list<
59   value_ref> init) noexcept 47   value_ref> init) noexcept
60   { 48   {
HITCBC 61   993 for(auto const& e : init) 49   993 for(auto const& e : init)
HITCBC 62   860 if(! e.is_key_value_pair()) 50   860 if(! e.is_key_value_pair())
HITCBC 63   380 return false; 51   380 return false;
HITCBC 64   133 return true; 52   133 return true;
65   } 53   }
66   54  
67   string_view 55   string_view
HITCBC 68   475 value_ref:: 56   475 value_ref::
69   get_string() const noexcept 57   get_string() const noexcept
70   { 58   {
HITCBC 71   475 BOOST_ASSERT( 59   475 BOOST_ASSERT(
72   what_ == what::str || 60   what_ == what::str ||
73   what_ == what::strfunc); 61   what_ == what::strfunc);
HITCBC 74   475 if (what_ == what::strfunc) 62   475 if (what_ == what::strfunc)
HITCBC 75   2 return *static_cast<const string*>(f_.p); 63   2 return *static_cast<const string*>(f_.p);
HITCBC 76   473 return arg_.str_; 64   473 return arg_.str_;
77   } 65   }
78   66  
79   value 67   value
HITCBC 80   9159 value_ref:: 68   9159 value_ref::
81   make_value( 69   make_value(
82   storage_ptr sp) const 70   storage_ptr sp) const
83   { 71   {
HITCBC 84   9159 switch(what_) 72   9159 switch(what_)
85   { 73   {
HITCBC 86   417 default: 74   417 default:
87   case what::str: 75   case what::str:
HITCBC 88   834 return string( 76   834 return string(
89   arg_.str_, 77   arg_.str_,
HITCBC 90   817 std::move(sp)); 78   817 std::move(sp));
91   79  
HITCBC 92   172 case what::ini: 80   172 case what::ini:
93   return make_value( 81   return make_value(
94   arg_.init_list_, 82   arg_.init_list_,
HITCBC 95   175 std::move(sp)); 83   175 std::move(sp));
96   84  
HITCBC 97   61 case what::func: 85   61 case what::func:
HITCBC 98   122 return f_.f(f_.p, 86   122 return f_.f(f_.p,
HITCBC 99   61 std::move(sp)); 87   61 std::move(sp));
100 - 88 +
HITCBC 101   5 case what::strfunc: 89   5 case what::strfunc:
HITCBC 102   10 return f_.f(f_.p, 90   10 return f_.f(f_.p,
HITCBC 103   5 std::move(sp)); 91   5 std::move(sp));
104 - 92 +
HITCBC 105   8504 case what::cfunc: 93   8504 case what::cfunc:
HITCBC 106   17008 return cf_.f(cf_.p, 94   17008 return cf_.f(cf_.p,
HITCBC 107   8504 std::move(sp)); 95   8504 std::move(sp));
108   } 96   }
109   } 97   }
110   98  
111   value 99   value
HITCBC 112   174 value_ref:: 100   174 value_ref::
113   make_value( 101   make_value(
114   std::initializer_list< 102   std::initializer_list<
115   value_ref> init, 103   value_ref> init,
116   storage_ptr sp) 104   storage_ptr sp)
117   { 105   {
HITCBC 118   174 if(maybe_object(init)) 106   174 if(maybe_object(init))
HITCBC 119   60 return make_object( 107   60 return make_object(
HITCBC 120   60 init, std::move(sp)); 108   60 init, std::move(sp));
HITCBC 121   288 return make_array( 109   288 return make_array(
HITCBC 122   285 init, std::move(sp)); 110   285 init, std::move(sp));
123   } 111   }
124   112  
125   object 113   object
HITCBC 126   133 value_ref:: 114   133 value_ref::
127   make_object( 115   make_object(
128   std::initializer_list<value_ref> init, 116   std::initializer_list<value_ref> init,
129   storage_ptr sp) 117   storage_ptr sp)
130   { 118   {
HITCBC 131   133 object obj(std::move(sp)); 119   133 object obj(std::move(sp));
HITCBC 132   133 obj.reserve(init.size()); 120   133 obj.reserve(init.size());
HITCBC 133   608 for(auto const& e : init) 121   608 for(auto const& e : init)
HITCBC 134   475 obj.emplace( 122   475 obj.emplace(
135   e.arg_.init_list_.begin()[0].get_string(), 123   e.arg_.init_list_.begin()[0].get_string(),
HITCBC 136   950 e.arg_.init_list_.begin()[1].make_value( 124   950 e.arg_.init_list_.begin()[1].make_value(
137   obj.storage())); 125   obj.storage()));
HITCBC 138   133 return obj; 126   133 return obj;
MISUBC 139   ✗ } 127   ✗ }
140   128  
141   array 129   array
HITCBC 142   366 value_ref:: 130   366 value_ref::
143   make_array( 131   make_array(
144   std::initializer_list< 132   std::initializer_list<
145   value_ref> init, 133   value_ref> init,
146   storage_ptr sp) 134   storage_ptr sp)
147   { 135   {
HITCBC 148   366 array arr(std::move(sp)); 136   366 array arr(std::move(sp));
HITCBC 149   366 arr.reserve(init.size()); 137   366 arr.reserve(init.size());
HITCBC 150   1382 for(auto const& e : init) 138   1382 for(auto const& e : init)
HITCBC 151   1019 arr.emplace_back( 139   1019 arr.emplace_back(
HITCBC 152   2038 e.make_value( 140   2038 e.make_value(
153   arr.storage())); 141   arr.storage()));
HITCBC 154   363 return arr; 142   363 return arr;
HITCBC 155   3 } 143   3 }
156   144  
157   void 145   void
HITCBC 158   241 value_ref:: 146   241 value_ref::
159   write_array( 147   write_array(
160   value* dest, 148   value* dest,
161   std::initializer_list< 149   std::initializer_list<
162   value_ref> init, 150   value_ref> init,
163   storage_ptr const& sp) 151   storage_ptr const& sp)
164   { 152   {
165   struct undo 153   struct undo
166   { 154   {
167   value* const base; 155   value* const base;
168   value* pos; 156   value* pos;
HITCBC 169   241 ~undo() 157   241 ~undo()
170   { 158   {
HITCBC 171   241 if(pos) 159   241 if(pos)
HITCBC 172   40 while(pos > base) 160   40 while(pos > base)
HITCBC 173   22 (--pos)->~value(); 161   22 (--pos)->~value();
HITCBC 174   241 } 162   241 }
175   }; 163   };
HITCBC 176   241 undo u{dest, dest}; 164   241 undo u{dest, dest};
HITCBC 177   817 for(auto const& e : init) 165   817 for(auto const& e : init)
178   { 166   {
HITCBC 179   18 ::new(u.pos) value( 167   18 ::new(u.pos) value(
HITCBC 180   630 e.make_value(sp)); 168   630 e.make_value(sp));
HITCBC 181   576 ++u.pos; 169   576 ++u.pos;
182   } 170   }
HITCBC 183   223 u.pos = nullptr; 171   223 u.pos = nullptr;
HITCBC 184   241 } 172   241 }
185   173  
186   } // namespace json 174   } // namespace json
187   } // namespace boost 175   } // namespace boost
188   176  
189   #endif 177   #endif