Name Generator 4.5.2
Culture-aware name generation for C++23
Loading...
Searching...
No Matches
dasmig::ng Class Reference

Name generator that produces culture-aware names and surnames. More...

#include <namegen.hpp>

Public Member Functions

 ng ()=default
 Default constructor — creates an empty generator with no names.
 
 ng (const ng &)=delete
 Not copyable.
 
ng & operator= (const ng &)=delete
 Not copyable.
 
 ng (ng &&) noexcept=default
 Move constructor.
 
ng & operator= (ng &&) noexcept=default
 Move assignment.
 
 ~ng ()=default
 Default destructor.
 
name get_name (const name_request &request)
 Generate a first name.
 
name get_name (const name_request &request, std::uint64_t call_seed) const
 Generate a deterministic first name using a specific seed.
 
std::vector< name > get_name_batch (const name_request &request, const core::batch_options &options)
 Generate a batch of name results from a seed drawn like get_name() draws its own.
 
std::vector< name > get_name_batch (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed) const
 Generate a batch of name results, deterministically.
 
template<typename Sink >
void for_each_name (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const
 Stream a batch of name results to a sink without holding the whole batch.
 
template<typename Sink >
void for_each_name (const name_request &request, const core::batch_options &options, Sink &&sink)
 Stream a batch of name results with a batch seed drawn like get_name() draws its own.
 
name get_surname (const name_request &request)
 Generate a surname.
 
name get_surname (const name_request &request, std::uint64_t call_seed) const
 Generate a deterministic surname using a specific seed.
 
std::vector< name > get_surname_batch (const name_request &request, const core::batch_options &options)
 Generate a batch of surname results from a seed drawn like get_surname() draws its own.
 
std::vector< name > get_surname_batch (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed) const
 Generate a batch of surname results, deterministically.
 
template<typename Sink >
void for_each_surname (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const
 Stream a batch of surname results to a sink without holding the whole batch.
 
template<typename Sink >
void for_each_surname (const name_request &request, const core::batch_options &options, Sink &&sink)
 Stream a batch of surname results with a batch seed drawn like get_surname() draws its own.
 
naming_convention convention (culture c) const
 How a culture composes a full name.
 
name get_full_name (const name_request &request)
 Generate a full name by the culture's convention.
 
name get_full_name (const name_request &request, std::uint64_t call_seed) const
 Generate a deterministic full name.
 
std::vector< name > get_full_name_batch (const name_request &request, const core::batch_options &options)
 Generate a batch of full names from a seed drawn like get_full_name() draws its own.
 
std::vector< name > get_full_name_batch (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed) const
 Generate a batch of full names, deterministically: item i is get_full_name(request, core::item_seed(batch_seed, options.first + i)).
 
template<typename Sink >
void for_each_full_name (const name_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const
 Stream a batch of full names to a sink, in index order.
 
template<typename Sink >
void for_each_full_name (const name_request &request, const core::batch_options &options, Sink &&sink)
 Stream a batch of full names with a batch seed drawn like get_full_name() draws its own.
 
name get_child_name (const name &father, const name &mother, const child_name_request &request)
 Name a child of two people by the culture's convention.
 
name get_child_name (const name &father, const name &mother, const child_name_request &request, std::uint64_t call_seed) const
 Name a child of two people, deterministically.
 
name get_married_name (const name &wife, const name &husband) const
 The name a woman has after marrying, by the culture's convention.
 
name compose_name (const name_parts &parts, culture c, std::uint64_t call_seed=0) const
 A name made from words the caller already has, put in the culture's order and carrying the roles of its parts.
 
name get_parent_name (const name &child, gender parent_gender)
 Name a parent of an existing person, consistently with the person's name; the inverse of get_child_name().
 
name get_parent_name (const name &child, gender parent_gender, std::uint64_t call_seed) const
 Name a parent of an existing person, deterministically.
 
std::wstring female_form (const std::wstring &surname, culture c, bool married=false) const
 The female form of a male surname, by the culture's surname_forms.tsv rules.
 
const std::vector< core::layer_info > & convention_layers () const
 The layers in effect for conventions.tsv.
 
const std::vector< core::layer_info > & surname_form_layers () const
 The layers in effect for surname_forms.tsv.
 
bool has_resources () const
 Check whether any name databases have been loaded.
 
void load (const std::filesystem::path &resource_path)
 Load name files from a directory, replacing all names and layers loaded before.
 
bool load (dataset tier)
 Load a dataset tier, replacing all names and layers loaded before.
 
void extend (const std::filesystem::path &path, core::layer_mode mode=core::layer_mode::override)
 Add name layers from a .names file or a directory of them.
 
const core::layer_info & extend_conventions_from_string (std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override)
 Add a layer of conventions.tsv from text.
 
const core::layer_info & extend_surname_forms_from_string (std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override)
 Add a layer of surname_forms.tsv from text.
 
const core::layer_info & extend_from_string (std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override)
 Add a name layer from text in the .names format.
 
const std::vector< core::layer_info > & layers (culture c, gender g) const
 The layers in effect for one name list.
 
const std::vector< core::layer_info > & surname_layers (culture c, gender g) const
 The layers in effect for the surnames of one gender.
 
std::uint64_t data_hash () const
 Hash of the loaded names, recorded in each result's signature().
 

Static Public Member Functions

static ng & instance ()
 Access the global singleton instance.
 
static culture to_culture (std::wstring_view country_code)
 Translate an ISO 3166 2-letter country code to a culture enum.
 
static gender to_gender (std::wstring_view gender_string)
 Translate a gender string to a gender enum.
 
static std::string_view culture_code (culture c)
 The ISO 3166 2-letter country code of a culture.
 
static std::string_view culture_name (culture c)
 The name of a culture.
 
static std::wstring patronymic_of (patronymic_style style, const std::wstring &father, bool daughter)
 The patronymic a father's given name gives a child.
 

Friends

class name
 
struct ::ng_test_access
 

Detailed Description

Name generator that produces culture-aware names and surnames.

Generates realistic names by picking from popular name databases indexed by culture and gender, weighted by popularity. Supports 105 cultures.

Output is identical on every compiler and platform (dasmig-core): a seed, the same request and the same data give the same name everywhere.

Can be used as a singleton via instance() or constructed independently. Independent instances own their own name databases and random engine.

Thread safety
Each instance is independent. Concurrent calls to get_name() on the same instance require external synchronization. load() and extend() mutate internal state and must not be called concurrently with get_name() on the same instance.

Definition at line 431 of file namegen.hpp.

Constructor & Destructor Documentation

◆ ng()

dasmig::ng::ng ( )
default

Default constructor — creates an empty generator with no names.

Call load() to populate name databases before generating.

Member Function Documentation

◆ compose_name()

name dasmig::ng::compose_name ( const name_parts &  parts,
culture  c,
std::uint64_t  call_seed = 0 
) const
inline

A name made from words the caller already has, put in the culture's order and carrying the roles of its parts.

For a person whose name is known and whose relatives are to be named to match: pass the result to get_child_name(), get_parent_name() or get_married_name(), which read only the roles of the parts.

Parameters
partsThe words of the name.
cThe culture whose convention orders them; not any.
call_seedSeed recorded in the name's signature.
Returns
A composed name.
Exceptions
std::invalid_argumentIf the culture is any, the gender is not male or female, or the given name is empty.

Definition at line 885 of file namegen.hpp.

◆ convention()

naming_convention dasmig::ng::convention ( culture  c) const
inline

How a culture composes a full name.

Parameters
cCulture.
Returns
The convention loaded from conventions.tsv; the default (one surname, given name first) for a culture without a row.

Definition at line 698 of file namegen.hpp.

◆ convention_layers()

const std::vector< core::layer_info > & dasmig::ng::convention_layers ( ) const
inline

The layers in effect for conventions.tsv.

Returns
The layer records.

Definition at line 1010 of file namegen.hpp.

◆ culture_code()

static std::string_view dasmig::ng::culture_code ( culture  c)
inlinestatic

The ISO 3166 2-letter country code of a culture.

Parameters
cCulture.
Returns
Lower-case code such as "br", or "" for culture::any.

Definition at line 483 of file namegen.hpp.

◆ culture_name()

static std::string_view dasmig::ng::culture_name ( culture  c)
inlinestatic

The name of a culture.

Parameters
cCulture.
Returns
Lower-case name such as "brazilian", or "any".

Definition at line 492 of file namegen.hpp.

◆ data_hash()

std::uint64_t dasmig::ng::data_hash ( ) const
inline

Hash of the loaded names, recorded in each result's signature().

Returns
The hash; 0 when nothing is loaded.

Definition at line 1221 of file namegen.hpp.

◆ extend()

void dasmig::ng::extend ( const std::filesystem::path &  path,
core::layer_mode  mode = core::layer_mode::override 
)
inline

Add name layers from a .names file or a directory of them.

Each file names its culture and gender in its first two lines, so it adds to (or changes, or removes from) that list. A directory is applied all together, or not at all if any file is invalid.

Parameters
pathA .names file or a directory.
modeHow the layers combine with the names loaded before.
Exceptions
core::tsv_errorIf a file cannot be read or is invalid; the names are then unchanged.
std::invalid_argumentIf path is a file without the .names extension.

Definition at line 1102 of file namegen.hpp.

◆ extend_conventions_from_string()

const core::layer_info & dasmig::ng::extend_conventions_from_string ( std::string_view  text,
std::string  source,
core::layer_mode  mode = core::layer_mode::override 
)
inline

Add a layer of conventions.tsv from text.

Parameters
textTab-separated text with a header line: culture (a culture name such as russian, the key) and any of order (given_family, family_given), patronymic (none, east_slavic, icelandic), family_name (0 or 1), surnames (1 or 2), second_surname (a chance from 0 to 1) and surname_order (paternal_first, maternal_first).
sourceName used in errors.
modeHow the layer combines with the conventions loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf the text is invalid; nothing then changes.

Definition at line 1141 of file namegen.hpp.

◆ extend_from_string()

const core::layer_info & dasmig::ng::extend_from_string ( std::string_view  text,
std::string  source,
core::layer_mode  mode = core::layer_mode::override 
)
inline

Add a name layer from text in the .names format.

Parameters
textThe country code, the list (male, female or any for surnames; male-surname or female-surname for the surnames of one gender), then one name per line with an optional weight.
sourceName used in errors.
modeHow the layer combines with the names loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf the text is invalid; the names are then unchanged.

Definition at line 1181 of file namegen.hpp.

◆ extend_surname_forms_from_string()

const core::layer_info & dasmig::ng::extend_surname_forms_from_string ( std::string_view  text,
std::string  source,
core::layer_mode  mode = core::layer_mode::override 
)
inline

Add a layer of surname_forms.tsv from text.

Parameters
textTab-separated text with a header line: culture and male (the keys: the ending of a male surname, or * for any), female (the ending a daughter has instead) and optionally married (the ending a wife has; female when empty). The longest matching male ending applies.
sourceName used in errors.
modeHow the layer combines with the rules loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf the text is invalid; nothing then changes.

Definition at line 1161 of file namegen.hpp.

◆ female_form()

std::wstring dasmig::ng::female_form ( const std::wstring &  surname,
culture  c,
bool  married = false 
) const
inline

The female form of a male surname, by the culture's surname_forms.tsv rules.

Parameters
surnameA male surname.
cCulture.
marriedWhether to give the form a wife takes rather than the one a daughter has (they differ in Lithuanian).
Returns
The form; surname when the culture has no rule for it.

Definition at line 1002 of file namegen.hpp.

◆ for_each_full_name() [1/2]

template<typename Sink >
void dasmig::ng::for_each_full_name ( const name_request &  request,
const core::batch_options &  options,
Sink &&  sink 
)
inline

Stream a batch of full names with a batch seed drawn like get_full_name() draws its own.

Template Parameters
SinkCallable taking (std::uint64_t, name&).
Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
sinkReceives the items.

Definition at line 785 of file namegen.hpp.

◆ for_each_full_name() [2/2]

template<typename Sink >
void dasmig::ng::for_each_full_name ( const name_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed,
Sink &&  sink 
) const
inline

Stream a batch of full names to a sink, in index order.

Template Parameters
SinkCallable taking (std::uint64_t, name&).
Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
batch_seedSeed of the whole batch.
sinkReceives the items.

Definition at line 770 of file namegen.hpp.

◆ for_each_name() [1/2]

template<typename Sink >
void dasmig::ng::for_each_name ( const name_request &  request,
const core::batch_options &  options,
Sink &&  sink 
)
inline

Stream a batch of name results with a batch seed drawn like get_name() draws its own.

Template Parameters
SinkCallable taking (std::uint64_t, name&).
Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
sinkReceives the items.

Definition at line 588 of file namegen.hpp.

◆ for_each_name() [2/2]

template<typename Sink >
void dasmig::ng::for_each_name ( const name_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed,
Sink &&  sink 
) const
inline

Stream a batch of name results to a sink without holding the whole batch.

Generates the same items as get_name_batch() and calls sink(index, item) in index order on the calling thread; index includes options.first.

Template Parameters
SinkCallable taking (std::uint64_t, name&); for example core::jsonl_writer or core::csv_writer.
Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
batch_seedSeed of the whole batch.
sinkReceives the items.

Definition at line 573 of file namegen.hpp.

◆ for_each_surname() [1/2]

template<typename Sink >
void dasmig::ng::for_each_surname ( const name_request &  request,
const core::batch_options &  options,
Sink &&  sink 
)
inline

Stream a batch of surname results with a batch seed drawn like get_surname() draws its own.

Template Parameters
SinkCallable taking (std::uint64_t, name&).
Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
sinkReceives the items.

Definition at line 685 of file namegen.hpp.

◆ for_each_surname() [2/2]

template<typename Sink >
void dasmig::ng::for_each_surname ( const name_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed,
Sink &&  sink 
) const
inline

Stream a batch of surname results to a sink without holding the whole batch.

Generates the same items as get_surname_batch() and calls sink(index, item) in index order on the calling thread; index includes options.first.

Template Parameters
SinkCallable taking (std::uint64_t, name&); for example core::jsonl_writer or core::csv_writer.
Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
batch_seedSeed of the whole batch.
sinkReceives the items.

Definition at line 670 of file namegen.hpp.

◆ get_child_name() [1/2]

name dasmig::ng::get_child_name ( const name &  father,
const name &  mother,
const child_name_request &  request 
)
inline

Name a child of two people by the culture's convention.

The child takes its family name from the parents as the culture does: one surname cultures give the father's family name (a daughter its female form where the culture has one); two-surname cultures give one surname of each parent, in the culture's surname_order; patronymic cultures derive the patronymic from the father's given name. The given name is drawn from the father's culture. Only the parts' roles are read, so the parents can be any names (composed or not); the structure of a family (who the parents are, how many children) is the caller's.

Siblings are not made distinct: draw each with its own seed and compare, if that matters.

Parameters
fatherThe father's name; its culture is the child's.
motherThe mother's name.
requestThe child's gender.
Returns
A composed name.
Exceptions
std::invalid_argumentIf the father's culture is any or has no forenames or surnames loaded.

Definition at line 812 of file namegen.hpp.

◆ get_child_name() [2/2]

name dasmig::ng::get_child_name ( const name &  father,
const name &  mother,
const child_name_request &  request,
std::uint64_t  call_seed 
) const
inline

Name a child of two people, deterministically.

Parameters
fatherThe father's name; its culture is the child's.
motherThe mother's name.
requestThe child's gender.
call_seedSeed; the same seed, parents and data give the same name on every platform.
Returns
A composed name.
Exceptions
std::invalid_argumentIf the father's culture is any or has no forenames or surnames loaded.

Definition at line 827 of file namegen.hpp.

◆ get_full_name() [1/2]

name dasmig::ng::get_full_name ( const name_request &  request)
inline

Generate a full name by the culture's convention.

The parts follow the culture's order: family name first for Chinese, Japanese and Korean; two surnames for Spanish and Portuguese; a patronymic from a drawn father's name for Russian and Icelandic. The parts carry roles (name::roles()). get_name() and get_surname() are unchanged by conventions.

Parameters
requestGender and culture (both default to any).
Returns
A composed name.
Exceptions
std::invalid_argumentIf no names are loaded for the resolved culture and gender.

Definition at line 716 of file namegen.hpp.

◆ get_full_name() [2/2]

name dasmig::ng::get_full_name ( const name_request &  request,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic full name.

Parameters
requestGender and culture.
call_seedSeed; the same seed, request and data give the same name on every platform.
Returns
A composed name.
Exceptions
std::invalid_argumentIf no names are loaded for the resolved culture and gender.

Definition at line 728 of file namegen.hpp.

◆ get_full_name_batch() [1/2]

std::vector< name > dasmig::ng::get_full_name_batch ( const name_request &  request,
const core::batch_options &  options 
)
inline

Generate a batch of full names from a seed drawn like get_full_name() draws its own.

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
Returns
The results, in index order.

Definition at line 743 of file namegen.hpp.

◆ get_full_name_batch() [2/2]

std::vector< name > dasmig::ng::get_full_name_batch ( const name_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed 
) const
inline

Generate a batch of full names, deterministically: item i is get_full_name(request, core::item_seed(batch_seed, options.first + i)).

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
batch_seedSeed of the whole batch.
Returns
The results, in index order.

Definition at line 755 of file namegen.hpp.

◆ get_married_name()

name dasmig::ng::get_married_name ( const name &  wife,
const name &  husband 
) const
inline

The name a woman has after marrying, by the culture's convention.

A single-surname culture gives her the husband's family name, in its married form where the culture has one (Kozlov gives Kozlova); a two-surname or patronymic culture leaves her name as it is. Only the roles of the names are read.

Parameters
wifeThe woman's name.
husbandThe husband's name; its culture is the one used.
Returns
A composed name with the wife's seed.

Definition at line 859 of file namegen.hpp.

◆ get_name() [1/2]

name dasmig::ng::get_name ( const name_request &  request)
inline

Generate a first name.

Parameters
requestGender and culture (both default to any).
Returns
A name object supporting chained appending.
Exceptions
std::invalid_argumentIf no names loaded for the resolved culture/gender.

Definition at line 502 of file namegen.hpp.

◆ get_name() [2/2]

name dasmig::ng::get_name ( const name_request &  request,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic first name using a specific seed.

Parameters
requestGender and culture.
call_seedSeed; the same seed, request and data give the same name on every platform.
Returns
A name object.
Exceptions
std::invalid_argumentIf no names loaded for the resolved culture/gender.

Definition at line 513 of file namegen.hpp.

◆ get_name_batch() [1/2]

std::vector< name > dasmig::ng::get_name_batch ( const name_request &  request,
const core::batch_options &  options 
)
inline

Generate a batch of name results from a seed drawn like get_name() draws its own.

Item i is get_name(request, core::item_seed(batch_seed, options.first + i)) for the drawn batch seed; see the seeded overload.

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
Returns
The results, in index order.

Definition at line 530 of file namegen.hpp.

◆ get_name_batch() [2/2]

std::vector< name > dasmig::ng::get_name_batch ( const name_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed 
) const
inline

Generate a batch of name results, deterministically.

Item i is exactly get_name(request, core::item_seed(batch_seed, options.first + i)), so an item replays on its own, a range can be generated directly, two batches that follow each other equal one, and the output does not depend on options.threads.

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness (see core::unique_rule; the rule must be made for name).
batch_seedSeed of the whole batch.
Returns
The results, in index order.
Exceptions
std::invalid_argumentIf the request or options are invalid.
std::runtime_errorIf no data has been loaded, or a unique batch runs out of attempts.

Definition at line 551 of file namegen.hpp.

◆ get_parent_name() [1/2]

name dasmig::ng::get_parent_name ( const name &  child,
gender  parent_gender 
)
inline

Name a parent of an existing person, consistently with the person's name; the inverse of get_child_name().

The father's family name is the child's (in its male form where the culture has one), and in a patronymic culture his given name is one whose patronymic is the child's. Two-surname cultures give the surname the child took from this parent, in the slot the culture puts it. Everything the child's name does not fix (the mother's family name, the other surname of a parent, a grandparent's name in a patronymic) is drawn. The culture is the child's. Only the roles of the child's parts are read.

Parameters
childThe person's name; its culture is the parent's.
parent_gendergender::m or gender::f.
Returns
A composed name.
Exceptions
std::invalid_argumentIf the child's culture is any, the gender is any, or the culture has no names loaded.

Definition at line 915 of file namegen.hpp.

◆ get_parent_name() [2/2]

name dasmig::ng::get_parent_name ( const name &  child,
gender  parent_gender,
std::uint64_t  call_seed 
) const
inline

Name a parent of an existing person, deterministically.

Parameters
childThe person's name; its culture is the parent's.
parent_gendergender::m or gender::f.
call_seedSeed; the same seed, child and data give the same name on every platform.
Returns
A composed name.
Exceptions
std::invalid_argumentIf the child's culture is any, the gender is any, or the culture has no names loaded.

Definition at line 928 of file namegen.hpp.

◆ get_surname() [1/2]

name dasmig::ng::get_surname ( const name_request &  request)
inline

Generate a surname.

Parameters
requestCulture, and gender for cultures with gendered surnames (both default to any).
Returns
A name object supporting chained appending.
Exceptions
std::invalid_argumentIf no surnames loaded for the resolved culture.

Definition at line 600 of file namegen.hpp.

◆ get_surname() [2/2]

name dasmig::ng::get_surname ( const name_request &  request,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic surname using a specific seed.

Parameters
requestCulture and gender.
call_seedSeed for reproducible results.
Returns
A name object.
Exceptions
std::invalid_argumentIf no surnames loaded for the resolved culture.

Definition at line 610 of file namegen.hpp.

◆ get_surname_batch() [1/2]

std::vector< name > dasmig::ng::get_surname_batch ( const name_request &  request,
const core::batch_options &  options 
)
inline

Generate a batch of surname results from a seed drawn like get_surname() draws its own.

Item i is get_surname(request, core::item_seed(batch_seed, options.first + i)) for the drawn batch seed; see the seeded overload.

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
Returns
The results, in index order.

Definition at line 627 of file namegen.hpp.

◆ get_surname_batch() [2/2]

std::vector< name > dasmig::ng::get_surname_batch ( const name_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed 
) const
inline

Generate a batch of surname results, deterministically.

Item i is exactly get_surname(request, core::item_seed(batch_seed, options.first + i)), so an item replays on its own, a range can be generated directly, two batches that follow each other equal one, and the output does not depend on options.threads.

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness (see core::unique_rule; the rule must be made for name).
batch_seedSeed of the whole batch.
Returns
The results, in index order.
Exceptions
std::invalid_argumentIf the request or options are invalid.
std::runtime_errorIf no data has been loaded, or a unique batch runs out of attempts.

Definition at line 648 of file namegen.hpp.

◆ has_resources()

bool dasmig::ng::has_resources ( ) const
inline

Check whether any name databases have been loaded.

Returns
true if at least one name list is loaded.

Definition at line 1024 of file namegen.hpp.

◆ instance()

static ng & dasmig::ng::instance ( )
inlinestatic

Access the global singleton instance.

Loads the lite tier on first access (or full when lite is not found), from compiled-in data or an auto-probed resources/. For independent generators, prefer constructing a separate ng instance.

Returns
Reference to the global ng instance.

Definition at line 451 of file namegen.hpp.

◆ layers()

const std::vector< core::layer_info > & dasmig::ng::layers ( culture  c,
gender  g 
) const
inline

The layers in effect for one name list.

Parameters
cCulture.
ggender::m or gender::f for forenames, gender::any for surnames.
Returns
The layer records.
Exceptions
std::out_of_rangeIf that list was never loaded.

Definition at line 1198 of file namegen.hpp.

◆ load() [1/2]

void dasmig::ng::load ( const std::filesystem::path &  resource_path)
inline

Load name files from a directory, replacing all names and layers loaded before.

Reads every .names file below resource_path, in path order (see doc/usage.md for the format). A path that is not a directory is ignored.

Parameters
resource_pathDirectory containing .names files, such as resources/lite.
Exceptions
core::tsv_errorIf a file is malformed; the names are then unchanged.

Definition at line 1040 of file namegen.hpp.

◆ load() [2/2]

bool dasmig::ng::load ( dataset  tier)
inline

Load a dataset tier, replacing all names and layers loaded before.

lite uses the compiled-in copy when built with DASMIG_NAME_EMBED. Otherwise the tier is read from the first of resources, ../resources, name-generator/resources and ../name-generator/resources that has it.

Parameters
tierThe dataset size to load (dataset::lite or dataset::full).
Returns
true if the tier was found and loaded.
Exceptions
core::tsv_errorIf a file is malformed.

Definition at line 1058 of file namegen.hpp.

◆ patronymic_of()

static std::wstring dasmig::ng::patronymic_of ( patronymic_style  style,
const std::wstring &  father,
bool  daughter 
)
inlinestatic

The patronymic a father's given name gives a child.

Rule-based, for names in Latin script, with a short list of irregular names (Pavel to Pavlovich, Jón to Jónsson).

Parameters
styleThe culture's patronymic style.
fatherThe father's given name.
daughterWhether the child is a daughter.
Returns
The patronymic; empty for patronymic_style::none.

Definition at line 989 of file namegen.hpp.

◆ surname_form_layers()

const std::vector< core::layer_info > & dasmig::ng::surname_form_layers ( ) const
inline

The layers in effect for surname_forms.tsv.

Returns
The layer records.

Definition at line 1017 of file namegen.hpp.

◆ surname_layers()

const std::vector< core::layer_info > & dasmig::ng::surname_layers ( culture  c,
gender  g 
) const
inline

The layers in effect for the surnames of one gender.

Parameters
cCulture.
ggender::m or gender::f; gender::any is the surname list shared by both.
Returns
The layer records.
Exceptions
std::out_of_rangeIf that list was never loaded (a culture has one only when its surnames change with gender).

Definition at line 1210 of file namegen.hpp.

◆ to_culture()

static culture dasmig::ng::to_culture ( std::wstring_view  country_code)
inlinestatic

Translate an ISO 3166 2-letter country code to a culture enum.

Parameters
country_codeTwo-letter country code (e.g., L"us", L"br").
Returns
Matching culture, or culture::any if not recognized.

Definition at line 460 of file namegen.hpp.

◆ to_gender()

static gender dasmig::ng::to_gender ( std::wstring_view  gender_string)
inlinestatic

Translate a gender string to a gender enum.

Parameters
gender_stringGender string (e.g., L"male", L"female", L"m", L"f").
Returns
Matching gender, or gender::any if not recognized.

Definition at line 473 of file namegen.hpp.

Friends And Related Symbol Documentation

◆ ::ng_test_access

friend struct ::ng_test_access
friend

Definition at line 2152 of file namegen.hpp.

◆ name

friend class name
friend

Definition at line 2151 of file namegen.hpp.


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