6#include "phosphorconfig_export.h"
51 QString
readString(
const QString& key,
const QString& defaultValue = {})
const override;
52 int readInt(
const QString& key,
int defaultValue = 0)
const override;
53 bool readBool(
const QString& key,
bool defaultValue =
false)
const override;
54 double readDouble(
const QString& key,
double defaultValue = 0.0)
const override;
55 QColor
readColor(
const QString& key,
const QColor& defaultValue = {})
const override;
57 void writeString(
const QString& key,
const QString& value)
override;
58 void writeInt(
const QString& key,
int value)
override;
59 void writeBool(
const QString& key,
bool value)
override;
61 void writeColor(
const QString& key,
const QColor& value)
override;
62 void writeJson(
const QString& key,
const QJsonValue& value)
override;
63 QJsonValue
readJson(
const QString& key,
const QJsonValue& defaultValue = {})
const override;
65 bool hasKey(
const QString& key)
const override;
72 QJsonObject groupObject()
const;
75 QJsonObject storedGroupObject()
const;
76 void setGroupObject(
const QJsonObject& obj);
80 bool refuseWrite(
const char* op)
const;
90 bool m_disabled =
false;
134 std::unique_ptr<IGroup>
group(
const QString& name)
override;
167 QString
readRootString(
const QString& key,
const QString& defaultValue = {})
const override;
327 void loadFromDisk(QString* problem =
nullptr);
334 void incActiveGroupCount();
335 void decActiveGroupCount();
336 int activeGroupCount()
const;
342 bool shouldWarnOnce(
const char* tag,
const QString& key);
345 std::unique_ptr<Data> d;
IBackend(const IBackend &)=delete
Optional plug-in for custom group name semantics.
Definition IGroupPathResolver.h:30
IGroup(const IGroup &)=delete
Atomic-write JSON configuration backend.
Definition JsonBackend.h:111
SyncPolicy
Sync timing policy. See setSyncPolicy for the full contract.
Definition JsonBackend.h:282
bool commit() override
Bypasses the Deferred sync policy's debounce so the return value is a real commit result under every ...
void setRootGroupName(const QString &name)
Change the JSON object that receives ungrouped writeRootString calls.
bool blankFile() const
The most recent load found a file of only white space, which reads as an empty document.
QStringList groupList() const override
Enumerates the file's groups and the overlay's together, as one document with the overlay merged in.
friend class JsonGroup
Definition JsonBackend.h:323
QString rootGroupName() const
Load
When the constructor reads the file.
Definition JsonBackend.h:114
@ Now
In the constructor, logging a file it cannot read.
Definition JsonBackend.h:115
void writeRootString(const QString &key, const QString &value) override
bool isDirty() const override
Whether the in-memory document carries changes that have not been committed to disk.
bool applyMigration(const Schema &schema) override
Run schema's migration chain against the in-memory root, and if any step bumps the version stamp,...
SyncPolicy syncPolicy() const
QString filePath() const
Backing file path (useful for migration-chain callers that need to rewrite via writeJsonAtomically du...
QString reload()
Reloads the file as reparseConfiguration does, for a caller that reports problems itself: nothing is ...
void reparseConfiguration() override
Reloads the file.
std::unique_ptr< IGroup > persistedGroup(const QString &name) override
A JsonGroup opened as JsonGroup::View::Persisted: the file's values without the overlay.
void setOverlay(const QJsonObject &overlay)
Lay overlay over the file for every read, without ever writing it.
QString readRootString(const QString &key, const QString &defaultValue={}) const override
Sees the overlay's root-group values over the file's.
std::unique_ptr< IGroup > group(const QString &name) override
Return a scoped view into the named group.
void setOverwriteUnreadable(bool overwrite)
Let writes replace an unreadable file instead of refusing.
void replaceRoot(QJsonObject root)
Replace the in-memory document with root.
void setPathResolver(std::shared_ptr< IGroupPathResolver > resolver) override
Attach a custom path resolver.
void setSyncPolicy(SyncPolicy policy, int debounceMs=500)
Configure when sync() commits to disk.
bool flushPending()
Flush to disk now, cancelling any pending deferred-sync timer first.
std::pair< QString, int > versionStamp() const override
Currently-installed version stamp as {key, version}.
void setVersionStamp(const QString &key, int version) override
Stamp-on-sync: if non-empty, every sync() that writes the file will insert key = version when the key...
std::shared_ptr< IGroupPathResolver > pathResolver() const override
Currently-installed resolver, or nullptr when none is set (also the default for backends that ignore ...
void removeRootKey(const QString &key) override
void applyVersionStamp(QJsonObject &root) const
Insert the installed version stamp into root when a stamp is configured and root does not already car...
void deleteGroup(const QString &name) override
Delete an entire group and everything inside it.
static bool writeJsonAtomically(const QString &filePath, const QJsonObject &root)
Atomically write root to filePath (temp file + rename via QSaveFile).
void clearDirty()
Clear the dirty flag without writing.
JsonBackend(QString filePath, Load load=Load::Now)
Construct a backend backed by filePath.
QJsonObject jsonRootSnapshot() const
Read-only access to the in-memory document.
bool loadFailed() const override
Whether the most recent load (construction or reparseConfiguration), or a flush that found the store ...
QJsonObject overlay() const
The overlay last set, or an empty object.
bool sync() override
Request that pending writes reach disk.
QStringList keyList() const override
Enumerate scalar leaf keys directly under this group.
QJsonValue readJson(const QString &key, const QJsonValue &defaultValue={}) const override
Read a structured JSON value.
QColor readColor(const QString &key, const QColor &defaultValue={}) const override
bool hasKey(const QString &key) const override
void writeInt(const QString &key, int value) override
bool readBool(const QString &key, bool defaultValue=false) const override
QString readString(const QString &key, const QString &defaultValue={}) const override
void writeString(const QString &key, const QString &value) override
Write a string.
void writeBool(const QString &key, bool value) override
int readInt(const QString &key, int defaultValue=0) const override
void writeJson(const QString &key, const QJsonValue &value) override
Write a structured JSON value (array/object/scalar) natively where supported, or as a compact-JSON st...
View
What the view's reads observe.
Definition JsonBackend.h:41
@ Effective
The overlay over the file: what JsonBackend::group() hands out.
Definition JsonBackend.h:43
void writeDouble(const QString &key, double value) override
double readDouble(const QString &key, double defaultValue=0.0) const override
JsonGroup(QJsonObject &root, QString groupName, JsonBackend *backend, View view=View::Effective)
void deleteKey(const QString &key) override
void writeColor(const QString &key, const QColor &value) override
Definition HostDirectory.h:19
Declarative description of a configuration store.
Definition Schema.h:127