Name Generator 1.0.0
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.
 
ngoperator= (const ng &)=delete
 Not copyable.
 
 ng (ng &&) noexcept=default
 Move constructor.
 
ngoperator= (ng &&) noexcept=default
 Move assignment.
 
 ~ng ()=default
 Default destructor.
 
name get_name (gender g=gender::any, culture c=culture::any)
 Generate a first name.
 
name get_name (gender g, culture c, std::uint64_t call_seed)
 Generate a deterministic first name using a specific seed.
 
name get_surname (culture c=culture::any)
 Generate a surname.
 
name get_surname (culture c, std::uint64_t call_seed)
 Generate a deterministic surname using a specific seed.
 
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.
 
Seeding
ngseed (std::uint64_t seed_value)
 Seed the internal random engine for deterministic sequences.
 
ngunseed ()
 Reseed the engine with a non-deterministic source.
 

Static Public Member Functions

static nginstance ()
 Access the global singleton instance.
 
static culture to_culture (const std::wstring &country_code)
 Translate an ISO 3166 2-letter country code to a culture enum.
 
static gender to_gender (const std::wstring &gender_string)
 Translate a gender string to a gender enum.
 

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. Supports 23 cultures.

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() mutates internal state and must not be called concurrently with get_name() on the same instance.

Definition at line 162 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

◆ get_name() [1/2]

name dasmig::ng::get_name ( gender  g,
culture  c,
std::uint64_t  call_seed 
)
inline

Generate a deterministic first name using a specific seed.

Parameters
gGender (default: random).
cCulture (default: random).
call_seedSeed for reproducible results.
Returns
A name object.
Exceptions
std::invalid_argumentIf no names loaded for the resolved culture/gender.

Definition at line 252 of file namegen.hpp.

◆ get_name() [2/2]

name dasmig::ng::get_name ( gender  g = gender::any,
culture  c = culture::any 
)
inline

Generate a first name.

Parameters
gGender (default: random).
cCulture (default: random).
Returns
A name object supporting chained appending.
Exceptions
std::invalid_argumentIf no names loaded for the resolved culture/gender.

Definition at line 237 of file namegen.hpp.

◆ get_surname() [1/2]

name dasmig::ng::get_surname ( culture  c,
std::uint64_t  call_seed 
)
inline

Generate a deterministic surname using a specific seed.

Parameters
cCulture (default: random).
call_seedSeed for reproducible results.
Returns
A name object.
Exceptions
std::invalid_argumentIf no surnames loaded for the resolved culture.

Definition at line 277 of file namegen.hpp.

◆ get_surname() [2/2]

name dasmig::ng::get_surname ( culture  c = culture::any)
inline

Generate a surname.

Parameters
cCulture (default: random).
Returns
A name object supporting chained appending.
Exceptions
std::invalid_argumentIf no surnames loaded for the resolved culture.

Definition at line 264 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 file has been loaded.

Definition at line 313 of file namegen.hpp.

◆ instance()

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

Access the global singleton instance.

The singleton auto-probes common resource paths on first access. For independent generators, prefer constructing a separate ng instance.

Returns
Reference to the global ng instance.

Definition at line 181 of file namegen.hpp.

◆ load()

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

Load name files from a directory.

Recursively scans resource_path for .names files and indexes them by culture and gender. Safe to call multiple times.

Parameters
resource_pathDirectory containing .names files.

Definition at line 326 of file namegen.hpp.

◆ seed()

ng & dasmig::ng::seed ( std::uint64_t  seed_value)
inline

Seed the internal random engine for deterministic sequences.

Subsequent get_name() / get_surname() calls (without an explicit seed) draw per-call seeds from this engine, producing a reproducible sequence.

Parameters
seed_valueThe seed value.
Returns
*this for chaining.

Definition at line 295 of file namegen.hpp.

◆ to_culture()

static culture dasmig::ng::to_culture ( const std::wstring &  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 190 of file namegen.hpp.

◆ to_gender()

static gender dasmig::ng::to_gender ( const std::wstring &  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 216 of file namegen.hpp.

◆ unseed()

ng & dasmig::ng::unseed ( )
inline

Reseed the engine with a non-deterministic source.

Returns
*this for chaining.

Definition at line 303 of file namegen.hpp.

Friends And Related Symbol Documentation

◆ ::ng_test_access

friend struct ::ng_test_access
friend

Definition at line 705 of file namegen.hpp.

◆ name

friend class name
friend

Definition at line 704 of file namegen.hpp.


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