Nickname Generator 5.2.2
Gamer-style nickname generation for C++23
Loading...
Searching...
No Matches
dasmig::nng Class Reference

Nickname generator that produces gamer-style nicknames. More...

#include <nicknamegen.hpp>

Public Member Functions

 nng ()=default
 Default constructor — creates an empty generator with no word lists.
 
 nng (const nng &)=delete
 Not copyable.
 
nng & operator= (const nng &)=delete
 Not copyable.
 
 nng (nng &&) noexcept=default
 Move constructor.
 
nng & operator= (nng &&) noexcept=default
 Move assignment.
 
 ~nng ()=default
 Default destructor.
 
nickname get_nickname (const nickname_request &request)
 Generate a random nickname, optionally based on a name.
 
nickname get_nickname (const nickname_request &request, std::uint64_t call_seed) const
 Generate a deterministic nickname.
 
std::vector< nickname > get_nickname_batch (const nickname_request &request, const core::batch_options &options)
 Generate a batch of nickname results from a seed drawn like get_nickname() draws its own.
 
std::vector< nickname > get_nickname_batch (const nickname_request &request, const core::batch_options &options, std::uint64_t batch_seed) const
 Generate a batch of nickname results, deterministically.
 
template<typename Sink >
void for_each_nickname (const nickname_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const
 Stream a batch of nickname results to a sink without holding the whole batch.
 
template<typename Sink >
void for_each_nickname (const nickname_request &request, const core::batch_options &options, Sink &&sink)
 Stream a batch of nickname results with a batch seed drawn like get_nickname() draws its own.
 
bool has_wordlists () const
 Check whether any word list is loaded.
 
void load (const std::filesystem::path &resource_path)
 Load word lists from a directory, replacing all lists and layers loaded before.
 
bool load (dataset tier)
 Load the shipped word lists, replacing all lists and layers loaded before.
 
void extend (const std::filesystem::path &path, core::layer_mode mode=core::layer_mode::override)
 Add word list layers from a directory or a file.
 
const core::layer_info & extend_from_string (std::string_view list, std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override)
 Add a layer to a word list from TSV text with a word column (and optionally disabled).
 
std::vector< std::string > list_names () const
 Names of the loaded word lists, in the order they are used.
 
const std::vector< core::layer_info > & layers (const std::string &list) const
 The layers in effect for one word list.
 
std::uint64_t data_hash () const
 Hash of the loaded word lists, recorded in each result's signature().
 

Static Public Member Functions

static nng & instance ()
 Access the global singleton instance.
 

Friends

struct ::nng_test_access
 

Detailed Description

Nickname generator that produces gamer-style nicknames.

Generates nicknames either from a person's name (first name, initials, mixed parts, ...) or from word lists, then decorates them (leet speak, suffixes, reversal, ...) and formats their case.

Output is identical on every compiler and platform (dasmig-core): the case changes use a fixed mapping rather than the C locale, and word lists are read as UTF-8 in name order.

Can be used as a singleton via instance() or constructed independently.

Thread safety
Each instance is independent. Concurrent calls to get_nickname(request) on the same instance require external synchronisation. Seeded calls are read-only and can run concurrently, provided no word lists are changed.

Definition at line 198 of file nicknamegen.hpp.

Member Function Documentation

◆ data_hash()

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

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

Returns
The hash; 0 when nothing is loaded.

Definition at line 460 of file nicknamegen.hpp.

◆ extend()

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

Add word list layers from a directory or a file.

A directory is read like load() and all its files are applied together, or none if any is invalid. A .words file has one word per line; a .tsv file has a word column and may have disabled to remove words. The list name is the file name without extension; a new name adds a list.

Parameters
pathDirectory or file.
modeHow the layers combine with the words loaded before.
Exceptions
core::tsv_errorIf a file cannot be read or is invalid; the lists are then unchanged.
std::invalid_argumentIf path is a file that is neither .words nor .tsv.

Definition at line 397 of file nicknamegen.hpp.

◆ extend_from_string()

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

Add a layer to a word list from TSV text with a word column (and optionally disabled).

Parameters
listName of the list (a new name adds a list).
textTSV text.
sourceName used in errors.
modeHow the layer combines with the words loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf the text is invalid; the lists are unchanged.

Definition at line 426 of file nicknamegen.hpp.

◆ for_each_nickname() [1/2]

template<typename Sink >
void dasmig::nng::for_each_nickname ( const nickname_request &  request,
const core::batch_options &  options,
Sink &&  sink 
)
inline

Stream a batch of nickname results with a batch seed drawn like get_nickname() draws its own.

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

Definition at line 321 of file nicknamegen.hpp.

◆ for_each_nickname() [2/2]

template<typename Sink >
void dasmig::nng::for_each_nickname ( const nickname_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed,
Sink &&  sink 
) const
inline

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

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

Template Parameters
SinkCallable taking (std::uint64_t, nickname&); 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 306 of file nicknamegen.hpp.

◆ get_nickname() [1/2]

nickname dasmig::nng::get_nickname ( const nickname_request &  request)
inline

Generate a random nickname, optionally based on a name.

With a name, one in four nicknames is derived from it (always, when no word lists are loaded); the others come from the word lists.

Parameters
requestPer-call choices; use {} for a word-list nickname.
Returns
The generated nickname.
Exceptions
std::invalid_argumentIf request.name has no name parts and no word lists are loaded.

Definition at line 231 of file nicknamegen.hpp.

◆ get_nickname() [2/2]

nickname dasmig::nng::get_nickname ( const nickname_request &  request,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic nickname.

Parameters
requestPer-call choices; use {} for a word-list nickname.
call_seedSeed; the same seed, request and word lists give the same nickname.
Returns
The generated nickname.
Exceptions
std::invalid_argumentIf request.name has no name parts and no word lists are loaded.

Definition at line 243 of file nicknamegen.hpp.

◆ get_nickname_batch() [1/2]

std::vector< nickname > dasmig::nng::get_nickname_batch ( const nickname_request &  request,
const core::batch_options &  options 
)
inline

Generate a batch of nickname results from a seed drawn like get_nickname() draws its own.

Item i is get_nickname(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 263 of file nicknamegen.hpp.

◆ get_nickname_batch() [2/2]

std::vector< nickname > dasmig::nng::get_nickname_batch ( const nickname_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed 
) const
inline

Generate a batch of nickname results, deterministically.

Item i is exactly get_nickname(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 nickname).
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 284 of file nicknamegen.hpp.

◆ has_wordlists()

bool dasmig::nng::has_wordlists ( ) const
inline

Check whether any word list is loaded.

Returns
True when at least one non-empty word list is loaded.

Definition at line 330 of file nicknamegen.hpp.

◆ instance()

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

Access the global singleton instance.

Loads the shipped word lists on first access, from compiled-in data or an auto-probed resources/.

Returns
Reference to the global nng instance.

Definition at line 216 of file nicknamegen.hpp.

◆ layers()

const std::vector< core::layer_info > & dasmig::nng::layers ( const std::string &  list) const
inline

The layers in effect for one word list.

Parameters
listThe list name.
Returns
The layer records.
Exceptions
std::out_of_rangeIf there is no such list.

Definition at line 452 of file nicknamegen.hpp.

◆ list_names()

std::vector< std::string > dasmig::nng::list_names ( ) const
inline

Names of the loaded word lists, in the order they are used.

Returns
The list names (UTF-8).

Definition at line 438 of file nicknamegen.hpp.

◆ load() [1/2]

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

Load word lists from a directory, replacing all lists and layers loaded before.

Reads every .words file (one word per line) and .tsv file (a word column) below the directory, in path order. The list name is the file name without extension; files with the same name extend the same list. A path that is not a directory is ignored.

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

Definition at line 346 of file nicknamegen.hpp.

◆ load() [2/2]

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

Load the shipped word lists, replacing all lists and layers loaded before.

The library ships one tier: dataset::full loads the same lists as dataset::lite. Uses the compiled-in copy when built with DASMIG_NICKNAME_EMBED, otherwise searches resources/, ../resources, nickname-generator/resources and ../nickname-generator/resources.

Parameters
tierIgnored (one tier).
Returns
False when no word list was found.
Exceptions
core::tsv_errorIf a file is malformed.

Definition at line 365 of file nicknamegen.hpp.

Friends And Related Symbol Documentation

◆ ::nng_test_access

friend struct ::nng_test_access
friend

Definition at line 1477 of file nicknamegen.hpp.


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