guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::SessionStorage Class Reference

Key-value storage that lasts as long as the process: the place for data shared between scenes that need not survive a restart. More...

#include <headers/guillaume/session_storage.hpp>

Inheritance diagram for guillaume::SessionStorage:
Collaboration diagram for guillaume::SessionStorage:

Public Member Functions

 SessionStorage (void)=default
 Create a handle on the process-wide session items.
 ~SessionStorage (void) override=default
 Destroy the handle. The items are kept.
void setItem (const std::string &key, const std::string &value) override
 Store a string under a key, replacing the item already stored under that key, if any.
std::optional< std::string > getItem (const std::string &key) override
 Read the text stored under a key.
void removeItem (const std::string &key) override
 Delete the item stored under a key. Does nothing when there is none.
void clear (void) override
 Delete every session item of the process, including those written through other SessionStorage objects.
void setItem (const std::string &key, std::string_view value)
 Store a copy of a string view under a key.
void setItem (const std::string &key, const char *value)
 Store a copy of a C string under a key.
template<typename ValueType>
requires (std::is_same_v<std::remove_cvref_t<ValueType>, bool>)
void setItem (const std::string &key, ValueType value)
 Store a boolean under a key, as the text "true" or "false".
Public Member Functions inherited from guillaume::Storage
virtual ~Storage (void)=default
 Virtual destructor.
void setItem (const std::string &key, std::string_view value)
 Store a copy of a string view under a key.
void setItem (const std::string &key, const char *value)
 Store a copy of a C string under a key.
template<typename ValueType>
requires (std::is_same_v<std::remove_cvref_t<ValueType>, bool>)
void setItem (const std::string &key, ValueType value)
 Store a boolean under a key, as the text "true" or "false".
template<typename ValueType>
requires (std::is_arithmetic_v<ValueType> && !std::is_same_v<ValueType, bool>)
void setItem (const std::string &key, ValueType value)
 Store a number under a key, as its decimal text.
template<typename ValueType>
std::optional< ValueType > getItemAs (const std::string &key)
 Read the item stored under a key and convert it to a type.

Detailed Description

Key-value storage that lasts as long as the process: the place for data shared between scenes that need not survive a restart.

All SessionStorage objects of a process read and write the same items: creating a second instance gives another handle on the same data, not a second store, and destroying an instance deletes nothing. The typed overloads of Storage (numbers, booleans, getItemAs) are available.

first.setItem("step", 3);
second.getItemAs<int>("step"); // 3
Key-value storage that lasts as long as the process: the place for data shared between scenes that ne...
void setItem(const std::string &key, const std::string &value) override
Store a string under a key, replacing the item already stored under that key, if any.
std::optional< ValueType > getItemAs(const std::string &key)
Read the item stored under a key and convert it to a type.
Note
Every operation takes a lock, so the storage can be used from several threads. clear() empties it for the whole process.
See also
Storage
LocalStorage

Definition at line 58 of file session_storage.hpp.

Member Function Documentation

◆ clear()

void guillaume::SessionStorage::clear ( void )
overridevirtual

Delete every session item of the process, including those written through other SessionStorage objects.

Implements guillaume::Storage.

◆ getItem()

std::optional< std::string > guillaume::SessionStorage::getItem ( const std::string & key)
overridevirtual

Read the text stored under a key.

Parameters
keyThe name of the item.
Returns
A copy of the stored text, or std::nullopt when no item has that key.

Implements guillaume::Storage.

◆ removeItem()

void guillaume::SessionStorage::removeItem ( const std::string & key)
overridevirtual

Delete the item stored under a key. Does nothing when there is none.

Parameters
keyThe name of the item.

Implements guillaume::Storage.

◆ setItem() [1/4]

void guillaume::Storage::setItem ( const std::string & key,
const char * value )

Store a copy of a C string under a key.

Parameters
keyThe name of the item.
valueThe null-terminated text to store. A null pointer stores an empty string.

◆ setItem() [2/4]

void guillaume::SessionStorage::setItem ( const std::string & key,
const std::string & value )
overridevirtual

Store a string under a key, replacing the item already stored under that key, if any.

Parameters
keyThe name of the item.
valueThe text to store.

Implements guillaume::Storage.

◆ setItem() [3/4]

void guillaume::Storage::setItem ( const std::string & key,
std::string_view value )

Store a copy of a string view under a key.

Parameters
keyThe name of the item.
valueThe text to store.

◆ setItem() [4/4]

template<typename ValueType>
requires (std::is_same_v<std::remove_cvref_t<ValueType>, bool>)
void guillaume::Storage::setItem ( const std::string & key,
ValueType value )

Store a boolean under a key, as the text "true" or "false".

Template Parameters
ValueTypebool (possibly const or a reference).
Parameters
keyThe name of the item.
valueThe boolean to store.

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