|
Name Generator 1.0.0
Culture-aware name generation for C++23
|
This guide covers every feature of the name-generator library in detail. For a quick overview, see the README. For the full API reference, run doxygen Doxyfile from the repository root and open doc/api/html/index.html.
dasmig/namegen.hpp and dasmig/random.hpp into your include path.resources/ folder (containing .names files) to your working directory.-std=c++23 (GCC/Clang) or /std:c++latest (MSVC).The singleton ng::instance() auto-probes resources/, ../resources/, and name-generator/resources/ on first access. For custom locations:
Note:
load()silently does nothing if the path does not exist or is not a directory. Always usehas_resources()to verify that databases were actually loaded.
Check whether resources loaded successfully:
23 cultures are supported:
| Culture | Code | Culture | Code |
|---|---|---|---|
| American | us | Mexican | mx |
| Argentinian | ar | Norwegian | no |
| Australian | au | Polish | pl |
| Brazilian | br | Portuguese | pt |
| British | gb | Russian | ru |
| Bulgarian | bg | Spanish | es |
| Canadian | ca | Swedish | se |
| Chinese | cn | Turkish | tr |
| Danish | dk | Ukrainian | ua |
| Finnish | fi | ||
| French | fr | ||
| German | de | ||
| Kazakh | kz |
The name return type supports chained appending:
Each ng instance is independent. The static instance() singleton uses a local static for safe initialization.
| Operation | Thread-safe? |
|---|---|
instance() | Yes (static local) |
get_name() / get_surname() on different instances | Yes |
get_name() / get_surname() on the same instance | No — requires external synchronization |
load() | No — must not be called concurrently with generation on the same instance |
For concurrent generation, give each thread its own ng instance.
A name object holds a back-pointer to the ng instance that created it. Calling append_name() or append_surname() on a name whose ng instance has been destroyed is undefined behavior. Keep the generator alive for as long as you need to chain appends:
Pass an explicit seed to produce the same name every time:
Every name records its seed. Retrieve it with name::seed():
Seed the generator engine for deterministic sequences:
Construct independent ng objects with their own name databases and random engine:
Each instance maintains its own engine:
Instances can be moved (but not copied):
| Exception | Thrown by | Condition |
|---|---|---|
std::invalid_argument | get_name() / get_surname() | No names loaded for the resolved culture/gender |
Note:
load()does not throw if the path is missing — it silently returns. Usehas_resources()to check.