|
Entity Generator 1.1.0
Composable, deterministic entity generation for C++23
|
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. | |
| eg & | operator= (const eg &)=delete |
| Not copyable. | |
| eg (eg &&)=default | |
| Move constructor. | |
| eg & | operator= (eg &&)=default |
| Move assignment. | |
| ~eg ()=default | |
| Default destructor. | |
Registration | |
| eg & | add (std::unique_ptr< component > comp) |
| Register a component. | |
| eg & | add (std::unique_ptr< component > comp, double weight_override) |
| Register a component with a weight override. | |
| eg & | weight (const std::wstring &component_key, double weight_value) |
| Set or update the weight override for a registered component. | |
| eg & | remove (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. | |
| eg & | clear () |
| 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 | |
| eg & | seed (std::uint64_t seed_value) |
| Seed the internal random engine. | |
| eg & | unseed () |
| Reseed the engine with a non-deterministic source. | |
Validation | |
| eg & | set_validator (std::function< bool(const entity &)> fn) |
| Set an entity-level validation function. | |
| eg & | clear_validator () |
| Remove the entity-level validation function. | |
| eg & | max_retries (std::size_t retries) |
| Set the maximum number of retries for validation (default 10). | |
Observers | |
| eg & | add_observer (std::shared_ptr< generation_observer > obs) |
| Add an observer to receive generation lifecycle callbacks. | |
| eg & | remove_observer (const std::shared_ptr< generation_observer > &obs) |
| Remove a specific observer by identity. | |
| eg & | clear_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< entity > | generate_batch (std::size_t count) |
| Generate multiple entities with all registered components. | |
| std::vector< entity > | generate_batch (std::size_t count, std::uint64_t call_seed) const |
| Generate multiple entities using a seed. | |
Concurrent Batch Generation | |
| std::vector< entity > | generate_batch_async (std::size_t count) |
| Generate multiple entities concurrently. | |
| std::vector< entity > | generate_batch_async (std::size_t count, std::uint64_t call_seed) const |
| Generate multiple entities concurrently using a seed. | |
Component Groups | |
| eg & | add_group (const std::wstring &group_name, std::vector< std::wstring > component_keys) |
| Register a named group of component keys. | |
| eg & | remove_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 eg & | instance () |
| Access the global singleton instance. | |
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.
Definition at line 681 of file entitygen.hpp.
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.
| comp | The component to register (moved). |
*this for chaining. Definition at line 713 of file entitygen.hpp.
Register a component with a weight override.
The override takes precedence over the component's own weight() method.
| comp | The component to register (moved). |
| weight_override | Inclusion probability override (0.0–1.0). |
*this for chaining. Definition at line 739 of file entitygen.hpp.
|
inline |
Register a named group of component keys.
| group_name | Name for the group. |
| component_keys | Keys in the group. |
*this for chaining. Definition at line 1123 of file entitygen.hpp.
|
inline |
Add an observer to receive generation lifecycle callbacks.
| obs | The observer (shared ownership). |
*this for chaining. Definition at line 884 of file entitygen.hpp.
|
inline |
Remove all registered components, weight overrides, and groups.
*this for chaining. Definition at line 791 of file entitygen.hpp.
|
inline |
|
inline |
Remove the entity-level validation function.
*this for chaining. Definition at line 859 of file entitygen.hpp.
|
inline |
Return all registered component keys in registration order.
Definition at line 804 of file entitygen.hpp.
|
inline |
Generate an entity with all registered components.
Uses the generator's internal engine.
| std::runtime_error | If component or entity validation is exhausted. |
Definition at line 916 of file entitygen.hpp.
|
inline |
Generate with an initializer list of keys (convenience overload).
Definition at line 967 of file entitygen.hpp.
|
inline |
Generate with an initializer list of keys and a seed.
Definition at line 975 of file entitygen.hpp.
|
inline |
Generate an entity with only the specified components.
Uses the generator's internal engine. Unknown keys are silently skipped.
| component_keys | The keys to include. |
| std::runtime_error | If validation is exhausted. |
Definition at line 943 of file entitygen.hpp.
|
inline |
Generate an entity with only the specified components using a seed.
| component_keys | The keys to include. |
| call_seed | Seed for reproducible results. |
| std::runtime_error | If validation is exhausted. |
Definition at line 956 of file entitygen.hpp.
|
inline |
Generate an entity with all registered components using a seed.
| call_seed | Seed for reproducible results. |
| std::runtime_error | If validation is exhausted. |
Definition at line 928 of file entitygen.hpp.
|
inline |
Generate multiple entities with all registered components.
| count | Number of entities to generate. |
Definition at line 990 of file entitygen.hpp.
|
inline |
Generate multiple entities using a seed.
The seed initializes the engine once; successive entities draw from the same deterministic sequence.
| count | Number of entities to generate. |
| call_seed | Seed for reproducible results. |
Definition at line 1013 of file entitygen.hpp.
|
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.
| count | Number of entities to generate. |
Definition at line 1043 of file entitygen.hpp.
|
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.
| count | Number of entities to generate. |
| call_seed | Seed for reproducible results. |
Definition at line 1081 of file entitygen.hpp.
|
inline |
Generate an entity using a named group.
| group_name | The group to generate. |
| std::out_of_range | If the group does not exist. |
Definition at line 1151 of file entitygen.hpp.
|
inline |
Generate an entity using a named group with a seed.
| group_name | The group to generate. |
| call_seed | Seed for reproducible results. |
| std::out_of_range | If the group does not exist. |
Definition at line 1170 of file entitygen.hpp.
|
inline |
Check if a component is registered by key.
| component_key | The component key to look up. |
true if a component with the key exists. Definition at line 782 of file entitygen.hpp.
|
inline |
Check if a named group exists.
| group_name | The group name to look up. |
true if the group exists. Definition at line 1142 of file entitygen.hpp.
|
inlinestatic |
Access the global singleton instance.
For multi-threaded use, prefer creating independent eg instances.
Definition at line 697 of file entitygen.hpp.
|
inline |
Set the maximum number of retries for validation (default 10).
Applies to both component-level and entity-level validation.
| retries | The maximum retry count. |
*this for chaining. Definition at line 870 of file entitygen.hpp.
|
inline |
Remove a registered component by key.
| component_key | The component key to remove. |
*this for chaining. Definition at line 766 of file entitygen.hpp.
|
inline |
Remove a named group.
| group_name | The group to remove. |
*this for chaining. Definition at line 1133 of file entitygen.hpp.
|
inline |
Remove a specific observer by identity.
| obs | The observer to remove. |
*this for chaining. Definition at line 893 of file entitygen.hpp.
|
inline |
Seed the internal random engine.
Subsequent generate() calls without an explicit seed will draw from this seeded sequence.
| seed_value | The seed value. |
*this for chaining. Definition at line 823 of file entitygen.hpp.
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.
| fn | Validator callable returning true to accept. |
*this for chaining. Definition at line 851 of file entitygen.hpp.
|
inline |
Return the number of registered components.
Definition at line 800 of file entitygen.hpp.
|
inline |
Reseed the engine with a non-deterministic source.
Subsequent generate() calls will produce non-reproducible results.
*this for chaining. Definition at line 834 of file entitygen.hpp.
|
inline |
Set or update the weight override for a registered component.
| component_key | The component key. |
| weight_value | New inclusion probability (0.0–1.0). |
*this for chaining. | std::out_of_range | If the component is not registered. |
Definition at line 752 of file entitygen.hpp.