DirectZ
Loading...
Searching...
No Matches
dz::KeyValueStream< KeyT, ValueT > Class Template Reference

A key-value binary stream writer/reader with support for serialization, deserialization, and deletion. More...

#include <KeyValueStream.hpp>

Classes

struct  HeaderEntry
 Represents metadata for a key-value entry in the file. More...

Public Member Functions

 KeyValueStream (FileHandle &file_handle)
 Constructs a KeyValueStream with a reference to an existing file handle.
void write (const KeyT &key, const ValueT &value)
 Writes a key-value pair to the stream, replacing any existing value for the key.
bool read (const KeyT &key, ValueT &out)
 Reads a value by key.
bool erase (const KeyT &key)
 Removes a key-value pair from the stream.

Detailed Description

template<typename KeyT, typename ValueT>
class dz::KeyValueStream< KeyT, ValueT >

A key-value binary stream writer/reader with support for serialization, deserialization, and deletion.

Template Parameters
KeyTType of the key.
ValueTType of the value.

Constructor & Destructor Documentation

◆ KeyValueStream()

template<typename KeyT, typename ValueT>
dz::KeyValueStream< KeyT, ValueT >::KeyValueStream ( FileHandle & file_handle)
inline

Constructs a KeyValueStream with a reference to an existing file handle.

Parameters
file_handleThe file handle to operate on.

Member Function Documentation

◆ erase()

template<typename KeyT, typename ValueT>
bool dz::KeyValueStream< KeyT, ValueT >::erase ( const KeyT & key)
inline

Removes a key-value pair from the stream.

Parameters
keyThe key to erase.
Returns
True if erased successfully, false if the key did not exist.

◆ read()

template<typename KeyT, typename ValueT>
bool dz::KeyValueStream< KeyT, ValueT >::read ( const KeyT & key,
ValueT & out )
inline

Reads a value by key.

Parameters
keyThe key to look up.
outOutput parameter for the deserialized value.
Returns
True if the value was found and read successfully, false otherwise.

◆ write()

template<typename KeyT, typename ValueT>
void dz::KeyValueStream< KeyT, ValueT >::write ( const KeyT & key,
const ValueT & value )
inline

Writes a key-value pair to the stream, replacing any existing value for the key.

Parameters
keyThe key to write.
valueThe value to write.

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