-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathbase_collections_input_map.h
111 lines (89 loc) · 3.06 KB
/
base_collections_input_map.h
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
namespace winrt::impl
{
template <typename K, typename V, typename Container, typename ThreadingBase>
struct map_impl :
implements<map_impl<K, V, Container, ThreadingBase>, wfc::IMap<K, V>, wfc::IMapView<K, V>, wfc::IIterable<wfc::IKeyValuePair<K, V>>>,
map_base<map_impl<K, V, Container, ThreadingBase>, K, V>,
ThreadingBase
{
static_assert(std::is_same_v<Container, std::remove_reference_t<Container>>, "Must be constructed with rvalue.");
explicit map_impl(Container&& values) : m_values(std::forward<Container>(values))
{
}
auto& get_container() noexcept
{
return m_values;
}
auto& get_container() const noexcept
{
return m_values;
}
using ThreadingBase::acquire_shared;
using ThreadingBase::acquire_exclusive;
private:
Container m_values;
};
template <typename K, typename V, typename Container>
using input_map = map_impl<K, V, Container, single_threaded_collection_base>;
template <typename K, typename V, typename Container>
auto make_input_map(Container&& values)
{
return make<input_map<K, V, Container>>(std::forward<Container>(values));
}
}
WINRT_EXPORT namespace winrt::param
{
template <typename K, typename V>
struct map
{
using value_type = Windows::Foundation::Collections::IKeyValuePair<K, V>;
using interface_type = Windows::Foundation::Collections::IMap<K, V>;
map(std::nullptr_t) noexcept
{
}
map(map const& values) = delete;
map& operator=(map const& values) = delete;
map(interface_type const& values) noexcept : m_owned(false)
{
attach_abi(m_interface, winrt::get_abi(values));
}
template <typename Collection, std::enable_if_t<std::is_convertible_v<Collection, interface_type>, int> = 0>
map(Collection const& values) noexcept
{
m_interface = values;
}
template <typename Compare, typename Allocator>
map(std::map<K, V, Compare, Allocator>&& values) :
m_interface(impl::make_input_map<K, V>(std::move(values)))
{
}
template <typename Hash, typename KeyEqual, typename Allocator>
map(std::unordered_map<K, V, Hash, KeyEqual, Allocator>&& values) :
m_interface(impl::make_input_map<K, V>(std::move(values)))
{
}
map(std::initializer_list<std::pair<K const, V>> values) :
m_interface(impl::make_input_map<K, V>(std::map<K, V>(values)))
{
}
~map() noexcept
{
if (!m_owned)
{
detach_abi(m_interface);
}
}
operator interface_type const& () const noexcept
{
return m_interface;
}
private:
interface_type m_interface;
bool m_owned{ true };
};
template <typename K, typename V>
auto get_abi(map<K, V> const& object) noexcept
{
return *(void**)(&object);
}
}