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

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ RuleSet()

PhosphorRules::RuleSet::RuleSet ( )
default

Member Function Documentation

◆ addRule()

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.

◆ clear()

void PhosphorRules::RuleSet::clear ( )

Drop every rule.

Bumps the revision iff the set was non-empty (a no-op clear does not bump).

◆ count()

int PhosphorRules::RuleSet::count ( ) const
inline

◆ fromJson()

std::optional< RuleSet > PhosphorRules::RuleSet::fromJson ( const QJsonObject & obj)
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.

◆ isEmpty()

bool PhosphorRules::RuleSet::isEmpty ( ) const
inline

◆ loadFromFile()

std::optional< RuleSet > PhosphorRules::RuleSet::loadFromFile ( const QString & path)
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.

◆ operator!=()

bool PhosphorRules::RuleSet::operator!= ( const RuleSet & other) const
inline

◆ operator==()

bool PhosphorRules::RuleSet::operator== ( const RuleSet & other) const
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.

◆ removeRule()

bool PhosphorRules::RuleSet::removeRule ( const QUuid & id)

Remove the rule with id. Returns false if no such rule exists.

◆ revision()

quint64 PhosphorRules::RuleSet::revision ( ) const
inline

The monotonic revision — bumped on every mutating call.

Starts at 0 for an empty default-constructed set.

◆ ruleById()

std::optional< Rule > PhosphorRules::RuleSet::ruleById ( const QUuid & id) const

The rule with id, or nullopt if not present.

◆ rules()

const QList< Rule > & PhosphorRules::RuleSet::rules ( ) const
inline

◆ saveToFile()

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.

◆ setRules()

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.

◆ toJson()

QJsonObject PhosphorRules::RuleSet::toJson ( ) const

◆ updateRule()

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.

Member Data Documentation

◆ SchemaVersion

int PhosphorRules::RuleSet::SchemaVersion = 4
staticconstexpr

The schema version this library reads and writes.


The documentation for this class was generated from the following file:
  • phosphor-rules/include/PhosphorRules/RuleSet.h