libdisplaydevice master
C++ library to modify display devices.
persistent_state_utils.h File Reference

Shared helpers for persistent state wrappers. More...

#include <cstdint>
#include <iterator>
#include <optional>
#include <string_view>
#include <vector>
#include "display_device/logging.h"
#include "display_device/settings_persistence_interface.h"
Include dependency graph for persistent_state_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename State , typename SerializeFn >
bool display_device::detail::persistState (SettingsPersistenceInterface &settings_persistence_api, std::optional< State > &cached_state, const std::optional< State > &state, const SerializeFn &serialize_state, const std::string_view serialize_error_message)
 Persist state and update the cached copy after a successful write.
 

Detailed Description

Shared helpers for persistent state wrappers.

Function Documentation

◆ persistState()

template<typename State , typename SerializeFn >
bool display_device::detail::persistState ( SettingsPersistenceInterface & settings_persistence_api,
std::optional< State > & cached_state,
const std::optional< State > & state,
const SerializeFn & serialize_state,
const std::string_view serialize_error_message )
nodiscard

Persist state and update the cached copy after a successful write.

Template Parameters
StateCached state type.
SerializeFnCallable type used to serialize the state.
Parameters
settings_persistence_apiPersistence API used to store or clear state.
cached_stateCached state to compare and update.
stateNew state to persist.
serialize_stateCallable that serializes a state and updates a success flag.
serialize_error_messageError message used when serialization fails.
Returns
True if the state was already current or was persisted successfully, false otherwise.