Entity Generator 1.1.0
Composable, deterministic entity generation for C++23
Loading...
Searching...
No Matches
dasmig::eg Class Reference

The entity generator — produces entities with configurable components. More...

#include <entitygen.hpp>

Public Member Functions

 eg ()=default
 Default constructor creates an empty generator.
 
 eg (const eg &)=delete
 Not copyable.
 
egoperator= (const eg &)=delete
 Not copyable.
 
 eg (eg &&)=default
 Move constructor.
 
egoperator= (eg &&)=default
 Move assignment.
 
 ~eg ()=default
 Default destructor.
 
Registration
egadd (std::unique_ptr< component > comp)
 Register a component.
 
egadd (std::unique_ptr< component > comp, double weight_override)
 Register a component with a weight override.
 
egweight (const std::wstring &component_key, double weight_value)
 Set or update the weight override for a registered component.
 
egremove (const std::wstring &component_key)
 Remove a registered component by key.
 
bool has (const std::wstring &component_key) const
 Check if a component is registered by key.
 
egclear ()
 Remove all registered components, weight overrides, and groups.
 
std::size_t size () const
 Return the number of registered components.
 
std::vector< std::wstring > component_keys () const
 Return all registered component keys in registration order.
 
Seeding
egseed (std::uint64_t seed_value)
 Seed the internal random engine.
 
egunseed ()
 Reseed the engine with a non-deterministic source.
 
Validation
egset_validator (std::function< bool(const entity &)> fn)
 Set an entity-level validation function.
 
egclear_validator ()
 Remove the entity-level validation function.
 
egmax_retries (std::size_t retries)
 Set the maximum number of retries for validation (default 10).
 
Observers
egadd_observer (std::shared_ptr< generation_observer > obs)
 Add an observer to receive generation lifecycle callbacks.
 
egremove_observer (const std::shared_ptr< generation_observer > &obs)
 Remove a specific observer by identity.
 
egclear_observers ()
 Remove all observers.
 
Generation
entity generate ()
 Generate an entity with all registered components.
 
entity generate (std::uint64_t call_seed) const
 Generate an entity with all registered components using a seed.
 
entity generate (std::span< const std::wstring > component_keys)
 Generate an entity with only the specified components.
 
entity generate (std::span< const std::wstring > component_keys, std::uint64_t call_seed) const
 Generate an entity with only the specified components using a seed.
 
entity generate (std::initializer_list< std::wstring > component_keys)
 Generate with an initializer list of keys (convenience overload).
 
entity generate (std::initializer_list< std::wstring > component_keys, std::uint64_t call_seed) const
 Generate with an initializer list of keys and a seed.
 
Batch Generation
std::vector< entitygenerate_batch (std::size_t count)
 Generate multiple entities with all registered components.
 
std::vector< entitygenerate_batch (std::size_t count, std::uint64_t call_seed) const
 Generate multiple entities using a seed.
 
Concurrent Batch Generation
std::vector< entitygenerate_batch_async (std::size_t count)
 Generate multiple entities concurrently.
 
std::vector< entitygenerate_batch_async (std::size_t count, std::uint64_t call_seed) const
 Generate multiple entities concurrently using a seed.
 
Component Groups
egadd_group (const std::wstring &group_name, std::vector< std::wstring > component_keys)
 Register a named group of component keys.
 
egremove_group (const std::wstring &group_name)
 Remove a named group.
 
bool has_group (const std::wstring &group_name) const
 Check if a named group exists.
 
entity generate_group (const std::wstring &group_name)
 Generate an entity using a named group.
 
entity generate_group (const std::wstring &group_name, std::uint64_t call_seed) const
 Generate an entity using a named group with a seed.
 

Static Public Member Functions

static eginstance ()
 Access the global singleton instance.
 

Detailed Description

The entity generator — produces entities with configurable components.

Components are registered by implementing the component interface and adding them to the generator. Components are generated in registration order, allowing later components to access earlier ones via context.

See also
component, entity, generation_context

Definition at line 681 of file entitygen.hpp.

Member Function Documentation

◆ add() [1/2]

eg & dasmig::eg::add ( std::unique_ptr< component comp)
inline

Register a component.

Takes ownership of the component. If a component with the same key already exists, it will be replaced. Components are generated in the order they are registered.

Parameters
compThe component to register (moved).
Returns
*this for chaining.

Definition at line 713 of file entitygen.hpp.

◆ add() [2/2]

eg & dasmig::eg::add ( std::unique_ptr< component comp,
double  weight_override 
)
inline

Register a component with a weight override.

The override takes precedence over the component's own weight() method.

Parameters
compThe component to register (moved).
weight_overrideInclusion probability override (0.0–1.0).
Returns
*this for chaining.

Definition at line 739 of file entitygen.hpp.

◆ add_group()

eg & dasmig::eg::add_group ( const std::wstring &  group_name,
std::vector< std::wstring >  component_keys 
)
inline

Register a named group of component keys.

Parameters
group_nameName for the group.
component_keysKeys in the group.
Returns
*this for chaining.

Definition at line 1123 of file entitygen.hpp.

◆ add_observer()

eg & dasmig::eg::add_observer ( std::shared_ptr< generation_observer obs)
inline

Add an observer to receive generation lifecycle callbacks.

Parameters
obsThe observer (shared ownership).
Returns
*this for chaining.
See also
generation_observer

Definition at line 884 of file entitygen.hpp.

◆ clear()

eg & dasmig::eg::clear ( )
inline

Remove all registered components, weight overrides, and groups.

Returns
*this for chaining.

Definition at line 791 of file entitygen.hpp.

◆ clear_observers()

eg & dasmig::eg::clear_observers ( )
inline

Remove all observers.

Returns
*this for chaining.

Definition at line 901 of file entitygen.hpp.

◆ clear_validator()

eg & dasmig::eg::clear_validator ( )
inline

Remove the entity-level validation function.

Returns
*this for chaining.

Definition at line 859 of file entitygen.hpp.

◆ component_keys()

std::vector< std::wstring > dasmig::eg::component_keys ( ) const
inline

Return all registered component keys in registration order.

Returns
A vector of component keys.

Definition at line 804 of file entitygen.hpp.

◆ generate() [1/6]

entity dasmig::eg::generate ( )
inline

Generate an entity with all registered components.

Uses the generator's internal engine.

Returns
The generated entity.
Exceptions
std::runtime_errorIf component or entity validation is exhausted.

Definition at line 916 of file entitygen.hpp.

◆ generate() [2/6]

entity dasmig::eg::generate ( std::initializer_list< std::wstring >  component_keys)
inline

Generate with an initializer list of keys (convenience overload).

Definition at line 967 of file entitygen.hpp.

◆ generate() [3/6]

entity dasmig::eg::generate ( std::initializer_list< std::wstring >  component_keys,
std::uint64_t  call_seed 
) const
inline

Generate with an initializer list of keys and a seed.

Definition at line 975 of file entitygen.hpp.

◆ generate() [4/6]

entity dasmig::eg::generate ( std::span< const std::wstring >  component_keys)
inline

Generate an entity with only the specified components.

Uses the generator's internal engine. Unknown keys are silently skipped.

Parameters
component_keysThe keys to include.
Returns
The generated entity.
Exceptions
std::runtime_errorIf validation is exhausted.

Definition at line 943 of file entitygen.hpp.

◆ generate() [5/6]

entity dasmig::eg::generate ( std::span< const std::wstring >  component_keys,
std::uint64_t  call_seed 
) const
inline

Generate an entity with only the specified components using a seed.

Parameters
component_keysThe keys to include.
call_seedSeed for reproducible results.
Returns
The generated entity.
Exceptions
std::runtime_errorIf validation is exhausted.

Definition at line 956 of file entitygen.hpp.

◆ generate() [6/6]

entity dasmig::eg::generate ( std::uint64_t  call_seed) const
inline

Generate an entity with all registered components using a seed.

Parameters
call_seedSeed for reproducible results.
Returns
The generated entity.
Exceptions
std::runtime_errorIf validation is exhausted.

Definition at line 928 of file entitygen.hpp.

◆ generate_batch() [1/2]

std::vector< entity > dasmig::eg::generate_batch ( std::size_t  count)
inline

Generate multiple entities with all registered components.

Parameters
countNumber of entities to generate.
Returns
A vector of generated entities.

Definition at line 990 of file entitygen.hpp.

◆ generate_batch() [2/2]

std::vector< entity > dasmig::eg::generate_batch ( std::size_t  count,
std::uint64_t  call_seed 
) const
inline

Generate multiple entities using a seed.

The seed initializes the engine once; successive entities draw from the same deterministic sequence.

Parameters
countNumber of entities to generate.
call_seedSeed for reproducible results.
Returns
A vector of generated entities.

Definition at line 1013 of file entitygen.hpp.

◆ generate_batch_async() [1/2]

std::vector< entity > dasmig::eg::generate_batch_async ( std::size_t  count)
inline

Generate multiple entities concurrently.

Entity seeds are pre-derived sequentially from the engine, then each entity is generated in its own async task. Results are returned in seed order. If observers are set, the caller is responsible for their thread safety.

Parameters
countNumber of entities to generate.
Returns
A vector of generated entities.

Definition at line 1043 of file entitygen.hpp.

◆ generate_batch_async() [2/2]

std::vector< entity > dasmig::eg::generate_batch_async ( std::size_t  count,
std::uint64_t  call_seed 
) const
inline

Generate multiple entities concurrently using a seed.

The seed initializes a dedicated engine for pre-deriving per-entity seeds; all subsequent generation is parallel.

Parameters
countNumber of entities to generate.
call_seedSeed for reproducible results.
Returns
A vector of generated entities.

Definition at line 1081 of file entitygen.hpp.

◆ generate_group() [1/2]

entity dasmig::eg::generate_group ( const std::wstring &  group_name)
inline

Generate an entity using a named group.

Parameters
group_nameThe group to generate.
Returns
The generated entity.
Exceptions
std::out_of_rangeIf the group does not exist.

Definition at line 1151 of file entitygen.hpp.

◆ generate_group() [2/2]

entity dasmig::eg::generate_group ( const std::wstring &  group_name,
std::uint64_t  call_seed 
) const
inline

Generate an entity using a named group with a seed.

Parameters
group_nameThe group to generate.
call_seedSeed for reproducible results.
Returns
The generated entity.
Exceptions
std::out_of_rangeIf the group does not exist.

Definition at line 1170 of file entitygen.hpp.

◆ has()

bool dasmig::eg::has ( const std::wstring &  component_key) const
inline

Check if a component is registered by key.

Parameters
component_keyThe component key to look up.
Returns
true if a component with the key exists.

Definition at line 782 of file entitygen.hpp.

◆ has_group()

bool dasmig::eg::has_group ( const std::wstring &  group_name) const
inline

Check if a named group exists.

Parameters
group_nameThe group name to look up.
Returns
true if the group exists.

Definition at line 1142 of file entitygen.hpp.

◆ instance()

static eg & dasmig::eg::instance ( )
inlinestatic

Access the global singleton instance.

For multi-threaded use, prefer creating independent eg instances.

Returns
A reference to the singleton.

Definition at line 697 of file entitygen.hpp.

◆ max_retries()

eg & dasmig::eg::max_retries ( std::size_t  retries)
inline

Set the maximum number of retries for validation (default 10).

Applies to both component-level and entity-level validation.

Parameters
retriesThe maximum retry count.
Returns
*this for chaining.

Definition at line 870 of file entitygen.hpp.

◆ remove()

eg & dasmig::eg::remove ( const std::wstring &  component_key)
inline

Remove a registered component by key.

Parameters
component_keyThe component key to remove.
Returns
*this for chaining.

Definition at line 766 of file entitygen.hpp.

◆ remove_group()

eg & dasmig::eg::remove_group ( const std::wstring &  group_name)
inline

Remove a named group.

Parameters
group_nameThe group to remove.
Returns
*this for chaining.

Definition at line 1133 of file entitygen.hpp.

◆ remove_observer()

eg & dasmig::eg::remove_observer ( const std::shared_ptr< generation_observer > &  obs)
inline

Remove a specific observer by identity.

Parameters
obsThe observer to remove.
Returns
*this for chaining.

Definition at line 893 of file entitygen.hpp.

◆ seed()

eg & dasmig::eg::seed ( std::uint64_t  seed_value)
inline

Seed the internal random engine.

Subsequent generate() calls without an explicit seed will draw from this seeded sequence.

Parameters
seed_valueThe seed value.
Returns
*this for chaining.

Definition at line 823 of file entitygen.hpp.

◆ set_validator()

eg & dasmig::eg::set_validator ( std::function< bool(const entity &)>  fn)
inline

Set an entity-level validation function.

After each entity is fully generated, the validator is called. If it returns false, the entity is re-generated up to max_retries times.

Parameters
fnValidator callable returning true to accept.
Returns
*this for chaining.

Definition at line 851 of file entitygen.hpp.

◆ size()

std::size_t dasmig::eg::size ( ) const
inline

Return the number of registered components.

Definition at line 800 of file entitygen.hpp.

◆ unseed()

eg & dasmig::eg::unseed ( )
inline

Reseed the engine with a non-deterministic source.

Subsequent generate() calls will produce non-reproducible results.

Returns
*this for chaining.

Definition at line 834 of file entitygen.hpp.

◆ weight()

eg & dasmig::eg::weight ( const std::wstring &  component_key,
double  weight_value 
)
inline

Set or update the weight override for a registered component.

Parameters
component_keyThe component key.
weight_valueNew inclusion probability (0.0–1.0).
Returns
*this for chaining.
Exceptions
std::out_of_rangeIf the component is not registered.

Definition at line 752 of file entitygen.hpp.


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