An ordered collection of Rules — the persistent rule store. More...
#include <PhosphorRules/RuleSet.h>
Public Member Functions | |
| RuleSet ()=default | |
| const QList< Rule > & | rules () const |
| int | count () const |
| bool | isEmpty () const |
| quint64 | revision () const |
| The monotonic revision — bumped on every mutating call. | |
| std::optional< Rule > | ruleById (const QUuid &id) const |
The rule with id, or nullopt if not present. | |
| bool | addRule (const Rule &rule) |
| Append a rule. | |
| bool | updateRule (const Rule &rule) |
| Replace the rule with the same id. | |
| bool | removeRule (const QUuid &id) |
Remove the rule with id. Returns false if no such rule exists. | |
| int | setRules (const QList< Rule > &rules) |
| Replace the entire ordered rule list. | |
| void | clear () |
| Drop every rule. | |
| QJsonObject | toJson () const |
| bool | saveToFile (const QString &path) const |
Canonicalize-on-save: serialize and atomically write to path (temp-file + rename). | |
| bool | operator== (const RuleSet &other) const |
| Equality compares the rule LIST only; revision is intentionally ignored. | |
| bool | operator!= (const RuleSet &other) const |
Static Public Member Functions | |
| static std::optional< RuleSet > | fromJson (const QJsonObject &obj) |
| Strict loader. | |
| static std::optional< RuleSet > | loadFromFile (const QString &path) |
Load from path (an explicit file path — the library never derives config locations). | |
Static Public Attributes | |
| static constexpr int | SchemaVersion = 4 |
| The schema version this library reads and writes. | |
An ordered collection of Rules — the persistent rule store.
Serializes to rules.json with "_version": 4. This rules-file version is INDEPENDENT of the application config schema version (which is at 5): the v4→v5 config migration renamed windowrules.json to rules.json without changing the {type, params} action wire shape, so the rules-file version stayed 4. Do NOT bump SchemaVersion to track the config version. The set also carries a monotonic revision counter bumped on every mutation; the RuleEvaluator keys its match cache on (windowId, revision) so an edit transparently invalidates stale resolutions.
fromJson refuses a non-4 _version — schema migration is the config layer's job, never the library's.
|
default |
| bool PhosphorRules::RuleSet::addRule | ( | const Rule & | rule | ) |
Append a rule.
Returns false (no revision bump) if the rule is invalid or its id collides with an existing rule.
| void PhosphorRules::RuleSet::clear | ( | ) |
Drop every rule.
Bumps the revision iff the set was non-empty (a no-op clear does not bump).
|
inline |
|
static |
Strict loader.
Refuses a non-4 _version (returns nullopt). Malformed individual rules are dropped with a logged diagnostic — the set still loads. The loaded set's revision is reset to 0.
|
inline |
|
static |
Load from path (an explicit file path — the library never derives config locations).
Returns nullopt on a missing/unreadable file, malformed JSON, or a version mismatch.
|
inline |
|
inline |
Equality compares the rule LIST only; revision is intentionally ignored.
The store's no-op fast path uses this to skip an in-place setRules(candidate.rules()) (and the revision bump it would imply) when the post-validation content has not changed — the stored revision stays monotonic because either both sides are equal (no bump) or the live setRules advances it past the prior peak.
| bool PhosphorRules::RuleSet::removeRule | ( | const QUuid & | id | ) |
Remove the rule with id. Returns false if no such rule exists.
|
inline |
The monotonic revision — bumped on every mutating call.
Starts at 0 for an empty default-constructed set.
| std::optional< Rule > PhosphorRules::RuleSet::ruleById | ( | const QUuid & | id | ) | const |
The rule with id, or nullopt if not present.
|
inline |
| bool PhosphorRules::RuleSet::saveToFile | ( | const QString & | path | ) | const |
Canonicalize-on-save: serialize and atomically write to path (temp-file + rename).
Returns false on any I/O failure.
| int PhosphorRules::RuleSet::setRules | ( | const QList< Rule > & | rules | ) |
Replace the entire ordered rule list.
Invalid rules are dropped with a logged diagnostic. Bumps the revision on every call, even if the post-validation list is structurally identical to the current set — downstream consumers keyed on revision must rebuild on every set. The cache-invalidation pessimization is intentional; the round-trip addRule(X) → setRules(originalList) would otherwise let a stale cache survive a real edit. Returns the accepted count.
| QJsonObject PhosphorRules::RuleSet::toJson | ( | ) | const |
| bool PhosphorRules::RuleSet::updateRule | ( | const Rule & | rule | ) |
Replace the rule with the same id.
Returns false if no such rule exists or the replacement is invalid.
|
staticconstexpr |
The schema version this library reads and writes.