OperationSubject.h header

#include <ew/core/OperationSubject.h>

Namespace ew::core

Types

using ew::core::foundation::OperationSubject = std::variant<std::monostate, ContentId, CategoryId, ProjectFacet>

The one thing an operation was about: what an operation journal names as the target of a change, and what a policy check asks about when deciding whether a change was allowed.

Three alternatives, because the model genuinely has three kinds of subject – measured across every Command in the tree rather than assumed:

  • ContentId – a content object (a document, entity, task, map, sheet, language, ...).
  • CategoryId – a taxonomy category, which has its own id kind and is not a content object.
  • ProjectFacet – project-level state that has no id at all, because the project is the container ids live in (its calendar, goal, mounts, saved searches, timeline eras, ...).

std::monostate means "no subject of its own" and is reserved for a command that groups others: the group's members carry the real subjects. It is first so a default-constructed subject is the empty one.

A subject is deliberately NOT derivable from a command's members. A command holds ids for its subject, for the new value it applies, and for the state it snapshotted to undo with, and nothing in the type system tells those apart – SetEntityCategoryCommand holds a CategoryId that is its value while its subject is an entity, and ReparentCategoryCommand holds a ContentId that is undo state while its subject is a category. Each command therefore states its own subject.

Functions

bool ew::core::foundation::isEmpty(const OperationSubject &subject)

Whether subject is the empty one (a group with no subject of its own).

std::optional< OperationSubject > ew::core::foundation::operationSubjectFromString(QStringView text)

Parses a subject from its serialization form. Returns std::nullopt when text is malformed or names a kind or facet this build does not know – distinct from parsing the empty subject, which succeeds and yields std::monostate for empty input.

QString ew::core::foundation::toString(const OperationSubject &subject)

Returns the stable serialization form of subject: a kind prefix and a value, e.g. "content:2f1c…", "category:9ab0…", "facet:calendar". The empty subject serializes as an empty string. Prefixed rather than bare so a reader never has to guess which id kind a UUID is.