Entity Generator 1.1.0
Composable, deterministic entity generation for C++23
Loading...
Searching...
No Matches
dasmig::callback_component< T, GenFn, Formatter > Class Template Reference

Component that wraps a callable for one-off or computed values. More...

#include <entitygen.hpp>

Inheritance diagram for dasmig::callback_component< T, GenFn, Formatter >:
dasmig::component

Public Member Functions

 callback_component (std::wstring key, GenFn fn, Formatter fmt={})
 Construct a callback component.
 
std::wstring key () const override
 Unique key identifying this component (e.g. "name", "age").
 
std::any generate (const generation_context &ctx) const override
 Generate a random value for this component.
 
std::wstring to_string (const std::any &value) const override
 Convert a generated value to a displayable string.
 
- Public Member Functions inherited from dasmig::component
virtual ~component ()=default
 Virtual destructor for proper cleanup of derived classes.
 
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.
 

Additional Inherited Members

- Static Protected Member Functions inherited from dasmig::component
static std::wstring default_to_string (const std::any &value)
 Default conversion covering common standard types.
 

Detailed Description

template<typename T, typename GenFn, typename Formatter = use_default_formatter>
class dasmig::callback_component< T, GenFn, Formatter >

Component that wraps a callable for one-off or computed values.

Avoids subclassing component entirely. The callable receives a generation_context and returns a value of type T.

Template Parameters
TThe return type of the callable.
GenFnCallable type taking const generation_context&.
FormatterOptional callable for custom string conversion.

Definition at line 315 of file entitygen.hpp.

Constructor & Destructor Documentation

◆ callback_component()

template<typename T , typename GenFn , typename Formatter = use_default_formatter>
dasmig::callback_component< T, GenFn, Formatter >::callback_component ( std::wstring  key,
GenFn  fn,
Formatter  fmt = {} 
)
inlineexplicit

Construct a callback component.

Parameters
keyUnique component key.
fnCallable invoked during generation.
fmtOptional custom formatter.

Definition at line 322 of file entitygen.hpp.

Member Function Documentation

◆ generate()

template<typename T , typename GenFn , typename Formatter = use_default_formatter>
std::any dasmig::callback_component< T, GenFn, Formatter >::generate ( const generation_context ctx) const
inlineoverridevirtual

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.

Implements dasmig::component.

Definition at line 328 of file entitygen.hpp.

◆ key()

template<typename T , typename GenFn , typename Formatter = use_default_formatter>
std::wstring dasmig::callback_component< T, GenFn, Formatter >::key ( ) const
inlineoverridevirtual

Unique key identifying this component (e.g. "name", "age").

Returns
The component key as a wide string.

Implements dasmig::component.

Definition at line 326 of file entitygen.hpp.

◆ to_string()

template<typename T , typename GenFn , typename Formatter = use_default_formatter>
std::wstring dasmig::callback_component< T, GenFn, Formatter >::to_string ( const std::any &  value) const
inlineoverridevirtual

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()

Implements dasmig::component.

Definition at line 334 of file entitygen.hpp.


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