![]() |
Entity Generator 4.2.0
Composable, deterministic entity generation for C++23
|
Abstract base for entity components. More...
#include <entitygen.hpp>
Public Member Functions | |
| component ()=default | |
| Default constructor. | |
| component (const component &)=default | |
| Copyable. | |
| component & | operator= (const component &)=default |
| Copyable. | |
| component (component &&) noexcept=default | |
| Movable. | |
| component & | operator= (component &&) noexcept=default |
| Movable. | |
| virtual | ~component ()=default |
| Virtual destructor for proper cleanup of derived classes. | |
| virtual std::wstring | key () const =0 |
Unique key identifying this component (e.g. "name", "age"). | |
| virtual std::any | generate (const generation_context &ctx) const =0 |
| Generate a random value for this component. | |
| virtual std::wstring | to_string (const std::any &value) const =0 |
| Convert a generated value to a displayable string. | |
| virtual json_value | to_json (const std::any &value) const |
| Convert a generated value to JSON, for entity::to_json(). | |
| virtual std::wstring | label () const |
| Display name of this component, used by entity::to_string(). | |
| virtual std::vector< std::wstring > | depends_on () const |
| Keys of the components this one reads from the context. | |
| virtual std::uint64_t | data_hash () const |
| Hash of the data this component draws from, for replay. | |
| virtual double | weight () const |
| Inclusion weight for this component (0.0 to 1.0). | |
| virtual bool | validate (const std::any &value) const |
| Validate a generated value. | |
| virtual bool | should_generate (const generation_context &ctx) const |
| Decide whether this component should be generated. | |
Static Protected Member Functions | |
| static std::wstring | default_to_string (const std::any &value) |
| Default conversion covering common standard types. | |
| static json_value | default_to_json (const std::any &value, const std::wstring &display) |
| Default JSON conversion used by to_json(). | |
Abstract base for entity components.
Implement this interface to define custom components that the entity generator can produce. Each component has a unique key, generates typed random values, and converts them to display strings.
Definition at line 293 of file entitygen.hpp.
|
inlinevirtual |
Hash of the data this component draws from, for replay.
A component that calls a generator with data returns that generator's data_hash(). entity::signature() combines the hashes of the components that ran, so a replay shows whether the data changed.
Reimplemented in dasmig::field_component< T >.
Definition at line 359 of file entitygen.hpp.
|
inlinestaticprotected |
Default JSON conversion used by to_json().
| value | The value to convert. |
| display | Its to_string() form, used for unrecognized types. |
Definition at line 453 of file entitygen.hpp.
|
inlinestaticprotected |
Default conversion covering common standard types.
Handles std::wstring, std::string (UTF-8), bool, float, double and the integer types int, long, long long and their unsigned forms. Returns "[?]" for unrecognized types.
| value | The value to convert. |
Definition at line 399 of file entitygen.hpp.
|
inlinevirtual |
Keys of the components this one reads from the context.
A request that selects this component also generates its dependencies (transitively) and orders them before it, whatever the registration order. If a dependency is skipped (weight roll or should_generate()), this component is skipped too. A dependency that is not registered, or a cycle, makes generation throw.
Reimplemented in dasmig::field_component< T >.
Definition at line 351 of file entitygen.hpp.
|
pure virtual |
Generate a random value for this component.
| ctx | Context providing access to previously generated values and a seeded random engine. |
std::any. Implemented in dasmig::constant_component< T, Formatter >, dasmig::choice_component< T, Formatter >, dasmig::range_component< T, Formatter >, dasmig::callback_component< T, GenFn, Formatter >, dasmig::field_component< T >, and dasmig::weighted_choice_component< T, Formatter >.
|
pure virtual |
Unique key identifying this component (e.g. "name", "age").
Implemented in dasmig::constant_component< T, Formatter >, dasmig::choice_component< T, Formatter >, dasmig::range_component< T, Formatter >, dasmig::callback_component< T, GenFn, Formatter >, dasmig::field_component< T >, and dasmig::weighted_choice_component< T, Formatter >.
|
inlinevirtual |
Display name of this component, used by entity::to_string().
The key stays the identifier (lookups, seeds, JSON). A key with dots is a path: L"identity.age" is written as {"identity":{"age":..}}.
Reimplemented in dasmig::field_component< T >.
Definition at line 341 of file entitygen.hpp.
|
inlinevirtual |
Decide whether this component should be generated.
Unlike weight() (probabilistic), this is logic-driven. Return false to skip generation entirely based on the current context.
| ctx | Context with previously generated component values. |
true to generate, false to skip. Reimplemented in dasmig::field_component< T >.
Definition at line 385 of file entitygen.hpp.
|
inlinevirtual |
Convert a generated value to JSON, for entity::to_json().
The default writes bool as a boolean, integers as integers, double and float as numbers (non-finite ones as null), std::wstring and std::string as strings, and anything else as the string from to_string(). Override it to write a richer value: a json_value can hold arrays and objects.
| value | The value previously returned by generate(). |
Reimplemented in dasmig::field_component< T >.
Definition at line 331 of file entitygen.hpp.
|
pure virtual |
Convert a generated value to a displayable string.
| value | The value previously returned by generate(). |
Implemented in dasmig::constant_component< T, Formatter >, dasmig::choice_component< T, Formatter >, dasmig::range_component< T, Formatter >, dasmig::callback_component< T, GenFn, Formatter >, dasmig::field_component< T >, and dasmig::weighted_choice_component< T, Formatter >.
|
inlinevirtual |
Validate a generated value.
| value | The value to validate. |
true to accept, false to retry generation. Reimplemented in dasmig::field_component< T >.
Definition at line 374 of file entitygen.hpp.
|
inlinevirtual |
Inclusion weight for this component (0.0 to 1.0).
A value of 1.0 means always included; 0.5 means included roughly half the time. The generator may override this per-component at registration time via eg::add(comp, weight) or eg::weight().
Reimplemented in dasmig::field_component< T >.
Definition at line 368 of file entitygen.hpp.