qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::CoreInitializer::ActorBuilder Class Reference

Helper to fluently build multiple Actors for a CoreInitializer. More...

#include <Main.h>

Public Types

using ActorIdList = std::vector<ActorId>

Public Member Functions

 ActorBuilder (ActorBuilder const &rhs)=default
template<typename _Actor, typename... _Args>
ActorBuilderaddActor (_Args &&...args) noexcept
 Create and add a new _Actor to the VirtualCore associated with this builder.
bool valid () const noexcept
 Checks if all actor additions via this builder were successful up to this point.
 operator bool () const noexcept
 Explicit boolean conversion, equivalent to calling valid().
ActorIdList idList () const noexcept
 Get the list of ActorIds created by this ActorBuilder instance.

Detailed Description

Helper to fluently build multiple Actors for a CoreInitializer.

Provides a chained interface to add multiple actors to a specific VirtualCore during the setup phase via its CoreInitializer.

Member Function Documentation

◆ addActor()

template<typename _Actor, typename... _Args>
ActorBuilder & qb::CoreInitializer::ActorBuilder::addActor ( _Args &&... args)
noexcept

Create and add a new _Actor to the VirtualCore associated with this builder.

Template Parameters
_ActorDerivedActor type to create.
_ArgsArguments to forward to the constructor of the _Actor.
Parameters
argsArguments to forward to the _Actor's constructor.
Returns
Reference to this ActorBuilder for method chaining.

Creates a new _Actor on the attached VirtualCore. This function can be chained to add multiple actors in a single statement. Example:

// auto builder = main.core(0).builder(); // Get actor builder
// builder.addActor<MyActor1>(param1, param2)
// .addActor<MyActor2>(arg_a)
// .addActor<MyServiceActor>();
Attention
This function is only available before the engine is running. If actor creation fails (e.g. duplicate ServiceActor, max actors reached), the valid() state of the builder will become false.

◆ valid()

bool qb::CoreInitializer::ActorBuilder::valid ( ) const
nodiscardnoexcept

Checks if all actor additions via this builder were successful up to this point.

Returns
true if all preceding addActor() calls on this builder instance succeeded, false if any actor creation failed (e.g., duplicate ServiceActor, max actors, or internal error).

If this returns false, subsequent calls to addActor() on this builder may also effectively fail or might not add to the idList().

◆ operator bool()

qb::CoreInitializer::ActorBuilder::operator bool ( ) const
explicitnoexcept

Explicit boolean conversion, equivalent to calling valid().

Returns
true if the builder is in a valid state (all actor additions succeeded so far), false otherwise.
See also
valid()

◆ idList()

ActorIdList qb::CoreInitializer::ActorBuilder::idList ( ) const
nodiscardnoexcept

Get the list of ActorIds created by this ActorBuilder instance.

Returns
An ActorIdList (std::vector<ActorId>) containing the IDs of all actors successfully created by this builder instance up to the point of calling, in the order of creation. If valid() is false, this list may not contain all attempted actors or may be incomplete.