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_STRUCT_H
6 : : #define MP_PROXY_TYPE_STRUCT_H
7 : :
8 : : #include <mp/util.h>
9 : :
10 : : namespace mp {
11 : : template <size_t index, typename LocalType, typename Value, typename Output>
12 : 0 : void BuildOne(TypeList<LocalType> param,
13 : : InvokeContext& invoke_context,
14 : : Output&& output,
15 : : Value&& value,
16 : : typename std::enable_if < index<ProxyType<LocalType>::fields>::type * enable = nullptr)
17 : : {
18 : : using Index = std::integral_constant<size_t, index>;
19 : : using Struct = typename ProxyType<LocalType>::Struct;
20 : : using Accessor = typename std::tuple_element<index, typename ProxyStruct<Struct>::Accessors>::type;
21 : 0 : auto&& field_output = Make<StructField, Accessor>(output);
22 : 0 : auto&& field_value = value.*ProxyType<LocalType>::get(Index());
23 : 0 : BuildField(TypeList<Decay<decltype(field_value)>>(), invoke_context, field_output, field_value);
24 : 0 : BuildOne<index + 1>(param, invoke_context, output, value);
25 : 0 : }
26 : :
27 : : template <size_t index, typename LocalType, typename Value, typename Output>
28 : : void BuildOne(TypeList<LocalType> param,
29 : : InvokeContext& invoke_context,
30 : : Output&& output,
31 : : Value&& value,
32 : : typename std::enable_if<index == ProxyType<LocalType>::fields>::type* enable = nullptr)
33 : : {
34 : : }
35 : :
36 : : template <typename LocalType, typename Value, typename Output>
37 : 0 : void CustomBuildField(TypeList<LocalType> local_type,
38 : : Priority<1>,
39 : : InvokeContext& invoke_context,
40 : : Value&& value,
41 : : Output&& output,
42 : : typename ProxyType<LocalType>::Struct* enable = nullptr)
43 : : {
44 : 0 : BuildOne<0>(local_type, invoke_context, output.init(), value);
45 : 0 : }
46 : :
47 : : template <size_t index, typename LocalType, typename Input, typename Value>
48 : 0 : void ReadOne(TypeList<LocalType> param,
49 : : InvokeContext& invoke_context,
50 : : Input&& input,
51 : : Value&& value,
52 : : typename std::enable_if<index != ProxyType<LocalType>::fields>::type* enable = nullptr)
53 : : {
54 : : using Index = std::integral_constant<size_t, index>;
55 : : using Struct = typename ProxyType<LocalType>::Struct;
56 : : using Accessor = typename std::tuple_element<index, typename ProxyStruct<Struct>::Accessors>::type;
57 : 0 : const auto& struc = input.get();
58 : 0 : auto&& field_value = value.*ProxyType<LocalType>::get(Index());
59 : 0 : ReadField(TypeList<RemoveCvRef<decltype(field_value)>>(), invoke_context, Make<StructField, Accessor>(struc),
60 : 0 : ReadDestUpdate(field_value));
61 : 0 : ReadOne<index + 1>(param, invoke_context, input, value);
62 : 0 : }
63 : :
64 : : template <size_t index, typename LocalType, typename Input, typename Value>
65 : : void ReadOne(TypeList<LocalType> param,
66 : : InvokeContext& invoke_context,
67 : : Input& input,
68 : : Value& value,
69 : : typename std::enable_if<index == ProxyType<LocalType>::fields>::type* enable = nullptr)
70 : : {
71 : : }
72 : :
73 : : template <typename LocalType, typename Input, typename ReadDest>
74 : 0 : decltype(auto) CustomReadField(TypeList<LocalType> param,
75 : : Priority<1>,
76 : : InvokeContext& invoke_context,
77 : : Input&& input,
78 : : ReadDest&& read_dest,
79 : : typename ProxyType<LocalType>::Struct* enable = nullptr)
80 : : {
81 [ # # ]: 0 : return read_dest.update([&](auto& value) { ReadOne<0>(param, invoke_context, input, value); });
82 : : }
83 : : } // namespace mp
84 : :
85 : : #endif // MP_PROXY_TYPE_STRUCT_H
|