Taxonomy.h header

#include <ew/core/Taxonomy.h>

Namespace ew::core

Taxonomy class

class ew::core::Taxonomy

The user-defined codex taxonomy: the tree of Categories for a project. It owns the categories and answers structural queries (roots, children). Categories are keyed by id in a std::map so on-disk order is stable and diff-friendly. Removing a category promotes its children to its former parent so the tree stays connected. (Field inheritance across the tree is layered on in a later step.)

Members

ew::core::Taxonomy::Taxonomy()

Constructs an empty taxonomy.

ew::core::Taxonomy::~Taxonomy()

Destroys the taxonomy and its categories.

ew::core::Taxonomy::Taxonomy(const Taxonomy &)=delete

Not copyable.

ew::core::Taxonomy::Taxonomy(Taxonomy &&)=delete

Not movable.

Taxonomy & ew::core::Taxonomy::operator=(const Taxonomy &)=delete

Not copyable.

Taxonomy & ew::core::Taxonomy::operator=(Taxonomy &&)=delete

Not movable.

bool ew::core::Taxonomy::add(Category category)

Adds category. Returns false (and changes nothing) if its id already exists.

bool ew::core::Taxonomy::remove(CategoryId id)

Removes the category with id, promoting its children to its former parent. Returns true if a category was removed.

bool ew::core::Taxonomy::contains(CategoryId id) const

Returns true if a category with id exists.

const Category * ew::core::Taxonomy::find(CategoryId id) const

Returns the category with id, or nullptr if none.

Category * ew::core::Taxonomy::find(CategoryId id)

Returns the mutable category with id (for editing), or nullptr if none.

int ew::core::Taxonomy::categoryCount() const

The number of categories in the taxonomy.

std::vector< CategoryId > ew::core::Taxonomy::ids() const

All category ids, in stable (id-sorted) order.

std::vector< const Category * > ew::core::Taxonomy::roots() const

The root categories (those with no parent), in id-sorted order.

std::vector< const Category * > ew::core::Taxonomy::children(CategoryId id) const

The direct children of the category with id, in id-sorted order.

std::vector< FieldDefinition > ew::core::Taxonomy::effectiveFields(CategoryId id) const

The fields that apply to the category with id: its own fields plus every ancestor's, ordered from the root down, with a descendant's field overriding an ancestor's when they share a key. Empty if id is unknown. Cycle-safe.

Result< void > ew::core::Taxonomy::reparent(CategoryId child, CategoryId newParent)

Reparents child under newParent (a null id makes it a root). Fails if child or a non-null newParent is unknown, or if the move would create a cycle (newParent is child or one of its descendants).