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;
}
A parser result, which may contain a result of type T, or an error, or both.
Definition ParseResult.h:17
entt::entity Entity
Entity type for the Registry, a std::uint32_t alias.
Definition EcsRegistry.h:16
Helper to guard against recursion when evaluating references.
Definition RecursionGuard.h:41

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

Entity next = getNext(current);
if (next != entt::null) {
doSomething(next, guard.with(next));
}
}

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: