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

Abstract base for entity components. More...

#include <entitygen.hpp>

Inheritance diagram for dasmig::component:
dasmig::callback_component< T, GenFn, Formatter > dasmig::choice_component< T, Formatter > dasmig::constant_component< T, Formatter > dasmig::range_component< T, Formatter > dasmig::weighted_choice_component< T, Formatter >

Public Member Functions

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 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.
 

Detailed Description

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.

See also
generation_context, eg::add()

Definition at line 87 of file entitygen.hpp.

Member Function Documentation

◆ default_to_string()

static std::wstring dasmig::component::default_to_string ( const std::any &  value)
inlinestaticprotected

Default conversion covering common standard types.

Handles std::wstring, int, double, float, long, and bool. Returns "[?]" for unrecognized types.

Parameters
valueThe value to convert.
Returns
A wide-string representation.

Definition at line 147 of file entitygen.hpp.

◆ generate()

virtual std::any dasmig::component::generate ( const generation_context ctx) const
pure virtual

Generate a random value for this component.

Parameters
ctxContext providing access to previously generated values and a seeded random engine.
Returns
The generated value wrapped in 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 >, and dasmig::weighted_choice_component< T, Formatter >.

◆ key()

virtual std::wstring dasmig::component::key ( ) const
pure virtual

◆ should_generate()

virtual bool dasmig::component::should_generate ( const generation_context ctx) const
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.

Parameters
ctxContext with previously generated component values.
Returns
true to generate, false to skip.

Definition at line 134 of file entitygen.hpp.

◆ to_string()

virtual std::wstring dasmig::component::to_string ( const std::any &  value) const
pure virtual

Convert a generated value to a displayable string.

Parameters
valueThe value previously returned by generate().
Returns
A human-readable wide-string representation.
See also
default_to_string()

Implemented in dasmig::constant_component< T, Formatter >, dasmig::choice_component< T, Formatter >, dasmig::range_component< T, Formatter >, dasmig::callback_component< T, GenFn, Formatter >, and dasmig::weighted_choice_component< T, Formatter >.

◆ validate()

virtual bool dasmig::component::validate ( const std::any &  value) const
inlinevirtual

Validate a generated value.

Parameters
valueThe value to validate.
Returns
true to accept, false to retry generation.
See also
eg::max_retries()

Definition at line 123 of file entitygen.hpp.

◆ weight()

virtual double dasmig::component::weight ( ) const
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().

Returns
The inclusion probability.
See also
eg::weight()

Definition at line 117 of file entitygen.hpp.


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