![]() |
Name Generator 4.2.1
Culture-aware name generation for C++23
|
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. | |
| 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_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. | |
Friends | |
| class | name |
| struct | ::ng_test_access |
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.
Definition at line 320 of file namegen.hpp.
|
default |
Default constructor — creates an empty generator with no names.
Call load() to populate name databases before generating.
|
inlinestatic |
The ISO 3166 2-letter country code of a culture.
| c | Culture. |
"br", or "" for culture::any. Definition at line 372 of file namegen.hpp.
|
inlinestatic |
The name of a culture.
| c | Culture. |
"brazilian", or "any". Definition at line 381 of file namegen.hpp.
|
inline |
Hash of the loaded names, recorded in each result's signature().
Definition at line 720 of file namegen.hpp.
|
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.
| path | A .names file or a directory. |
| mode | How the layers combine with the names loaded before. |
| core::tsv_error | If a file cannot be read or is invalid; the names are then unchanged. |
| std::invalid_argument | If path is a file without the .names extension. |
Definition at line 651 of file namegen.hpp.
|
inline |
Add a name layer from text in the .names format.
| text | The 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. |
| source | Name used in errors. |
| mode | How the layer combines with the names loaded before. |
| core::tsv_error | If the text is invalid; the names are then unchanged. |
Definition at line 680 of file namegen.hpp.
|
inline |
Stream a batch of name results with a batch seed drawn like get_name() draws its own.
| Sink | Callable taking (std::uint64_t, name&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 477 of file namegen.hpp.
|
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.
| Sink | Callable taking (std::uint64_t, name&); for example core::jsonl_writer or core::csv_writer. |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items. |
Definition at line 462 of file namegen.hpp.
|
inline |
Stream a batch of surname results with a batch seed drawn like get_surname() draws its own.
| Sink | Callable taking (std::uint64_t, name&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 574 of file namegen.hpp.
|
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.
| Sink | Callable taking (std::uint64_t, name&); for example core::jsonl_writer or core::csv_writer. |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items. |
Definition at line 559 of file namegen.hpp.
|
inline |
Generate a first name.
| request | Gender and culture (both default to any). |
| std::invalid_argument | If no names loaded for the resolved culture/gender. |
Definition at line 391 of file namegen.hpp.
|
inline |
Generate a deterministic first name using a specific seed.
| request | Gender and culture. |
| call_seed | Seed; the same seed, request and data give the same name on every platform. |
| std::invalid_argument | If no names loaded for the resolved culture/gender. |
Definition at line 402 of file namegen.hpp.
|
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.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 419 of file namegen.hpp.
|
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.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (see core::unique_rule; the rule must be made for name). |
| batch_seed | Seed of the whole batch. |
| std::invalid_argument | If the request or options are invalid. |
| std::runtime_error | If no data has been loaded, or a unique batch runs out of attempts. |
Definition at line 440 of file namegen.hpp.
|
inline |
Generate a surname.
| request | Culture, and gender for cultures with gendered surnames (both default to any). |
| std::invalid_argument | If no surnames loaded for the resolved culture. |
Definition at line 489 of file namegen.hpp.
|
inline |
Generate a deterministic surname using a specific seed.
| request | Culture and gender. |
| call_seed | Seed for reproducible results. |
| std::invalid_argument | If no surnames loaded for the resolved culture. |
Definition at line 499 of file namegen.hpp.
|
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.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 516 of file namegen.hpp.
|
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.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (see core::unique_rule; the rule must be made for name). |
| batch_seed | Seed of the whole batch. |
| std::invalid_argument | If the request or options are invalid. |
| std::runtime_error | If no data has been loaded, or a unique batch runs out of attempts. |
Definition at line 537 of file namegen.hpp.
|
inline |
Check whether any name databases have been loaded.
true if at least one name list is loaded. Definition at line 583 of file namegen.hpp.
|
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.
Definition at line 340 of file namegen.hpp.
The layers in effect for one name list.
| c | Culture. |
| g | gender::m or gender::f for forenames, gender::any for surnames. |
| std::out_of_range | If that list was never loaded. |
Definition at line 697 of file namegen.hpp.
|
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.
| resource_path | Directory containing .names files, such as resources/lite. |
| core::tsv_error | If a file is malformed; the names are then unchanged. |
Definition at line 599 of file namegen.hpp.
|
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.
| tier | The dataset size to load (dataset::lite or dataset::full). |
true if the tier was found and loaded. | core::tsv_error | If a file is malformed. |
Definition at line 617 of file namegen.hpp.
|
inline |
The layers in effect for the surnames of one gender.
| c | Culture. |
| g | gender::m or gender::f; gender::any is the surname list shared by both. |
| std::out_of_range | If that list was never loaded (a culture has one only when its surnames change with gender). |
Definition at line 709 of file namegen.hpp.
|
inlinestatic |
Translate an ISO 3166 2-letter country code to a culture enum.
| country_code | Two-letter country code (e.g., L"us", L"br"). |
Definition at line 349 of file namegen.hpp.
|
inlinestatic |
Translate a gender string to a gender enum.
| gender_string | Gender string (e.g., L"male", L"female", L"m", L"f"). |
Definition at line 362 of file namegen.hpp.
|
friend |
Definition at line 1177 of file namegen.hpp.
|
friend |
Definition at line 1176 of file namegen.hpp.