EntityGroupManager
EntityGroupManager
Manages user-defined groups of EntityIds for cross-data linking and visualization. More…
#include <EntityGroupManager.hpp>
Public Functions
| Name | |
|---|---|
| GroupId | createGroup(std::string const & name, std::string const & description =““) Create a new empty group with the given name. |
| bool | deleteGroup(GroupId group_id) Delete a group and all its entities. |
| bool | hasGroup(GroupId group_id) const Check if a group exists. |
| std::optional< GroupDescriptor > | getGroupDescriptor(GroupId group_id) const Get information about a group. |
| bool | updateGroup(GroupId group_id, std::string const & name, std::string const & description =““) Update the name and/or description of a group. |
| std::vector< GroupId > | getAllGroupIds() const Get all group IDs. |
| std::vector< GroupDescriptor > | getAllGroupDescriptors() const Get all group descriptors. |
| bool | addEntityToGroup(GroupId group_id, EntityId entity_id) Add a single entity to a group. |
| std::size_t | addEntitiesToGroup(GroupId group_id, std::ranges::range auto const & entity_ids) Add multiple entities to a group. |
| bool | removeEntityFromGroup(GroupId group_id, EntityId entity_id) Remove a single entity from a group. |
| std::size_t | removeEntitiesFromGroup(GroupId group_id, std::vector< EntityId > const & entity_ids) Remove multiple entities from a group. |
| std::vector< EntityId > | getEntitiesInGroup(GroupId group_id) const Get all entities in a group. |
| bool | isEntityInGroup(GroupId group_id, EntityId entity_id) const Check if an entity is in a specific group. |
| std::vector< GroupId > | getGroupsContainingEntity(EntityId entity_id) const Get all groups that contain a specific entity. |
| std::size_t | getGroupSize(GroupId group_id) const Get the number of entities in a group. |
| bool | clearGroup(GroupId group_id) Clear all entities from a group without deleting the group. |
| void | clear() Clear all groups and entities (session reset). |
| std::size_t | getGroupCount() const Get total number of groups. |
| std::size_t | getTotalEntityCount() const Get total number of unique entities across all groups. |
| ObserverData & | getGroupObservers() Access the observer sink for group changes. Subscribers will be notified when notifyGroupsChanged() is called. |
| void | notifyGroupsChanged() Notify observers that group membership or descriptors changed. Call this once after bulk updates to avoid excessive UI refreshes. |
| uint64_t | generation() const Get the current generation counter. |
Detailed Description
class EntityGroupManager;Manages user-defined groups of EntityIds for cross-data linking and visualization.
Note: Thread Safety: This class is not thread-safe. Callers must synchronize access when using from multiple threads. Consider wrapping operations in a mutex or using from a single thread (e.g., the Qt UI thread).
This class provides fast lookup and manipulation of entity groups to support linking data across different formats (e.g., from TableView rows back to raw LineData). Optimized for hundreds of thousands of entities with O(1) group operations.
Public Functions Documentation
function createGroup
GroupId createGroup(
std::string const & name,
std::string const & description =""
)Create a new empty group with the given name.
Parameters:
- name User-friendly name for the group (empty allowed).
- description Optional description for the group (default ““).
Return: GroupId of the created group (never 0; 0 is reserved for invalid).
Note: Does not check for an existing group with the same name; each call creates a new group and returns a new id. Duplicate names are allowed.
No preconditions on name or description; both are stored as-is.
function deleteGroup
bool deleteGroup(
GroupId group_id
)Delete a group and all its entities.
Parameters:
- group_id The group to delete (e.g. from createGroup or getAllGroupIds).
Return: True if the group existed and was deleted, false if the group did not exist.
No preconditions on group_id; any GroupId is valid. Non-existent id returns false.
function hasGroup
bool hasGroup(
GroupId group_id
) constCheck if a group exists.
Parameters:
- group_id The group to check (e.g. from createGroup or getAllGroupIds).
Return: True if the group exists, false otherwise.
No preconditions on group_id; any GroupId is valid. Non-existent id returns false.
function getGroupDescriptor
std::optional< GroupDescriptor > getGroupDescriptor(
GroupId group_id
) constGet information about a group.
Parameters:
- group_id The group to query (e.g. from createGroup or getAllGroupIds).
Return: GroupDescriptor if the group exists, std::nullopt otherwise.
No preconditions on group_id; any GroupId is valid. Non-existent id returns nullopt.
function updateGroup
bool updateGroup(
GroupId group_id,
std::string const & name,
std::string const & description =""
)Update the name and/or description of a group.
Parameters:
- group_id The group to update (e.g. from createGroup or getAllGroupIds).
- name New name for the group (empty allowed).
- description New description for the group (default ““).
Return: True if the group existed and was updated, false if the group did not exist.
No preconditions on group_id, name, or description. Non-existent group_id returns false.
function getAllGroupIds
std::vector< GroupId > getAllGroupIds() constGet all group IDs.
Return: Vector of all existing group IDs (empty if no groups exist).
function getAllGroupDescriptors
std::vector< GroupDescriptor > getAllGroupDescriptors() constGet all group descriptors.
Return: Vector of all group descriptors
function addEntityToGroup
bool addEntityToGroup(
GroupId group_id,
EntityId entity_id
)Add a single entity to a group.
Parameters:
- group_id The group to add to (e.g. from createGroup or getAllGroupIds).
- entity_id The entity to add (any EntityId; e.g. from EntityRegistry::ensureId).
Return: True if the entity was added (group exists and entity was not already in group), false if the group does not exist or the entity was already in the group.
No preconditions on group_id or entity_id. Non-existent group returns false.
function addEntitiesToGroup
inline std::size_t addEntitiesToGroup(
GroupId group_id,
std::ranges::range auto const & entity_ids
)Add multiple entities to a group.
Parameters:
- group_id The group to add to (e.g. from createGroup or getAllGroupIds).
- entity_ids The entities to add (empty range is valid; duplicates are skipped).
Template Parameters:
- Range A range type satisfying std::ranges::range whose elements are EntityId.
Return: Number of entities successfully added (0 if group does not exist).
No preconditions on group_id or entity_ids. Non-existent group returns 0.
function removeEntityFromGroup
bool removeEntityFromGroup(
GroupId group_id,
EntityId entity_id
)Remove a single entity from a group.
Parameters:
- group_id The group to remove from
- entity_id The entity to remove
Return: True if the entity was removed (group exists and entity was in group), false otherwise
function removeEntitiesFromGroup
std::size_t removeEntitiesFromGroup(
GroupId group_id,
std::vector< EntityId > const & entity_ids
)Remove multiple entities from a group.
Parameters:
- group_id The group to remove from
- entity_ids The entities to remove
Return: Number of entities successfully removed
function getEntitiesInGroup
std::vector< EntityId > getEntitiesInGroup(
GroupId group_id
) constGet all entities in a group.
Parameters:
- group_id The group to query
Return: Vector of EntityIds in the group, empty if group doesn’t exist
function isEntityInGroup
bool isEntityInGroup(
GroupId group_id,
EntityId entity_id
) constCheck if an entity is in a specific group.
Parameters:
- group_id The group to check
- entity_id The entity to check
Return: True if the entity is in the group, false otherwise
function getGroupsContainingEntity
std::vector< GroupId > getGroupsContainingEntity(
EntityId entity_id
) constGet all groups that contain a specific entity.
Parameters:
- entity_id The entity to query
Return: Vector of GroupIds that contain the entity
function getGroupSize
std::size_t getGroupSize(
GroupId group_id
) constGet the number of entities in a group.
Parameters:
- group_id The group to query
Return: Number of entities in the group, 0 if group doesn’t exist
function clearGroup
bool clearGroup(
GroupId group_id
)Clear all entities from a group without deleting the group.
Parameters:
- group_id The group to clear
Return: True if the group existed and was cleared, false otherwise
function clear
void clear()Clear all groups and entities (session reset).
function getGroupCount
std::size_t getGroupCount() constGet total number of groups.
Return: Number of groups
function getTotalEntityCount
std::size_t getTotalEntityCount() constGet total number of unique entities across all groups.
Return: Number of unique entities
function getGroupObservers
inline ObserverData & getGroupObservers()Access the observer sink for group changes. Subscribers will be notified when notifyGroupsChanged() is called.
function notifyGroupsChanged
inline void notifyGroupsChanged()Notify observers that group membership or descriptors changed. Call this once after bulk updates to avoid excessive UI refreshes.
function generation
inline uint64_t generation() constGet the current generation counter.
Return: Monotonically increasing generation counter
The generation is incremented on every call to notifyGroupsChanged(). Widgets can cache this value and compare on each paint frame to detect changes without connecting to observer signals.
Updated on 2026-11-13 at 20:25:40 +0000