Branch data Line data Source code
1 : : // Copyright (c) The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #ifndef MP_PROXY_TYPE_MAP_H
6 : : #define MP_PROXY_TYPE_MAP_H
7 : :
8 : : #include <mp/proxy-types.h>
9 : : #include <mp/type-pair.h>
10 : : #include <mp/util.h>
11 : :
12 : : namespace mp {
13 : : template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
14 : 0 : void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
15 : : Priority<1>,
16 : : InvokeContext& invoke_context,
17 : : Value&& value,
18 : : Output&& output)
19 : : {
20 : : // FIXME dededup with vector handler above
21 : 0 : auto list = output.init(value.size());
22 : 0 : size_t i = 0;
23 [ # # ]: 0 : for (const auto& elem : value) {
24 : 0 : BuildField(TypeList<std::pair<KeyLocalType, ValueLocalType>>(), invoke_context,
25 : 0 : ListOutput<typename decltype(list)::Builds>(list, i), elem);
26 : 0 : ++i;
27 : : }
28 : 0 : }
29 : :
30 : : template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
31 : 0 : decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
32 : : Priority<1>,
33 : : InvokeContext& invoke_context,
34 : : Input&& input,
35 : : ReadDest&& read_dest)
36 : : {
37 : 0 : return read_dest.update([&](auto& value) {
38 : 0 : auto data = input.get();
39 : 0 : value.clear();
40 [ # # ]: 0 : for (auto item : data) {
41 : 0 : ReadField(TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), invoke_context,
42 : 0 : Make<ValueField>(item),
43 : 0 : ReadDestEmplace(
44 : 0 : TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), [&](auto&&... args) -> auto& {
45 : 0 : return *value.emplace(std::forward<decltype(args)>(args)...).first;
46 : : }));
47 : : }
48 : 0 : });
49 : : }
50 : : } // namespace mp
51 : :
52 : : #endif // MP_PROXY_TYPE_MAP_H
|