CCF
Loading...
Searching...
No Matches
set.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"
9#include "ccf/kv/set_handle.h"
10#include "ccf/kv/untyped.h"
11
12namespace ccf::kv
13{
28 template <
29 typename K,
30 typename KSerialiser,
32 class TypedSet : public GetName
33 {
34 public:
38
39 // Note: The type V of the value `std::optional<V>` does not matter here.
40 // The optional type is required to differentiate additions from deletions,
41 // and to provide a consistent interface with the more generic `TypedMap`.
42 using Write =
43 std::map<K, std::optional<ccf::kv::serialisers::SerialisedEntry>>;
46
47 using Key = K;
48 using KeySerialiser = KSerialiser;
49
50 using GetName::GetName;
51
52 private:
53 static Write deserialise_write(const ccf::kv::untyped::Write& w)
54 {
55 Write typed_writes;
56 for (const auto& [uk, opt_uv] : w)
57 {
58 if (!opt_uv.has_value())
59 {
60 // Deletions are indicated by nullopt. We cannot deserialise them,
61 // they are deletions here as well
62 typed_writes[KSerialiser::from_serialised(uk)] = std::nullopt;
63 }
64 else
65 {
66 typed_writes[KSerialiser::from_serialised(uk)] = Unit::get();
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 template <typename>
91 typename KSerialiser,
94
95 template <typename K>
98
99 template <typename K>
102
106 template <typename K>
108}
Definition set_handle.h:14
Definition set_handle.h:156
Definition set.h:33
K Key
Definition set.h:47
std::map< K, std::optional< ccf::kv::serialisers::SerialisedEntry > > Write
Definition set.h:43
static ccf::kv::untyped::CommitHook wrap_commit_hook(const CommitHook &hook)
Definition set.h:73
static ccf::kv::untyped::MapHook wrap_map_hook(const MapHook &hook)
Definition set.h:80
CommitHook< Write > CommitHook
Definition set.h:45
MapHook< Write > MapHook
Definition set.h:44
KSerialiser KeySerialiser
Definition set.h:48
Definition set_handle.h:107
ccf::kv::CommitHook< Write > CommitHook
Definition untyped.h:18
SerialisedEntry K
Definition untyped_change_set.h:22
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