Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorRegistry::PathKeyedOverrides< Payload > Class Template Reference

A baseline payload plus keyed overrides, in insertion order. More...

#include <PhosphorRegistry/PathKeyedOverrides.h>

Public Member Functions

const Payload & baseline () const
void setBaseline (const Payload &payload)
bool hasOverride (const QString &key) const
Payload directOverride (const QString &key) const
 The override stored at key, or a default-constructed payload when there is none.
const Payload * findOverride (const QString &key) const
 A POINTER to the override at key, or nullptr when there is none.
const QStringList & keys () const
 Every overridden key, in the order it was first set.
void setOverride (const QString &key, const Payload &payload)
 Store payload at key.
bool clearOverride (const QString &key)
void clearAllOverrides ()
bool hasOverrides () const
 True when at least one override is present.
template<typename Fn>
void forEachInOrder (Fn fn) const
 Invoke fn(key, payload) for every override, in insertion order.
bool sameBaseline (const PathKeyedOverrides &other) const
bool sameOverrides (const PathKeyedOverrides &other) const
 Compares the overrides as a SET: same keys, same payloads, order ignored.
bool sameKeyOrder (const PathKeyedOverrides &other) const

Detailed Description

template<typename Payload>
class PhosphorRegistry::PathKeyedOverrides< Payload >

A baseline payload plus keyed overrides, in insertion order.

The container the shader-assignment trees each re-derived: a global baseline, a map of per-key overrides, the order they were added in, and the handful of mutators and accessors over both. All FOUR assignment trees hold one of these now and forward to it: PhosphorAnimationShaders::ShaderProfileTree, PhosphorSurfaceShaders::DecorationProfileTree, PlasmaZones::OverlayShaderTree and PhosphorAnimation::ProfileTree, the motion tree, which was the last to convert.

What this deliberately does NOT do

It is not an attempt to make the four assignment trees named above one TYPE. They genuinely differ in key space (dot-paths against layout UUIDs), inheritance model (a full walk-up against a single override-or-baseline step), payload shape (per-field optionals against a plain struct) and parse dependency, and collapsing those would force optionals onto a payload that deliberately has none or cost the others their per-field inheritance. So resolve(), the seed overlay, key normalisation and equality stay with each tree, where the differences live.

What was duplicated and should not have been is everything below: four hand-written copies of the same storage, the same setOverride / clearOverride / overriddenPaths, the same insertion-order bookkeeping, the same empty-key guard, the same serialisation loop. They had already drifted — one tree dropped its insertion-order list while the other three kept theirs, and the empty-key guard was written out three times — which is the evidence that lifting the CONSTANTS into a shared header while leaving the traversals hand-written was never going to hold. The numbers were not the hard part.

Insertion order is always tracked

Even for a consumer that presents its keys sorted. It is one QStringList of keys, and making it a policy knob would encode the very divergence this exists to remove — a tree that wants sorted output sorts in its own accessor and is free to ignore the order this keeps.

Template Parameters
PayloadA value type. Needs copy-assignment and operator==; the owning tree supplies its own toJson / fromJson, because the root object's field names belong to the tree, not here.

Member Function Documentation

◆ baseline()

template<typename Payload>
const Payload & PhosphorRegistry::PathKeyedOverrides< Payload >::baseline ( ) const
inline

◆ clearAllOverrides()

template<typename Payload>
void PhosphorRegistry::PathKeyedOverrides< Payload >::clearAllOverrides ( )
inline

◆ clearOverride()

template<typename Payload>
bool PhosphorRegistry::PathKeyedOverrides< Payload >::clearOverride ( const QString & key)
inline
Returns
true when an override was actually removed.

removeAll, not removeOne, and the two are equivalent only because setOverride above is the sole writer of m_insertionOrder and appends only on a !contains miss — so a key can appear at most once. Stating the invariant here rather than relying on it silently: if a second writer ever appends, removeAll still leaves the list consistent with the hash, which removeOne would not.

◆ directOverride()

template<typename Payload>
Payload PhosphorRegistry::PathKeyedOverrides< Payload >::directOverride ( const QString & key) const
inline

The override stored at key, or a default-constructed payload when there is none.

Returning the default rather than asserting is what lets a caller ask about a key it has not checked.

◆ findOverride()

template<typename Payload>
const Payload * PhosphorRegistry::PathKeyedOverrides< Payload >::findOverride ( const QString & key) const
inline

A POINTER to the override at key, or nullptr when there is none.

For the walk-up loops, which ask about a key and then read it: one hash lookup instead of hasOverride plus directOverride, and no payload copy per step. A resolve over a four-segment dot-path was paying four extra lookups and up to sixteen container ref-count operations for an answer it already had. Not a regression anyone would see — these paths are event-driven, never per frame — which is exactly why it is worth taking for free rather than arguing about.

The pointer is into this container's storage, so it is invalidated by any mutation. Every caller reads it and moves on within one expression; a caller that wants to keep the value takes directOverride instead.

◆ forEachInOrder()

template<typename Payload>
template<typename Fn>
void PhosphorRegistry::PathKeyedOverrides< Payload >::forEachInOrder ( Fn fn) const
inline

Invoke fn(key, payload) for every override, in insertion order.

The shared half of serialisation, and deliberately only this half. Three of the four trees write their overrides as a JSON ARRAY of {path, profile} entries — which is why insertion order is part of their identity, it is observable on the wire — while the fourth writes a key-addressed object. A shared overridesToJson would have to take the field names as parameters and still only fit three of four: a knob pretending to be an abstraction.

What they genuinely share is this walk and the guard inside it, which each had written out with the same comment attached. The entry shape stays with the tree that owns the format.

◆ hasOverride()

template<typename Payload>
bool PhosphorRegistry::PathKeyedOverrides< Payload >::hasOverride ( const QString & key) const
inline

◆ hasOverrides()

template<typename Payload>
bool PhosphorRegistry::PathKeyedOverrides< Payload >::hasOverrides ( ) const
inline

True when at least one override is present.

Says nothing about the baseline, which a caller judges with its own payload-specific emptiness test.

Named positively on purpose. The first spelling was hasNoOverrides, and every caller but one wanted the opposite, so each one read !hasNoOverrides().

◆ keys()

template<typename Payload>
const QStringList & PhosphorRegistry::PathKeyedOverrides< Payload >::keys ( ) const
inline

Every overridden key, in the order it was first set.

◆ sameBaseline()

template<typename Payload>
bool PhosphorRegistry::PathKeyedOverrides< Payload >::sameBaseline ( const PathKeyedOverrides< Payload > & other) const
inline

◆ sameKeyOrder()

template<typename Payload>
bool PhosphorRegistry::PathKeyedOverrides< Payload >::sameKeyOrder ( const PathKeyedOverrides< Payload > & other) const
inline

◆ sameOverrides()

template<typename Payload>
bool PhosphorRegistry::PathKeyedOverrides< Payload >::sameOverrides ( const PathKeyedOverrides< Payload > & other) const
inline

Compares the overrides as a SET: same keys, same payloads, order ignored.

◆ setBaseline()

template<typename Payload>
void PhosphorRegistry::PathKeyedOverrides< Payload >::setBaseline ( const Payload & payload)
inline

◆ setOverride()

template<typename Payload>
void PhosphorRegistry::PathKeyedOverrides< Payload >::setOverride ( const QString & key,
const Payload & payload )
inline

Store payload at key.

An EMPTY key is refused. Every tree that used this guarded it separately, and for the same reason: the empty string is how each of them spells "the baseline", so accepting it as an override key would create an entry that shadows the baseline it is supposed to BE.


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