Bitcoin Core  31.0.0
P2P Digital Currency
type-vector.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_VECTOR_H
6 #define MP_PROXY_TYPE_VECTOR_H
7 
8 #include <mp/proxy-types.h>
9 #include <mp/util.h>
10 
11 namespace mp {
12 template <typename LocalType, typename Value, typename Output>
13 void CustomBuildField(TypeList<std::vector<LocalType>>,
15  InvokeContext& invoke_context,
16  Value&& value,
17  Output&& output)
18 {
19  // FIXME dedup with set handler below
20  auto list = output.init(value.size());
21  size_t i = 0;
22  for (auto it = value.begin(); it != value.end(); ++it, ++i) {
23  BuildField(TypeList<LocalType>(), invoke_context, ListOutput<typename decltype(list)::Builds>(list, i), *it);
24  }
25 }
26 
27 inline static bool BuildPrimitive(InvokeContext& invoke_context, std::vector<bool>::const_reference value, TypeList<bool>)
28 {
29  return value;
30 }
31 
32 template <typename LocalType, typename Input, typename ReadDest>
33 decltype(auto) CustomReadField(TypeList<std::vector<LocalType>>,
34  Priority<1>,
35  InvokeContext& invoke_context,
36  Input&& input,
37  ReadDest&& read_dest)
38 {
39  return read_dest.update([&](auto& value) {
40  auto data = input.get();
41  value.clear();
42  value.reserve(data.size());
43  for (auto item : data) {
44  ReadField(TypeList<LocalType>(), invoke_context, Make<ValueField>(item),
45  ReadDestEmplace(TypeList<LocalType>(), [&](auto&&... args) -> auto& {
46  value.emplace_back(std::forward<decltype(args)>(args)...);
47  return value.back();
48  }));
49  }
50  });
51 }
52 
53 template <typename Input, typename ReadDest>
54 decltype(auto) CustomReadField(TypeList<std::vector<bool>>,
55  Priority<1>,
56  InvokeContext& invoke_context,
57  Input&& input,
58  ReadDest&& read_dest)
59 {
60  return read_dest.update([&](auto& value) {
61  auto data = input.get();
62  value.clear();
63  value.reserve(data.size());
64  for (auto item : data) {
65  value.push_back(ReadField(TypeList<bool>(), invoke_context, Make<ValueField>(item), ReadDestTemp<bool>()));
66  }
67  });
68 }
69 } // namespace mp
70 
71 #endif // MP_PROXY_TYPE_VECTOR_H
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous...
Definition: util.h:108
Definition: common.h:29
Generic utility functions used by capnp code.
Definition: util.h:32
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
ArgsManager & args
Definition: bitcoind.cpp:277
LocalType BuildPrimitive(InvokeContext &invoke_context, const Value &value, TypeList< LocalType >, typename std::enable_if< std::is_enum< Value >::value >::type *enable=nullptr)
Definition: type-number.h:12
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