60.38% Lines (32/53) 63.64% Functions (7/11)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2025 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/cppalliance/http 7   // Official repository: https://github.com/cppalliance/http
8   // 8   //
9   9  
10   #include <boost/http/core/polystore.hpp> 10   #include <boost/http/core/polystore.hpp>
11   #include <utility> 11   #include <utility>
12   12  
13   namespace boost { 13   namespace boost {
14   namespace http { 14   namespace http {
15   15  
HITCBC 16   234 polystore:: 16   234 polystore::
17   ~polystore() 17   ~polystore()
18   { 18   {
HITCBC 19   234 destroy(); 19   234 destroy();
HITCBC 20   234 } 20   234 }
21   21  
MISUBC 22   polystore:: 22   polystore::
23   polystore( 23   polystore(
MISUBC 24   polystore&& other) noexcept 24   polystore&& other) noexcept
25   { 25   {
26   using std::swap; 26   using std::swap;
MISUBC 27   swap(v_, other.v_); 27   swap(v_, other.v_);
MISUBC 28   swap(m_, other.m_); 28   swap(m_, other.m_);
MISUBC 29   } 29   }
30   30  
31   polystore& 31   polystore&
MISUBC 32   polystore:: 32   polystore::
33   operator=( 33   operator=(
34   polystore&& other) noexcept 34   polystore&& other) noexcept
35   { 35   {
MISUBC 36   if(this != &other) 36   if(this != &other)
37   { 37   {
38   using std::swap; 38   using std::swap;
MISUBC 39   polystore tmp(std::move(*this)); 39   polystore tmp(std::move(*this));
MISUBC 40   swap(v_, tmp.v_); 40   swap(v_, tmp.v_);
MISUBC 41   swap(m_, tmp.m_); 41   swap(m_, tmp.m_);
MISUBC 42   swap(v_, other.v_); 42   swap(v_, other.v_);
MISUBC 43   swap(m_, other.m_); 43   swap(m_, other.m_);
MISUBC 44   } 44   }
MISUBC 45   return *this; 45   return *this;
46   } 46   }
47   47  
48   void 48   void
HITCBC 49   4 polystore:: 49   4 polystore::
50   clear() noexcept 50   clear() noexcept
51   { 51   {
HITCBC 52   4 destroy(); 52   4 destroy();
HITCBC 53   4 m_.clear(); 53   4 m_.clear();
HITCBC 54   4 } 54   4 }
55   55  
56   auto 56   auto
MISUBC 57   polystore:: 57   polystore::
58   get_elements() noexcept -> 58   get_elements() noexcept ->
59   elements 59   elements
60   { 60   {
MISUBC 61   return elements(v_.size(), *this); 61   return elements(v_.size(), *this);
62   } 62   }
63   63  
64   void 64   void
HITCBC 65   238 polystore:: 65   238 polystore::
66   destroy() noexcept 66   destroy() noexcept
67   { 67   {
68   // destroy in reverse order 68   // destroy in reverse order
HITCBC 69   252 for(auto n = v_.size(); n--;) 69   252 for(auto n = v_.size(); n--;)
HITCBC 70   14 v_.resize(n); 70   14 v_.resize(n);
HITCBC 71   238 } 71   238 }
72   72  
73   auto 73   auto
MISUBC 74   polystore:: 74   polystore::
75   get(std::size_t i) -> any& 75   get(std::size_t i) -> any&
76   { 76   {
MISUBC 77   return *v_[i]; 77   return *v_[i];
78   } 78   }
79   79  
80   void* 80   void*
HITCBC 81   69 polystore:: 81   69 polystore::
82   find( 82   find(
83   core::typeinfo const& ti) const noexcept 83   core::typeinfo const& ti) const noexcept
84   { 84   {
HITCBC 85   69 auto const it = m_.find(ti); 85   69 auto const it = m_.find(ti);
HITCBC 86   69 if(it == m_.end()) 86   69 if(it == m_.end())
HITCBC 87   11 return nullptr; 87   11 return nullptr;
HITCBC 88   58 return it->second; 88   58 return it->second;
89   } 89   }
90   90  
91   void* 91   void*
HITCBC 92   18 polystore:: 92   18 polystore::
93   insert_impl( 93   insert_impl(
94   any_ptr p, key const* k, std::size_t n) 94   any_ptr p, key const* k, std::size_t n)
95   { 95   {
96   struct do_insert 96   struct do_insert
97   { 97   {
98   any_ptr p; 98   any_ptr p;
99   key const* k; 99   key const* k;
100   std::size_t n; 100   std::size_t n;
101   polystore& ps; 101   polystore& ps;
102   std::size_t i = 0; 102   std::size_t i = 0;
103   103  
HITCBC 104   18 do_insert( 104   18 do_insert(
105   any_ptr p_, 105   any_ptr p_,
106   key const* k_, 106   key const* k_,
107   std::size_t n_, 107   std::size_t n_,
108   polystore& ps_) 108   polystore& ps_)
HITCBC 109   18 : p(std::move(p_)), k(k_), n(n_), ps(ps_) 109   18 : p(std::move(p_)), k(k_), n(n_), ps(ps_)
110   { 110   {
111   // ensure emplace_back can't fail 111   // ensure emplace_back can't fail
HITCBC 112   18 ps.v_.reserve(ps.v_.size() + 1); 112   18 ps.v_.reserve(ps.v_.size() + 1);
113   113  
HITCBC 114   37 for(;i < n;++i) 114   37 for(;i < n;++i)
HITCBC 115   23 if(! ps.m_.emplace(k[i].ti, k[i].p).second) 115   23 if(! ps.m_.emplace(k[i].ti, k[i].p).second)
HITCBC 116   4 detail::throw_invalid_argument( 116   4 detail::throw_invalid_argument(
117   "polystore: duplicate key"); 117   "polystore: duplicate key");
118   118  
HITCBC 119   14 ps.v_.emplace_back(std::move(p)); 119   14 ps.v_.emplace_back(std::move(p));
HITCBC 120   18 } 120   18 }
121   121  
HITCBC 122   14 ~do_insert() 122   14 ~do_insert()
MISUBC 123   { 123   {
HITCBC 124   14 if(i == n) 124   14 if(i == n)
HITCBC 125   14 return; 125   14 return;
MISUBC 126   while(i--) 126   while(i--)
MISUBC 127   ps.m_.erase(k[i].ti); 127   ps.m_.erase(k[i].ti);
HITCBC 128   14 } 128   14 }
129   }; 129   };
130   130  
HITCBC 131   18 auto const pt = p->get(); 131   18 auto const pt = p->get();
HITCBC 132   22 do_insert(std::move(p), k, n, *this); 132   22 do_insert(std::move(p), k, n, *this);
HITCBC 133   14 return pt; 133   14 return pt;
134   } 134   }
135   135  
136   } // http 136   } // http
137   } // boost 137   } // boost