Bitcoin Core  31.0.0
P2P Digital Currency
type-optional.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_OPTIONAL_H
6 #define MP_PROXY_TYPE_OPTIONAL_H
7 
8 #include <mp/util.h>
9 
10 namespace mp {
11 template <typename LocalType, typename Value, typename Output>
12 void CustomBuildField(TypeList<std::optional<LocalType>>,
14  InvokeContext& invoke_context,
15  Value&& value,
16  Output&& output)
17 {
18  if (value) {
19  output.setHas();
20  BuildField(TypeList<LocalType>(), invoke_context, output, *std::forward<Value>(value));
21  }
22 }
23 
24 template <typename LocalType, typename Input, typename ReadDest>
25 decltype(auto) CustomReadField(TypeList<std::optional<LocalType>>,
26  Priority<1>,
27  InvokeContext& invoke_context,
28  Input&& input,
29  ReadDest&& read_dest)
30 {
31  return read_dest.update([&](auto& value) {
32  if (!CustomHasField(TypeList<LocalType>(), invoke_context, input)) {
33  value.reset();
34  } else if (value) {
35  ReadField(TypeList<LocalType>(), invoke_context, input, ReadDestUpdate(*value));
36  } else {
37  ReadField(TypeList<LocalType>(), invoke_context, input,
38  ReadDestEmplace(TypeList<LocalType>(), [&](auto&&... args) -> auto& {
39  value.emplace(std::forward<decltype(args)>(args)...);
40  return *value;
41  }));
42  }
43  });
44 }
45 } // namespace mp
46 
47 #endif // MP_PROXY_TYPE_OPTIONAL_H
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous...
Definition: util.h:108
bool CustomHasField(TypeList< LocalTypes... >, InvokeContext &invoke_context, const Input &input)
Return whether to read a C++ value from a Cap&#39;n Proto field.
Definition: proxy-types.h:207
Definition: common.h:29
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
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
ArgsManager & args
Definition: bitcoind.cpp:277
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...
decltype(auto) ReadField(TypeList< LocalTypes... >, InvokeContext &invoke_context, Input &&input, Args &&... args)
Definition: proxy-types.h:213