CCF
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser > Class Template Reference

#include <map_handle.h>

Inherited by ccf::kv::MapHandle< K, V, KSerialiser, VSerialiser >.

Public Types

using KeyType = K
 
using ValueType = V
 

Public Member Functions

 ReadableMapHandle (ccf::kv::untyped::MapHandle &uh)
 
std::string get_name_of_map () const
 
std::optional< V > get (const K &key)
 
std::optional< V > get_globally_committed (const K &key)
 
bool has (const K &key)
 
std::optional< Versionget_version_of_previous_write (const K &key)
 
template<class F >
void foreach (F &&f)
 
template<class F >
void foreach_key (F &&f)
 
template<class F >
void foreach_value (F &&f)
 
size_t size ()
 

Protected Attributes

ccf::kv::untyped::MapHandleread_handle
 

Detailed Description

template<typename K, typename V, typename KSerialiser, typename VSerialiser>
class ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >

Grants read access to a ccf::kv::Map, as part of a ccf::kv::Tx.

Member Typedef Documentation

◆ KeyType

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
using ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::KeyType = K

◆ ValueType

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
using ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::ValueType = V

Constructor & Destructor Documentation

◆ ReadableMapHandle()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::ReadableMapHandle ( ccf::kv::untyped::MapHandle uh)
inline

Member Function Documentation

◆ foreach()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
template<class F >
void ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::foreach ( F &&  f)
inline

Iterate over all entries in the map.

The passed functor should have the signature bool(const K& k, const V& v). The iteration order is undefined. Return true to continue iteration, or return false from any invocation to terminate the iteration at that point - the functor will not be invoked again after it returns false.

The set of key-value entries which will be iterated over is determined at the point foreach is called, and does not include any modifications made by the functor. This means:

  • If the functor sets a value V at a new key K', the functor will not be called for (K', V)
  • If the functor changes the value at key K from V to V', the functor will be called with the old value (K, V), not the new value (K, V')
  • If the functor removes K, the functor will still be called for (K, V)

Calling get will always return the true latest state; the iterator visibility described above only applies to the keys and values passed to this functor.

Template Parameters
FFunctor type. Should usually be derived implicitly from f
Parameters
fFunctor instance, taking (const K& k, const V& v) and returning a bool. Return value determines whether the iteration should continue (true) or stop (false)

◆ foreach_key()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
template<class F >
void ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::foreach_key ( F &&  f)
inline

Iterate over all keys in the map.

Similar to foreach but the functor takes a single key argument rather than a key and value. Avoids deserialisation of values.

Template Parameters
FFunctor type. Should usually be derived implicitly from f
Parameters
fFunctor instance, taking (const K& k) and returning a bool. Return value determines whether the iteration should continue (true) or stop (false)

◆ foreach_value()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
template<class F >
void ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::foreach_value ( F &&  f)
inline

Iterate over all values in the map.

Similar to foreach but the functor takes a single value argument rather than a key and value. Avoids deserialisation of keys.

Template Parameters
FFunctor type. Should usually be derived implicitly from f
Parameters
fFunctor instance, taking (const V& v) and returning a bool. Return value determines whether the iteration should continue (true) or stop (false)

◆ get()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
std::optional< V > ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::get ( const K &  key)
inline

Get value for key.

This returns the value for the key as seen by this transaction. If the key has been updated in the current transaction, that update will be reflected in the return of this call. Where the key has not been modified, this returns the state of a snapshot version from the start of the transaction's execution.

Parameters
keyKey to read
Returns
Optional containing associated value, or empty if the key doesn't exist

◆ get_globally_committed()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
std::optional< V > ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::get_globally_committed ( const K &  key)
inline

Get globally committed value for key, which has been replicated and acknowledged by consensus protocol.

This reads a globally replicated value for the specified key. The value will have been the most recent replicated value when the transaction began. Consensus may have advanced and committed a more recent version while this transaction executes. This is undetectable to the transaction.

Parameters
keyKey to read
Returns
Optional containing associated value, or empty if the key doesn't exist in globally committed state

◆ get_name_of_map()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
std::string ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::get_name_of_map ( ) const
inline

Get name of this map.

Returns
String containing name used to construct this map handle

◆ get_version_of_previous_write()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
std::optional< Version > ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::get_version_of_previous_write ( const K &  key)
inline

Get version when this key was last written to, by a previous transaction.

Returns nullopt when there is no value, because the key has no value (never existed or has been removed). Note that this is always talking about the version of previously applied state and not the same values as get or has. This current transaction's pending writes have no version yet, and this method does not talk about them.

Parameters
keyKey to read
Returns
Optional containing version of applied transaction which last wrote at this key, or nullopt if such a version does not exist

◆ has()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
bool ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::has ( const K &  key)
inline

Test if key is present.

This obeys the same rules as get regarding key visibility, but is more efficient if you do not need the associated value.

Parameters
keyKey to read
Returns
Boolean true iff key exists

◆ size()

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
size_t ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::size ( )
inline

Returns number of entries in this map.

This is the count of all currently present keys, including both those which were already committed and any modifications (taking into account new additions or removals) that have been made during this transaction.

Returns
Count of entries

Member Data Documentation

◆ read_handle

template<typename K , typename V , typename KSerialiser , typename VSerialiser >
ccf::kv::untyped::MapHandle& ccf::kv::ReadableMapHandle< K, V, KSerialiser, VSerialiser >::read_handle
protected

The documentation for this class was generated from the following file: