Scoped group view backed by a JsonBackend.
More...
#include <phosphor-config/include/PhosphorConfig/JsonBackend.h>
|
| | JsonGroup (QJsonObject &root, QString groupName, JsonBackend *backend) |
| |
| | ~JsonGroup () override |
| |
| QString | readString (const QString &key, const QString &defaultValue={}) const override |
| |
| int | readInt (const QString &key, int defaultValue=0) const override |
| |
| bool | readBool (const QString &key, bool defaultValue=false) const override |
| |
| double | readDouble (const QString &key, double defaultValue=0.0) const override |
| |
| QColor | readColor (const QString &key, const QColor &defaultValue={}) const override |
| |
| void | writeString (const QString &key, const QString &value) override |
| | Write a string.
|
| |
| void | writeInt (const QString &key, int value) override |
| |
| void | writeBool (const QString &key, bool value) override |
| |
| void | writeDouble (const QString &key, double value) override |
| |
| void | writeColor (const QString &key, const QColor &value) 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 string for backends without a native representation.
|
| |
| QJsonValue | readJson (const QString &key, const QJsonValue &defaultValue={}) const override |
| | Read a structured JSON value.
|
| |
| bool | hasKey (const QString &key) const override |
| |
| void | deleteKey (const QString &key) override |
| |
| QStringList | keyList () const override |
| | Enumerate scalar leaf keys directly under this group.
|
| |
| virtual | ~IGroup ()=default |
| |
| | IGroup (const IGroup &)=delete |
| |
| IGroup & | operator= (const IGroup &)=delete |
| |
Scoped group view backed by a JsonBackend.
See IGroup for the contract; this class only adds JSON-specific coercion rules documented on its reader methods.
Only one group view is permitted per backend at a time. Debug builds assert; release builds warn. The backend advances its dirty flag on any write-to-storage through this view.
◆ JsonGroup()
| PhosphorConfig::JsonGroup::JsonGroup |
( |
QJsonObject & |
root, |
|
|
QString |
groupName, |
|
|
JsonBackend * |
backend |
|
) |
| |
◆ ~JsonGroup()
| PhosphorConfig::JsonGroup::~JsonGroup |
( |
| ) |
|
|
override |
◆ deleteKey()
| void PhosphorConfig::JsonGroup::deleteKey |
( |
const QString & |
key | ) |
|
|
overridevirtual |
◆ hasKey()
| bool PhosphorConfig::JsonGroup::hasKey |
( |
const QString & |
key | ) |
const |
|
overridevirtual |
◆ keyList()
| QStringList PhosphorConfig::JsonGroup::keyList |
( |
| ) |
const |
|
overridevirtual |
Enumerate scalar leaf keys directly under this group.
Nested sub-groups (dot-path children in JsonBackend) are NOT included — consumers that want to purge stale keys without touching declared descendants can iterate this list against the schema. Order is implementation-defined.
Implements PhosphorConfig::IGroup.
◆ readBool()
| bool PhosphorConfig::JsonGroup::readBool |
( |
const QString & |
key, |
|
|
bool |
defaultValue = false |
|
) |
| const |
|
overridevirtual |
◆ readColor()
| QColor PhosphorConfig::JsonGroup::readColor |
( |
const QString & |
key, |
|
|
const QColor & |
defaultValue = {} |
|
) |
| const |
|
overridevirtual |
◆ readDouble()
| double PhosphorConfig::JsonGroup::readDouble |
( |
const QString & |
key, |
|
|
double |
defaultValue = 0.0 |
|
) |
| const |
|
overridevirtual |
◆ readInt()
| int PhosphorConfig::JsonGroup::readInt |
( |
const QString & |
key, |
|
|
int |
defaultValue = 0 |
|
) |
| const |
|
overridevirtual |
◆ readJson()
| QJsonValue PhosphorConfig::JsonGroup::readJson |
( |
const QString & |
key, |
|
|
const QJsonValue & |
defaultValue = {} |
|
) |
| const |
|
overridevirtual |
Read a structured JSON value.
Returns defaultValue when the key is absent or unparseable.
The default implementation calls readString and parses the result. Uses hasKey (not string emptiness) to distinguish an absent key from a present empty-string, so empty-string values written through writeJson round-trip correctly. JsonBackend overrides to return the native JSON node directly without a string round-trip.
Reimplemented from PhosphorConfig::IGroup.
◆ readString()
| QString PhosphorConfig::JsonGroup::readString |
( |
const QString & |
key, |
|
|
const QString & |
defaultValue = {} |
|
) |
| const |
|
overridevirtual |
◆ writeBool()
| void PhosphorConfig::JsonGroup::writeBool |
( |
const QString & |
key, |
|
|
bool |
value |
|
) |
| |
|
overridevirtual |
◆ writeColor()
| void PhosphorConfig::JsonGroup::writeColor |
( |
const QString & |
key, |
|
|
const QColor & |
value |
|
) |
| |
|
overridevirtual |
◆ writeDouble()
| void PhosphorConfig::JsonGroup::writeDouble |
( |
const QString & |
key, |
|
|
double |
value |
|
) |
| |
|
overridevirtual |
◆ writeInt()
| void PhosphorConfig::JsonGroup::writeInt |
( |
const QString & |
key, |
|
|
int |
value |
|
) |
| |
|
overridevirtual |
◆ writeJson()
| void PhosphorConfig::JsonGroup::writeJson |
( |
const QString & |
key, |
|
|
const QJsonValue & |
value |
|
) |
| |
|
overridevirtual |
Write a structured JSON value (array/object/scalar) natively where supported, or as a compact-JSON string for backends without a native representation.
The default implementation serializes every value — including strings — to its compact JSON form before storing, so readJson can round-trip it by re-parsing. Strings land on disk quoted ("hello", not hello); consumers that need the raw string should go through writeString / readString directly. JsonBackend overrides this to keep the value as a native JSON node on disk.
Reimplemented from PhosphorConfig::IGroup.
◆ writeString()
| void PhosphorConfig::JsonGroup::writeString |
( |
const QString & |
key, |
|
|
const QString & |
value |
|
) |
| |
|
overridevirtual |
Write a string.
Stored verbatim — no content-dependent reinterpretation.
Callers that need to persist structured data (array/object) should go through writeJson, which preserves the native JSON type where the backend supports it (JsonBackend stores as a native array/object; QSettingsBackend stringifies).
Implements PhosphorConfig::IGroup.
The documentation for this class was generated from the following file: