Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
PhosphorLayer::JsonSurfaceStore Class Reference

File-backed ISurfaceStore — one JSON document on disk. More...

#include <phosphor-layer/include/PhosphorLayer/defaults/JsonSurfaceStore.h>

Inheritance diagram for PhosphorLayer::JsonSurfaceStore:
[legend]

Public Member Functions

 JsonSurfaceStore (QString filePath)
 
 ~JsonSurfaceStore () override
 
bool save (const QString &key, const QJsonObject &data) override
 Persist data under key.
 
QJsonObject load (const QString &key) const override
 Load the JSON object previously stored under key.
 
bool has (const QString &key) const override
 True if key exists in the store.
 
void remove (const QString &key) override
 Remove the entry for key (no-op if absent).
 
QString filePath () const
 File path this store reads from / writes to.
 
- Public Member Functions inherited from PhosphorLayer::ISurfaceStore
 ISurfaceStore ()=default
 
virtual ~ISurfaceStore ()=default
 

Detailed Description

File-backed ISurfaceStore — one JSON document on disk.

The entire store is serialised as a single JSON object keyed by key-name. Loads happen lazily on first access; saves use QSaveFile for atomicity (write-to-temp + rename). Suitable for modest amounts of state (hundreds of keys); for heavier workloads wrap KConfig or a database.

The file path is consumer-chosen. Typical usage:

JsonSurfaceStore store(QStandardPaths::writableLocation(
QStandardPaths::AppDataLocation)
+ "/surface-state.json");
File-backed ISurfaceStore — one JSON document on disk.
Definition JsonSurfaceStore.h:43
Note
Thread safety. This store is NOT thread-safe — save() and load() share a single in-memory QJsonObject without locks. All calls must originate from the same thread (typically the GUI thread). Consumers that need cross-thread access must serialise calls externally, or wrap the store in their own mutex. Every save() also rewrites the full file; batching on the caller side is recommended if many keys are mutated together.

Constructor & Destructor Documentation

◆ JsonSurfaceStore()

PhosphorLayer::JsonSurfaceStore::JsonSurfaceStore ( QString  filePath)
explicit

◆ ~JsonSurfaceStore()

PhosphorLayer::JsonSurfaceStore::~JsonSurfaceStore ( )
override

Member Function Documentation

◆ filePath()

QString PhosphorLayer::JsonSurfaceStore::filePath ( ) const

File path this store reads from / writes to.

◆ has()

bool PhosphorLayer::JsonSurfaceStore::has ( const QString &  key) const
overridevirtual

True if key exists in the store.

Implements PhosphorLayer::ISurfaceStore.

◆ load()

QJsonObject PhosphorLayer::JsonSurfaceStore::load ( const QString &  key) const
overridevirtual

Load the JSON object previously stored under key.

Returns an empty object if the key does not exist or the stored data cannot be parsed.

Implements PhosphorLayer::ISurfaceStore.

◆ remove()

void PhosphorLayer::JsonSurfaceStore::remove ( const QString &  key)
overridevirtual

Remove the entry for key (no-op if absent).

Implements PhosphorLayer::ISurfaceStore.

◆ save()

bool PhosphorLayer::JsonSurfaceStore::save ( const QString &  key,
const QJsonObject &  data 
)
overridevirtual

Persist data under key.

Overwrites any existing entry. Returns false on I/O failure (the implementation logs the reason).

Implements PhosphorLayer::ISurfaceStore.


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