Bitcoin Core  31.0.0
P2P Digital Currency
type-struct.h
Go to the documentation of this file.
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>
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  auto&& field_output = Make<StructField, Accessor>(output);
22  auto&& field_value = value.*ProxyType<LocalType>::get(Index());
23  BuildField(TypeList<Decay<decltype(field_value)>>(), invoke_context, field_output, field_value);
24  BuildOne<index + 1>(param, invoke_context, output, value);
25 }
26 
27 template <size_t index, typename LocalType, typename Value, typename Output>
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>
39  InvokeContext& invoke_context,
40  Value&& value,
41  Output&& output,
42  typename ProxyType<LocalType>::Struct* enable = nullptr)
43 {
44  BuildOne<0>(local_type, invoke_context, output.init(), value);
45 }
46 
47 template <size_t index, typename LocalType, typename Input, typename Value>
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  const auto& struc = input.get();
58  auto&& field_value = value.*ProxyType<LocalType>::get(Index());
59  ReadField(TypeList<RemoveCvRef<decltype(field_value)>>(), invoke_context, Make<StructField, Accessor>(struc),
60  ReadDestUpdate(field_value));
61  ReadOne<index + 1>(param, invoke_context, input, value);
62 }
63 
64 template <size_t index, typename LocalType, typename Input, typename Value>
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 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  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
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous...
Definition: util.h:108
std::remove_cv_t< std::remove_reference_t< T > > RemoveCvRef
Substitutue for std::remove_cvref_t.
Definition: util.h:82
Accessor type holding flags that determine how to access a message field.
Definition: proxy.h:315
Generic utility functions used by capnp code.
Definition: util.h:32
Destination parameter type that can be passed to ReadField function as an alternative to ReadDestEmpl...
Definition: proxy-types.h:145
void ReadOne(TypeList< LocalType > param, InvokeContext &invoke_context, Input &&input, Value &&value, typename std::enable_if< index !=ProxyType< LocalType >::fields >::type *enable=nullptr)
Definition: type-struct.h:48
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
Mapping from local c++ type to capnp type and traits (specializations are generated by proxy-codegen...
Definition: proxy.h:34
void BuildField(TypeList< LocalTypes... >, Context &context, Output &&output, Values &&... values)
Definition: proxy-types.h:250
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest) requires Unserializable< LocalType
Overload multiprocess library&#39;s CustomReadField hook to allow any object with an Unserialize method t...
Definition: common-types.h:100
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output) requires Serializable< LocalType
Overload multiprocess library&#39;s CustomBuildField hook to allow any serializable object to be stored i...
std::decay_t< T > Decay
Type helper abbreviating std::decay.
Definition: util.h:86
decltype(auto) ReadField(TypeList< LocalTypes... >, InvokeContext &invoke_context, Input &&input, Args &&... args)
Definition: proxy-types.h:213
void BuildOne(TypeList< LocalType > param, InvokeContext &invoke_context, Output &&output, Value &&value, typename std::enable_if< index< ProxyType< LocalType >::fields >::type *enable=nullptr)
Definition: type-struct.h:12