Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
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
10namespace mp {
11template <typename LocalType, typename Value, typename Output>
12void CustomBuildField(TypeList<std::optional<LocalType>>,
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
24template <typename LocalType, typename Input, typename ReadDest>
25decltype(auto) CustomReadField(TypeList<std::optional<LocalType>>,
28 Input&& input,
30{
31 return read_dest.update([&](auto& value) {
33 value.reset();
34 } else if (value) {
36 } else {
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
ArgsManager & args
Definition bitcoind.cpp:277
Functions to serialize / deserialize common bitcoin types.
bool CustomHasField(TypeList< LocalTypes... >, InvokeContext &invoke_context, const Input &input)
Return whether to read a C++ value from a Cap'n Proto field.
void BuildField(TypeList< LocalTypes... >, Context &context, Output &&output, Values &&... values)
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Overload multiprocess library's CustomReadField hook to allow any object with an Unserialize method t...
decltype(auto) ReadField(TypeList< LocalTypes... >, InvokeContext &invoke_context, Input &&input, Args &&... args)
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Overload multiprocess library's CustomBuildField hook to allow any serializable object to be stored i...
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous.
Definition util.h:109
Destination parameter type that can be passed to ReadField function as an alternative to ReadDestEmpl...
Generic utility functions used by capnp code.
Definition util.h:33
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73