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

A generated entity holding component values in registration order. More...

#include <entitygen.hpp>

Public Member Functions

template<typename T >
T get (const std::wstring &component_key) const
 Typed retrieval of a component value by key.
 
const std::any & get_any (const std::wstring &component_key) const
 Type-erased retrieval of a component value by key.
 
bool has (const std::wstring &component_key) const
 Check if a component value exists by key.
 
std::uint64_t seed (const std::wstring &component_key) const
 Retrieve the random seed used to generate a specific component.
 
std::uint64_t seed () const
 Retrieve the random seed used to generate this entity.
 
core::seed_signature signature () const
 The seed and the data this entity was generated from, in the format every dasmig result uses.
 
void to_json (core::json_writer &w) const
 Write this entity as a JSON object {"components":{"key":value,…},"signature":{…}}, components in generation order, values from component::to_json().
 
std::string to_json () const
 This entity as a JSON document.
 
std::vector< std::wstring > keys () const
 Get all component keys present in this entity, in generation order.
 
std::map< std::wstring, std::wstring > to_map () const
 Return component values as a map of key to display string.
 
std::size_t size () const
 Number of component values in this entity.
 
bool empty () const
 Check if the entity has no component values.
 
std::wstring to_string () const
 Convert all component values to a single formatted string.
 

Friends

class eg
 
std::wostream & operator<< (std::wostream &wos, const entity &e)
 Stream all component values in generation order.
 

Detailed Description

A generated entity holding component values in registration order.

Entities are produced by eg::generate and provide typed access to component values, seed signatures for replay, and serialization.

See also
eg::generate

Definition at line 898 of file entitygen.hpp.

Member Function Documentation

◆ empty()

bool dasmig::entity::empty ( ) const
inline

Check if the entity has no component values.

Definition at line 1025 of file entitygen.hpp.

◆ get()

template<typename T >
T dasmig::entity::get ( const std::wstring &  component_key) const
inline

Typed retrieval of a component value by key.

Template Parameters
TThe expected type of the stored value.
Parameters
component_keyThe component key to retrieve.
Returns
The value cast to T.
Exceptions
std::out_of_rangeIf the key is not present.
std::bad_any_castIf T does not match the stored type.

Definition at line 908 of file entitygen.hpp.

◆ get_any()

const std::any & dasmig::entity::get_any ( const std::wstring &  component_key) const
inline

Type-erased retrieval of a component value by key.

Parameters
component_keyThe component key to retrieve.
Returns
A const reference to the stored std::any.
Exceptions
std::out_of_rangeIf the key is not present.

Definition at line 917 of file entitygen.hpp.

◆ has()

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

Check if a component value exists by key.

Parameters
component_keyThe component key to look up.
Returns
true if the entity contains a value for the key.

Definition at line 925 of file entitygen.hpp.

◆ keys()

std::vector< std::wstring > dasmig::entity::keys ( ) const
inline

Get all component keys present in this entity, in generation order.

Returns
A vector of component keys.

Definition at line 1001 of file entitygen.hpp.

◆ seed() [1/2]

std::uint64_t dasmig::entity::seed ( ) const
inline

Retrieve the random seed used to generate this entity.

eg::generate(request, seed()) with the same request and setup reproduces the entity: it is the call seed, or the seed of the attempt the entity validator accepted. Component k drew from core::rng{seed()}.split(core::to_utf8(k)).

Returns
The entity-level seed.

Definition at line 956 of file entitygen.hpp.

◆ seed() [2/2]

std::uint64_t dasmig::entity::seed ( const std::wstring &  component_key) const
inline

Retrieve the random seed used to generate a specific component.

Parameters
component_keyThe component key.
Returns
The per-component seed for replay.
Exceptions
std::out_of_rangeIf the key is not present.

Definition at line 936 of file entitygen.hpp.

◆ signature()

core::seed_signature dasmig::entity::signature ( ) const
inline

The seed and the data this entity was generated from, in the format every dasmig result uses.

Returns
The replay signature. data combines the request's inputs and the component::data_hash() of every component that ran; it is 0 when there are none, as for a generator without data.

Definition at line 966 of file entitygen.hpp.

◆ size()

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

Number of component values in this entity.

Definition at line 1022 of file entitygen.hpp.

◆ to_json() [1/2]

std::string dasmig::entity::to_json ( ) const
inline

This entity as a JSON document.

Returns
Compact JSON.

Definition at line 992 of file entitygen.hpp.

◆ to_json() [2/2]

void dasmig::entity::to_json ( core::json_writer &  w) const
inline

Write this entity as a JSON object {"components":{"key":value,…},"signature":{…}}, components in generation order, values from component::to_json().

A key with dots is a path: identity.name and identity.age are written as members of one identity object, placed where its first member comes.

Parameters
wWriter positioned where a value is allowed.

Definition at line 979 of file entitygen.hpp.

◆ to_map()

std::map< std::wstring, std::wstring > dasmig::entity::to_map ( ) const
inline

Return component values as a map of key to display string.

Returns
An ordered map of key → formatted value.

Definition at line 1011 of file entitygen.hpp.

◆ to_string()

std::wstring dasmig::entity::to_string ( ) const
inline

Convert all component values to a single formatted string.

Each entry is rendered as "label: display" separated by two spaces.

Returns
The formatted string, or empty if the entity is empty.

Definition at line 1031 of file entitygen.hpp.

Friends And Related Symbol Documentation

◆ eg

friend class eg
friend

Definition at line 1111 of file entitygen.hpp.

◆ operator<<

std::wostream & operator<< ( std::wostream &  wos,
const entity &  e 
)
friend

Stream all component values in generation order.

Definition at line 1045 of file entitygen.hpp.


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