Country Generator 1.0.1
Procedural country generation for C++23
Loading...
Searching...
No Matches
dasmig::cntg Class Reference

Country generator that produces random countries from aggregated open-data sources. More...

#include <countrygen.hpp>

Public Member Functions

 cntg ()=default
 Default constructor — creates an empty generator with no data.
 
 cntg (const cntg &)=delete
 Not copyable.
 
cntgoperator= (const cntg &)=delete
 Not copyable.
 
 cntg (cntg &&) noexcept=default
 Move constructor.
 
cntgoperator= (cntg &&) noexcept=default
 Move assignment.
 
 ~cntg ()=default
 Default destructor.
 
country get_country ()
 Generate a random country.
 
country get_country (std::uint64_t call_seed) const
 Generate a deterministic country using a specific seed.
 
country get_country (const std::string &rgn)
 Generate a random country filtered by region.
 
country get_country (const std::string &rgn, std::uint64_t call_seed) const
 Generate a deterministic country filtered by region.
 
country find_country (const std::string &cca2) const
 Look up a country by its ISO 3166-1 alpha-2 code.
 
cntgweighted (bool enable)
 Set whether generation is population-weighted or uniform.
 
bool weighted () const
 Query whether generation is population-weighted.
 
bool has_data () const
 Check whether any data has been loaded.
 
std::size_t country_count () const
 Return the number of loaded countries.
 
void load (const std::filesystem::path &tsv_path)
 Load country data from a TSV file.
 
bool load (dataset tier)
 Load a specific dataset tier from a base resources directory.
 
Seeding
cntgseed (std::uint64_t seed_value)
 Seed the internal random engine for deterministic sequences.
 
cntgunseed ()
 Reseed the engine with a non-deterministic source.
 

Static Public Member Functions

static cntginstance ()
 Access the global singleton instance.
 

Detailed Description

Country generator that produces random countries from aggregated open-data sources.

Generates countries using population-weighted random selection by default. Larger countries are proportionally more likely to be selected, mirroring real-world demographic distributions.

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

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

Definition at line 197 of file countrygen.hpp.

Member Function Documentation

◆ country_count()

std::size_t dasmig::cntg::country_count ( ) const
inline

Return the number of loaded countries.

Definition at line 378 of file countrygen.hpp.

◆ find_country()

country dasmig::cntg::find_country ( const std::string &  cca2) const
inline

Look up a country by its ISO 3166-1 alpha-2 code.

Parameters
cca2Two-letter country code (e.g. "US", "BR").
Returns
The matching country object.
Exceptions
std::runtime_errorIf no data has been loaded.
std::invalid_argumentIf no country matches the code.

Definition at line 311 of file countrygen.hpp.

◆ get_country() [1/4]

country dasmig::cntg::get_country ( )
inline

Generate a random country.

By default, selection is population-weighted. Call weighted(false) to switch to uniform random selection.

Returns
A country object with all fields.
Exceptions
std::runtime_errorIf no data has been loaded.

Definition at line 227 of file countrygen.hpp.

◆ get_country() [2/4]

country dasmig::cntg::get_country ( const std::string &  rgn)
inline

Generate a random country filtered by region.

Parameters
rgnUN geoscheme region (e.g. "Europe", "Asia").
Returns
A country object from the specified region.
Exceptions
std::runtime_errorIf no data has been loaded.
std::invalid_argumentIf no countries match the region.

Definition at line 262 of file countrygen.hpp.

◆ get_country() [3/4]

country dasmig::cntg::get_country ( const std::string &  rgn,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic country filtered by region.

Parameters
rgnUN geoscheme region.
call_seedSeed for reproducible results.
Returns
A country object from the specified region.
Exceptions
std::runtime_errorIf no data has been loaded.
std::invalid_argumentIf no countries match the region.

Definition at line 274 of file countrygen.hpp.

◆ get_country() [4/4]

country dasmig::cntg::get_country ( std::uint64_t  call_seed) const
inline

Generate a deterministic country using a specific seed.

Parameters
call_seedSeed for reproducible results.
Returns
A country object with all fields.
Exceptions
std::runtime_errorIf no data has been loaded.

Definition at line 237 of file countrygen.hpp.

◆ has_data()

bool dasmig::cntg::has_data ( ) const
inline

Check whether any data has been loaded.

Definition at line 372 of file countrygen.hpp.

◆ instance()

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

Access the global singleton instance.

The singleton auto-probes common resource paths on first access.

Returns
Reference to the global cntg instance.

Definition at line 213 of file countrygen.hpp.

◆ load() [1/2]

void dasmig::cntg::load ( const std::filesystem::path &  tsv_path)
inline

Load country data from a TSV file.

Expects a tab-delimited file with a header row and 31 columns matching the schema produced by scripts/prepare_countries.py. Safe to call multiple times.

Parameters
tsv_pathPath to the TSV file.

Definition at line 390 of file countrygen.hpp.

◆ load() [2/2]

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

Load a specific dataset tier from a base resources directory.

Parameters
tierThe dataset size to load.
Returns
true if a matching directory was found and loaded.

Definition at line 437 of file countrygen.hpp.

◆ seed()

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

Seed the internal random engine for deterministic sequences.

Parameters
seed_valueThe seed value.
Returns
*this for chaining.

Definition at line 337 of file countrygen.hpp.

◆ unseed()

cntg & dasmig::cntg::unseed ( )
inline

Reseed the engine with a non-deterministic source.

Returns
*this for chaining.

Definition at line 345 of file countrygen.hpp.

◆ weighted() [1/2]

bool dasmig::cntg::weighted ( ) const
inline

Query whether generation is population-weighted.

Returns
true if weighted (default), false if uniform.

Definition at line 364 of file countrygen.hpp.

◆ weighted() [2/2]

cntg & dasmig::cntg::weighted ( bool  enable)
inline

Set whether generation is population-weighted or uniform.

Parameters
enabletrue for weighted (default), false for uniform.
Returns
*this for chaining.

Definition at line 356 of file countrygen.hpp.


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