CCF
Loading...
Searching...
No Matches
map.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/kv/get_name.h"
6#include "ccf/kv/hooks.h"
7#include "ccf/kv/map_diff.h"
8#include "ccf/kv/map_handle.h"
11#include "ccf/kv/untyped.h"
12
13namespace ccf::kv
14{
28 template <typename K, typename V, typename KSerialiser, typename VSerialiser>
29 class TypedMap : public GetName
30 {
31 public:
32 // Expose correct public aliases of types
39
40 using Write = std::map<K, std::optional<V>>;
43
44 using Key = K;
45 using Value = V;
46 using KeySerialiser = KSerialiser;
47 using ValueSerialiser = VSerialiser;
48
49 using GetName::GetName;
50
51 private:
52 static Write deserialise_write(const ccf::kv::untyped::Write& w)
53 {
54 Write typed_writes;
55 for (const auto& [uk, opt_uv] : w)
56 {
57 if (!opt_uv.has_value())
58 {
59 // Deletions are indicated by nullopt. We cannot deserialise them,
60 // they are deletions here as well
61 typed_writes[KSerialiser::from_serialised(uk)] = std::nullopt;
62 }
63 else
64 {
65 typed_writes[KSerialiser::from_serialised(uk)] =
66 VSerialiser::from_serialised(opt_uv.value());
67 }
68 }
69 return typed_writes;
70 }
71
72 public:
74 {
75 return [hook](Version v, const ccf::kv::untyped::Write& w) {
76 hook(v, deserialise_write(w));
77 };
78 }
79
81 {
82 return [hook](Version v, const ccf::kv::untyped::Write& w) {
83 return hook(v, deserialise_write(w));
84 };
85 }
86 };
87
88 template <
89 typename K,
90 typename V,
91 template <typename>
92 typename KSerialiser,
93 template <typename> typename VSerialiser = KSerialiser>
95
96 template <typename K, typename V>
99
100 template <typename K, typename V>
102 K,
103 V,
106
110 template <typename K, typename V>
112}
Definition map_diff.h:11
Definition map_handle.h:268
Definition map_handle.h:13
Definition map.h:30
MapHook< Write > MapHook
Definition map.h:42
K Key
Definition map.h:44
std::map< K, std::optional< V > > Write
Definition map.h:40
KSerialiser KeySerialiser
Definition map.h:46
V Value
Definition map.h:45
VSerialiser ValueSerialiser
Definition map.h:47
static ccf::kv::untyped::CommitHook wrap_commit_hook(const CommitHook &hook)
Definition map.h:73
CommitHook< Write > CommitHook
Definition map.h:41
static ccf::kv::untyped::MapHook wrap_map_hook(const MapHook &hook)
Definition map.h:80
Definition map_handle.h:218
ccf::kv::CommitHook< Write > CommitHook
Definition untyped.h:18
std::map< ccf::kv::serialisers::SerialisedEntry, std::optional< ccf::kv::serialisers::SerialisedEntry > > Write
Definition untyped.h:16
ccf::kv::MapHook< Write > MapHook
Definition untyped.h:19
Definition app_interface.h:19
uint64_t Version
Definition version.h:8
Definition get_name.h:10
GetName(const std::string &s)
Definition get_name.h:15
Definition blit_serialiser.h:14