-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpolystore.cpp
More file actions
137 lines (120 loc) · 2.36 KB
/
Copy pathpolystore.cpp
File metadata and controls
137 lines (120 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// Copyright (c) 2025 Vinnie Falco ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/http
//
#include <boost/http/core/polystore.hpp>
#include <utility>
namespace boost {
namespace http {
polystore::
~polystore()
{
destroy();
}
polystore::
polystore(
polystore&& other) noexcept
{
using std::swap;
swap(v_, other.v_);
swap(m_, other.m_);
}
polystore&
polystore::
operator=(
polystore&& other) noexcept
{
if(this != &other)
{
using std::swap;
polystore tmp(std::move(*this));
swap(v_, tmp.v_);
swap(m_, tmp.m_);
swap(v_, other.v_);
swap(m_, other.m_);
}
return *this;
}
void
polystore::
clear() noexcept
{
destroy();
m_.clear();
}
auto
polystore::
get_elements() noexcept ->
elements
{
return elements(v_.size(), *this);
}
void
polystore::
destroy() noexcept
{
// destroy in reverse order
for(auto n = v_.size(); n--;)
v_.resize(n);
}
auto
polystore::
get(std::size_t i) -> any&
{
return *v_[i];
}
void*
polystore::
find(
core::typeinfo const& ti) const noexcept
{
auto const it = m_.find(ti);
if(it == m_.end())
return nullptr;
return it->second;
}
void*
polystore::
insert_impl(
any_ptr p, key const* k, std::size_t n)
{
struct do_insert
{
any_ptr p;
key const* k;
std::size_t n;
polystore& ps;
std::size_t i = 0;
do_insert(
any_ptr p_,
key const* k_,
std::size_t n_,
polystore& ps_)
: p(std::move(p_)), k(k_), n(n_), ps(ps_)
{
// ensure emplace_back can't fail
ps.v_.reserve(ps.v_.size() + 1);
for(;i < n;++i)
if(! ps.m_.emplace(k[i].ti, k[i].p).second)
detail::throw_invalid_argument(
"polystore: duplicate key");
ps.v_.emplace_back(std::move(p));
}
~do_insert()
{
if(i == n)
return;
while(i--)
ps.m_.erase(k[i].ti);
}
};
auto const pt = p->get();
do_insert(std::move(p), k, n, *this);
return pt;
}
} // http
} // boost