Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::RecursionGuard Struct Reference

Helper to guard against recursion when evaluating references. More...

#include "donner/svg/graph/RecursionGuard.h"

Public Member Functions

 RecursionGuard ()=default
 efault constructor.
 
bool hasRecursion (Entity entity) const
 Returns true if this entity has been seen before, indicating a cycle has been detected.
 
void add (Entity entity)
 Add the given entity to the set of entities that have been seen.
 
RecursionGuard with (Entity entity) const
 Create a new RecursionGuard with the given entity added to the set of entities that have been seen.
 

Detailed Description

Helper to guard against recursion when evaluating references.

This is used to prevent infinite recursion when reference hierarchies contain cycles.

Usage:

Entity current = ...;
while (current) {
Entity target = getTarget(current);
if (guard.hasRecursion(target)) {
break;
}
guard.add(target);
current = target;
}
entt::entity Entity
Entity type for the SVG Registry, a std::uint32_t alias.
Definition Registry.h:16
Helper to guard against recursion when evaluating references.
Definition RecursionGuard.h:41
bool hasRecursion(Entity entity) const
Returns true if this entity has been seen before, indicating a cycle has been detected.
Definition RecursionGuard.h:50
void add(Entity entity)
Add the given entity to the set of entities that have been seen.
Definition RecursionGuard.h:57

There is also a shorthand when passing a RecursionGuard as a parameter:

void doSomething(Entity element, RecursionGuard guard) {
Entity next = getNext(current);
if (next != entt::null) {
doSomething(next, guard.with(next));
}
}
RecursionGuard with(Entity entity) const
Create a new RecursionGuard with the given entity added to the set of entities that have been seen.
Definition RecursionGuard.h:68

Member Function Documentation

◆ add()

void donner::svg::RecursionGuard::add ( Entity entity)
inline

Add the given entity to the set of entities that have been seen.

Parameters
entityEntity to add.

◆ hasRecursion()

bool donner::svg::RecursionGuard::hasRecursion ( Entity entity) const
inline

Returns true if this entity has been seen before, indicating a cycle has been detected.

Parameters
entityEntity to check.

◆ with()

RecursionGuard donner::svg::RecursionGuard::with ( Entity entity) const
inline

Create a new RecursionGuard with the given entity added to the set of entities that have been seen.

Parameters
entityEntity to add.

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