CCF
Loading...
Searching...
No Matches
value_handle.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/unit.h"
7
8namespace ccf::kv
9{
12 template <typename V, typename VSerialiser, typename Unit>
14 {
15 protected:
17
18 public:
19 using ValueType = V;
20
22
31 std::optional<V> get()
32 {
33 const auto opt_v_rep = read_handle.get(Unit::get());
34
35 if (opt_v_rep.has_value())
36 {
37 return VSerialiser::from_serialised(*opt_v_rep);
38 }
39
40 return std::nullopt;
41 }
42
49 std::optional<V> get_globally_committed()
50 {
51 const auto opt_v_rep = read_handle.get_globally_committed(Unit::get());
52
53 if (opt_v_rep.has_value())
54 {
55 return VSerialiser::from_serialised(*opt_v_rep);
56 }
57
58 return std::nullopt;
59 }
60
68 bool has()
69 {
70 return read_handle.has(Unit::get());
71 }
72
81 std::optional<Version> get_version_of_previous_write()
82 {
84 }
85 };
86
89 template <typename V, typename VSerialiser, typename Unit>
91 {
92 protected:
94
95 public:
97
106 void put(const V& value)
107 {
108 write_handle.put(Unit::get(), VSerialiser::to_serialised(value));
109 }
110
113 void clear()
114 {
116 }
117 };
118
125 template <typename V, typename VSerialiser, typename Unit>
127 public ReadableValueHandle<V, VSerialiser, Unit>,
128 public WriteableValueHandle<V, VSerialiser, Unit>
129 {
130 protected:
132
135
136 public:
138 ccf::kv::untyped::ChangeSet& changes, const std::string& map_name) :
141 untyped_handle(changes, map_name)
142 {}
143 };
144}
Definition abstract_handle.h:8
Definition value_handle.h:14
V ValueType
Definition value_handle.h:19
ReadableValueHandle(ccf::kv::untyped::MapHandle &uh)
Definition value_handle.h:21
std::optional< V > get()
Definition value_handle.h:31
bool has()
Definition value_handle.h:68
ccf::kv::untyped::MapHandle & read_handle
Definition value_handle.h:16
std::optional< Version > get_version_of_previous_write()
Definition value_handle.h:81
std::optional< V > get_globally_committed()
Definition value_handle.h:49
Definition value_handle.h:129
ValueHandle(ccf::kv::untyped::ChangeSet &changes, const std::string &map_name)
Definition value_handle.h:137
ccf::kv::untyped::MapHandle untyped_handle
Definition value_handle.h:131
Definition value_handle.h:91
void put(const V &value)
Definition value_handle.h:106
void clear()
Definition value_handle.h:113
ccf::kv::untyped::MapHandle & write_handle
Definition value_handle.h:93
WriteableValueHandle(ccf::kv::untyped::MapHandle &uh)
Definition value_handle.h:96
Definition untyped_map_handle.h:18
void clear()
Definition untyped_map_handle.cpp:175
bool has(const KeyType &key)
Definition untyped_map_handle.cpp:145
void put(const KeyType &key, const ValueType &value)
Definition untyped_map_handle.cpp:160
std::optional< Version > get_version_of_previous_write(const KeyType &key)
Definition untyped_map_handle.cpp:111
std::optional< ValueType > get(const KeyType &key)
Definition untyped_map_handle.cpp:96
std::optional< ValueType > get_globally_committed(const KeyType &key)
Definition untyped_map_handle.cpp:131
Definition app_interface.h:19
Definition untyped_change_set.h:43