Country Generator 3.3.2
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.
 
cntg & operator= (const cntg &)=delete
 Not copyable.
 
 cntg (cntg &&) noexcept=default
 Move constructor.
 
cntg & operator= (cntg &&) noexcept=default
 Move assignment.
 
 ~cntg ()=default
 Default destructor.
 
country get_country (const country_request &request)
 Generate a random country with per-call selection options.
 
country get_country (const country_request &request, std::uint64_t call_seed) const
 Generate a deterministic country with per-call selection options.
 
std::vector< country > get_country_batch (const country_request &request, const core::batch_options &options)
 Generate a batch of country results from a seed drawn like get_country() draws its own.
 
std::vector< country > get_country_batch (const country_request &request, const core::batch_options &options, std::uint64_t batch_seed) const
 Generate a batch of country results, deterministically.
 
template<typename Sink >
void for_each_country (const country_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const
 Stream a batch of country results to a sink without holding the whole batch.
 
template<typename Sink >
void for_each_country (const country_request &request, const core::batch_options &options, Sink &&sink)
 Stream a batch of country results with a batch seed drawn like get_country() draws its own.
 
country find_country (const std::string &cca2) const
 Look up a country by its ISO 3166-1 alpha-2 code.
 
std::string get_language (const std::string &cca2, std::uint64_t call_seed) const
 Draw a language a person of a country speaks, in proportion to the share of the population that speaks it.
 
locale get_locale (const locale_request &request)
 Draw a locale of a country, by speakers.
 
locale get_locale (const locale_request &request, std::uint64_t call_seed) const
 Draw a locale of a country, by speakers, deterministically.
 
std::vector< locale > get_locale_batch (const locale_request &request, const core::batch_options &options)
 Generate a batch of locales from a seed drawn like get_locale() draws its own.
 
std::vector< locale > get_locale_batch (const locale_request &request, const core::batch_options &options, std::uint64_t batch_seed) const
 Generate a batch of locales, deterministically: item i is get_locale(request, core::item_seed(batch_seed, options.first + i)).
 
template<typename Sink >
void for_each_locale (const locale_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const
 Stream a batch of locales to a sink without holding the batch.
 
template<typename Sink >
void for_each_locale (const locale_request &request, const core::batch_options &options, Sink &&sink)
 Stream a batch of locales with a batch seed drawn like get_locale() draws its own.
 
locale find_locale (std::string_view tag) const
 Look up a locale by its tag.
 
std::vector< locale > locales (std::string_view country) const
 Every locale of a country, largest share first, then by tag.
 
time_zone get_time_zone (const time_zone_request &request)
 Draw a time zone of a country, by population.
 
time_zone get_time_zone (const time_zone_request &request, std::uint64_t call_seed) const
 Draw a time zone of a country, by population, deterministically.
 
std::vector< time_zone > get_time_zone_batch (const time_zone_request &request, const core::batch_options &options)
 Generate a batch of time zones from a seed drawn like get_time_zone() draws its own.
 
std::vector< time_zone > get_time_zone_batch (const time_zone_request &request, const core::batch_options &options, std::uint64_t batch_seed) const
 Generate a batch of time zones, deterministically: item i is get_time_zone(request, core::item_seed(batch_seed, options.first + i)).
 
template<typename Sink >
void for_each_time_zone (const time_zone_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const
 Stream a batch of time zones to a sink without holding the batch.
 
template<typename Sink >
void for_each_time_zone (const time_zone_request &request, const core::batch_options &options, Sink &&sink)
 Stream a batch of time zones with a batch seed drawn like get_time_zone() draws its own.
 
time_zone find_time_zone (std::string_view name, std::chrono::year_month_day reference_date=time_zone_request::default_reference_date) const
 Look up a time zone by its IANA name.
 
std::vector< time_zone > time_zones (std::string_view country) const
 Every time zone of a country, largest share first, then by name, at the default reference date.
 
std::vector< holiday > holidays (const holiday_request &request) const
 A country's holidays in a year.
 
bool is_holiday (std::string_view country, std::chrono::year_month_day date, bool optional=false) const
 Whether a date is a holiday's date or its observed date.
 
year_span holiday_years (std::string_view country) const
 The years holidays() serves for a country.
 
std::uint8_t currency_digits (std::string_view code) const
 The ISO 4217 minor unit of a currency (0 for JPY, 3 for KWD).
 
bool has_locale_data () const
 Whether any locale table (locales, zones, currencies, holidays) is loaded.
 
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 &path)
 Load country data from a TSV file or a tier directory, replacing all data and layers loaded before.
 
bool load (dataset tier)
 Load a dataset tier, replacing all data and layers loaded before.
 
const core::layer_info & extend (const std::filesystem::path &file, core::layer_mode mode=core::layer_mode::override)
 Add a data layer from a TSV file with the countries.tsv columns.
 
const core::layer_info & extend_from_string (std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override)
 Add a data layer from TSV text.
 
const core::layer_info & extend (core::tsv_document doc, core::layer_mode mode=core::layer_mode::override)
 Add a data layer.
 
const core::layer_info & extend (country_table which, core::tsv_document doc, core::layer_mode mode=core::layer_mode::override)
 Add a data layer to one table.
 
const core::layer_info & extend (country_table which, const std::filesystem::path &file, core::layer_mode mode=core::layer_mode::override)
 Add a data layer to one table from a TSV file.
 
const core::layer_info & extend_from_string (country_table which, std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override)
 Add a data layer to one table from TSV text.
 
const std::vector< core::layer_info > & layers () const
 The data layers of countries.tsv in effect, in order.
 
const std::vector< core::layer_info > & layers (country_table which) const
 The data layers of one table in effect, in order.
 
std::uint64_t data_hash () const
 Hash of the loaded countries.tsv, recorded in each country's signature() (the locale tables have their own, which locales, zones and holidays record).
 

Static Public Member Functions

static cntg & instance ()
 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.

Next to the countries it holds each country's locales (with their CLDR formats), IANA time zones, currency minor units and national holidays, in their own tables (country_table), which load with the tier when they are there.

Output is identical on every compiler and platform (dasmig-core).

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

Thread safety
Each instance is independent. Concurrent calls to the unseeded getters on the same instance require external synchronization. Calls with an explicit seed and the lookups (find_*, locales(), time_zones(), holidays(), is_holiday()) only read data and may run concurrently. load() and extend() must not run concurrently with any of them.

Definition at line 1738 of file countrygen.hpp.

Member Function Documentation

◆ country_count()

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

Return the number of loaded countries.

Returns
The count.

Definition at line 2391 of file countrygen.hpp.

◆ currency_digits()

std::uint8_t dasmig::cntg::currency_digits ( std::string_view  code) const
inline

The ISO 4217 minor unit of a currency (0 for JPY, 3 for KWD).

Parameters
codeISO 4217 alphabetic code, any case.
Returns
The digits, 0 to 4.
Exceptions
std::runtime_errorIf the currency table is not loaded.
std::invalid_argumentFor an unknown code.

Definition at line 2364 of file countrygen.hpp.

◆ data_hash()

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

Hash of the loaded countries.tsv, recorded in each country's signature() (the locale tables have their own, which locales, zones and holidays record).

Returns
The hash; 0 when nothing is loaded.

Definition at line 2569 of file countrygen.hpp.

◆ extend() [1/4]

const core::layer_info & dasmig::cntg::extend ( const std::filesystem::path &  file,
core::layer_mode  mode = core::layer_mode::override 
)
inline

Add a data layer from a TSV file with the countries.tsv columns.

Rows are keyed by cca2. In the default override mode a row replaces the loaded country with the same code and new codes are added; a row with disabled set to 1 removes its country.

Parameters
fileThe layer file.
modeHow the layer combines with the data loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf the file cannot be read or a row is invalid; the data is then unchanged.

Definition at line 2466 of file countrygen.hpp.

◆ extend() [2/4]

const core::layer_info & dasmig::cntg::extend ( core::tsv_document  doc,
core::layer_mode  mode = core::layer_mode::override 
)
inline

Add a data layer.

Parameters
docTSV with the countries.tsv columns.
modeHow the layer combines with the data loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf a row is invalid; the data is unchanged.

Definition at line 2489 of file countrygen.hpp.

◆ extend() [3/4]

const core::layer_info & dasmig::cntg::extend ( country_table  which,
const std::filesystem::path &  file,
core::layer_mode  mode = core::layer_mode::override 
)
inline

Add a data layer to one table from a TSV file.

Parameters
whichThe table.
fileThe layer file.
modeHow the layer combines with the data loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf the file cannot be read or a row is invalid; the data is then unchanged.

Definition at line 2530 of file countrygen.hpp.

◆ extend() [4/4]

const core::layer_info & dasmig::cntg::extend ( country_table  which,
core::tsv_document  doc,
core::layer_mode  mode = core::layer_mode::override 
)
inline

Add a data layer to one table.

Rows are keyed by the table's key columns (doc/data.md). In the default override mode a row replaces the loaded row with the same key and new keys are added; a row with disabled set to 1 removes its key. A locale table's rows must name loaded countries, and refer to loaded rows of the other tables (a locale's currency, a link's zone, a holiday's event dates and span).

Parameters
whichThe table.
docTSV with that table's columns.
modeHow the layer combines with the data loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf a row is invalid; the data is unchanged.

Definition at line 2513 of file countrygen.hpp.

◆ extend_from_string() [1/2]

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

Add a data layer to one table from TSV text.

Parameters
whichThe table.
textTSV with that table's columns.
sourceName used in errors.
modeHow the layer combines with the data loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf a row is invalid; the data is unchanged.

Definition at line 2543 of file countrygen.hpp.

◆ extend_from_string() [2/2]

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

Add a data layer from TSV text.

Parameters
textTSV with the countries.tsv columns.
sourceName used in errors.
modeHow the layer combines with the data loaded before.
Returns
What the layer did.
Exceptions
core::tsv_errorIf a row is invalid; the data is unchanged.

Definition at line 2478 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 (seed 0).
Exceptions
std::runtime_errorIf no data has been loaded.
std::invalid_argumentIf no country matches the code.

Definition at line 1892 of file countrygen.hpp.

◆ find_locale()

locale dasmig::cntg::find_locale ( std::string_view  tag) const
inline

Look up a locale by its tag.

Accepts any case, _ for -, and a script where the tag has none (pt-Latn-BR is pt-BR): a script the table has no row of for that language and country is taken as the language's likely one.

Parameters
tagBCP 47 tag.
Returns
The locale (seed 0).
Exceptions
std::runtime_errorIf the locale tables are not loaded.
std::invalid_argumentIf no locale has the tag.

Definition at line 2087 of file countrygen.hpp.

◆ find_time_zone()

time_zone dasmig::cntg::find_time_zone ( std::string_view  name,
std::chrono::year_month_day  reference_date = time_zone_request::default_reference_date 
) const
inline

Look up a time zone by its IANA name.

Accepts IANA's backward links (Asia/Calcutta is Asia/Kolkata), which GeoNames and older systems write; the result's name is then the current one. A zone two countries share is returned with the country IANA lists it for.

Parameters
nameIANA name.
reference_dateThe date whose offset is reported, at 12:00 UTC.
Returns
The zone (seed 0).
Exceptions
std::runtime_errorIf the zone tables are not loaded.
std::invalid_argumentFor an unknown name or an invalid date.
std::out_of_rangeFor a reference date before the zone's data.

Definition at line 2255 of file countrygen.hpp.

◆ for_each_country() [1/2]

template<typename Sink >
void dasmig::cntg::for_each_country ( const country_request &  request,
const core::batch_options &  options,
Sink &&  sink 
)
inline

Stream a batch of country results with a batch seed drawn like get_country() draws its own.

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

Definition at line 1880 of file countrygen.hpp.

◆ for_each_country() [2/2]

template<typename Sink >
void dasmig::cntg::for_each_country ( const country_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed,
Sink &&  sink 
) const
inline

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

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

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

◆ for_each_locale() [1/2]

template<typename Sink >
void dasmig::cntg::for_each_locale ( const locale_request &  request,
const core::batch_options &  options,
Sink &&  sink 
)
inline

Stream a batch of locales with a batch seed drawn like get_locale() draws its own.

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

Definition at line 2072 of file countrygen.hpp.

◆ for_each_locale() [2/2]

template<typename Sink >
void dasmig::cntg::for_each_locale ( const locale_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed,
Sink &&  sink 
) const
inline

Stream a batch of locales to a sink without holding the batch.

Template Parameters
SinkCallable taking (std::uint64_t, locale&).
Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
batch_seedSeed of the whole batch.
sinkReceives the items, in index order.

Definition at line 2057 of file countrygen.hpp.

◆ for_each_time_zone() [1/2]

template<typename Sink >
void dasmig::cntg::for_each_time_zone ( const time_zone_request &  request,
const core::batch_options &  options,
Sink &&  sink 
)
inline

Stream a batch of time zones with a batch seed drawn like get_time_zone() draws its own.

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

Definition at line 2237 of file countrygen.hpp.

◆ for_each_time_zone() [2/2]

template<typename Sink >
void dasmig::cntg::for_each_time_zone ( const time_zone_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed,
Sink &&  sink 
) const
inline

Stream a batch of time zones to a sink without holding the batch.

Template Parameters
SinkCallable taking (std::uint64_t, time_zone&).
Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
batch_seedSeed of the whole batch.
sinkReceives the items, in index order.

Definition at line 2222 of file countrygen.hpp.

◆ get_country() [1/2]

country dasmig::cntg::get_country ( const country_request &  request)
inline

Generate a random country with per-call selection options.

Draws a call seed from the internal random engine. Replay with the same request, the returned country's seed and the same data.

Parameters
requestRegion filter and selection mode for this call.
Returns
A country object with all fields.
Exceptions
std::runtime_errorIf no data has been loaded.
std::invalid_argumentIf no countries match the requested region.

Definition at line 1771 of file countrygen.hpp.

◆ get_country() [2/2]

country dasmig::cntg::get_country ( const country_request &  request,
std::uint64_t  call_seed 
) const
inline

Generate a deterministic country with per-call selection options.

Does not advance the internal random engine. Replay with the same request, seed and data.

Parameters
requestRegion filter and selection mode for this call.
call_seedSeed for reproducible results.
Returns
A country object with all fields.
Exceptions
std::runtime_errorIf no data has been loaded.
std::invalid_argumentIf no countries match the requested region.

Definition at line 1785 of file countrygen.hpp.

◆ get_country_batch() [1/2]

std::vector< country > dasmig::cntg::get_country_batch ( const country_request &  request,
const core::batch_options &  options 
)
inline

Generate a batch of country results from a seed drawn like get_country() draws its own.

Item i is get_country(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 1822 of file countrygen.hpp.

◆ get_country_batch() [2/2]

std::vector< country > dasmig::cntg::get_country_batch ( const country_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed 
) const
inline

Generate a batch of country results, deterministically.

Item i is exactly get_country(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 country).
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 1843 of file countrygen.hpp.

◆ get_language()

std::string dasmig::cntg::get_language ( const std::string &  cca2,
std::uint64_t  call_seed 
) const
inline

Draw a language a person of a country speaks, in proportion to the share of the population that speaks it.

Falls back to the first of the country's languages when the data has no shares for it. A pure function of the data, the country and the seed.

Parameters
cca2ISO 3166-1 alpha-2 code.
call_seedThe call seed.
Returns
The language's English name.
Exceptions
std::runtime_errorIf no data has been loaded.
std::invalid_argumentIf no country matches the code, or the country has no language data.

Definition at line 1914 of file countrygen.hpp.

◆ get_locale() [1/2]

locale dasmig::cntg::get_locale ( const locale_request &  request)
inline

Draw a locale of a country, by speakers.

Draws a call seed from the internal random engine. Replay with the same request, the returned locale's seed and the same data.

Parameters
requestThe country, the language and the selection mode.
Returns
The locale.
Exceptions
std::runtime_errorIf the locale tables are not loaded.
std::invalid_argumentAs the seeded overload.

Definition at line 1941 of file countrygen.hpp.

◆ get_locale() [2/2]

locale dasmig::cntg::get_locale ( const locale_request &  request,
std::uint64_t  call_seed 
) const
inline

Draw a locale of a country, by speakers, deterministically.

The country is the request's, or else drawn from the "country" stream exactly as get_country() draws it, so get_locale({}, s).country_code == get_country({}, s).cca2 for every country with a locale (a drawn country with none, Antarctica in full, is replaced by a draw among the countries that have one). With only language set, the country is drawn among those with a locale of that language, by speakers. The tag is drawn from the "locale" stream, weighted by its share.

Parameters
requestThe country, the language and the selection mode.
call_seedSeed for reproducible results.
Returns
The locale.
Exceptions
std::runtime_errorIf no countries or no locale tables are loaded.
std::invalid_argumentFor an unknown country, a language no country has a locale of, or a country with no locale (of the language, when set).

Definition at line 1961 of file countrygen.hpp.

◆ get_locale_batch() [1/2]

std::vector< locale > dasmig::cntg::get_locale_batch ( const locale_request &  request,
const core::batch_options &  options 
)
inline

Generate a batch of locales from a seed drawn like get_locale() draws its own.

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
Returns
The results, in index order.

Definition at line 2027 of file countrygen.hpp.

◆ get_locale_batch() [2/2]

std::vector< locale > dasmig::cntg::get_locale_batch ( const locale_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed 
) const
inline

Generate a batch of locales, deterministically: item i is get_locale(request, core::item_seed(batch_seed, options.first + i)).

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
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 is loaded, or a unique batch runs out of attempts.

Definition at line 2042 of file countrygen.hpp.

◆ get_time_zone() [1/2]

time_zone dasmig::cntg::get_time_zone ( const time_zone_request &  request)
inline

Draw a time zone of a country, by population.

Parameters
requestThe country, the reference date and the selection mode.
Returns
The zone.
Exceptions
std::runtime_errorIf the zone tables are not loaded.
std::invalid_argumentAs the seeded overload.

Definition at line 2141 of file countrygen.hpp.

◆ get_time_zone() [2/2]

time_zone dasmig::cntg::get_time_zone ( const time_zone_request &  request,
std::uint64_t  call_seed 
) const
inline

Draw a time zone of a country, by population, deterministically.

The country is the request's, or else drawn from the "country" stream as get_country() draws it; the zone is drawn from the "time_zone" stream, weighted by its share of the population. The offset, abbreviation and daylight flag are those at the reference date, 12:00 UTC.

Parameters
requestThe country, the reference date and the selection mode.
call_seedSeed for reproducible results.
Returns
The zone.
Exceptions
std::runtime_errorIf no countries or no zone tables are loaded.
std::invalid_argumentFor an unknown country, one with no zone, or an invalid reference date.
std::out_of_rangeFor a reference date before the zone's data.

Definition at line 2161 of file countrygen.hpp.

◆ get_time_zone_batch() [1/2]

std::vector< time_zone > dasmig::cntg::get_time_zone_batch ( const time_zone_request &  request,
const core::batch_options &  options 
)
inline

Generate a batch of time zones from a seed drawn like get_time_zone() draws its own.

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
Returns
The results, in index order.

Definition at line 2192 of file countrygen.hpp.

◆ get_time_zone_batch() [2/2]

std::vector< time_zone > dasmig::cntg::get_time_zone_batch ( const time_zone_request &  request,
const core::batch_options &  options,
std::uint64_t  batch_seed 
) const
inline

Generate a batch of time zones, deterministically: item i is get_time_zone(request, core::item_seed(batch_seed, options.first + i)).

Parameters
requestWhat every item is generated from.
optionsCount, first index, threads and uniqueness.
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 is loaded, or a unique batch runs out of attempts.

Definition at line 2207 of file countrygen.hpp.

◆ has_data()

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

Check whether any data has been loaded.

Returns
True when at least one country is loaded.

Definition at line 2384 of file countrygen.hpp.

◆ has_locale_data()

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

Whether any locale table (locales, zones, currencies, holidays) is loaded.

Returns
False when only countries.tsv is.

Definition at line 2375 of file countrygen.hpp.

◆ holiday_years()

year_span dasmig::cntg::holiday_years ( std::string_view  country) const
inline

The years holidays() serves for a country.

Parameters
countryISO 3166-1 alpha-2 code, any case.
Returns
The span (python-holidays' years for the country, within 1970 to 2050).
Exceptions
std::runtime_errorIf no countries or no holiday tables are loaded.
std::invalid_argumentFor an unknown country, or one with no holiday data.

Definition at line 2354 of file countrygen.hpp.

◆ holidays()

std::vector< holiday > dasmig::cntg::holidays ( const holiday_request &  request) const
inline

A country's holidays in a year.

A lookup, not a draw: no seed. Sorted by date, then key, then day. Public and bank holidays always; optional days and observances when asked. A day off a weekend rule moves has observed set (design 8.4); a move python-holidays records but no rule gives is its own entry, named as python-holidays names it ("Christmas Day (observed)").

Parameters
requestThe country, the year and the kinds.
Returns
The holidays.
Exceptions
std::runtime_errorIf no countries or no holiday tables are loaded.
std::invalid_argumentFor an unknown country, or one with no holiday data.
std::out_of_rangeFor a year outside holiday_years().

Definition at line 2310 of file countrygen.hpp.

◆ instance()

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

Access the global singleton instance.

Loads the lite tier (or full if lite is missing) on first access, from compiled-in data or an auto-probed resources/.

Returns
Reference to the global cntg instance.

Definition at line 1755 of file countrygen.hpp.

◆ is_holiday()

bool dasmig::cntg::is_holiday ( std::string_view  country,
std::chrono::year_month_day  date,
bool  optional = false 
) const
inline

Whether a date is a holiday's date or its observed date.

Looks at the holidays of the year before and after too, since an observed day can cross New Year (the US's New Year's Day 2022 was observed on 2021-12-31).

Parameters
countryISO 3166-1 alpha-2 code, any case.
dateThe date.
optionalCount holiday_kind::optional days too.
Returns
True for a public or bank holiday (or optional, if asked).
Exceptions
std::runtime_errorIf no countries or no holiday tables are loaded.
std::invalid_argumentFor an unknown country, one with no holiday data, or an invalid date.
std::out_of_rangeFor a date whose year is outside holiday_years().

Definition at line 2331 of file countrygen.hpp.

◆ layers() [1/2]

const std::vector< core::layer_info > & dasmig::cntg::layers ( ) const
inline

The data layers of countries.tsv in effect, in order.

Returns
The layer records.

Definition at line 2551 of file countrygen.hpp.

◆ layers() [2/2]

const std::vector< core::layer_info > & dasmig::cntg::layers ( country_table  which) const
inline

The data layers of one table in effect, in order.

Parameters
whichThe table.
Returns
The layer records.

Definition at line 2559 of file countrygen.hpp.

◆ load() [1/2]

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

Load country data from a TSV file or a tier directory, replacing all data and layers loaded before.

A file is countries.tsv (see doc/data.md); the locale tables are then left as they are. A directory such as resources/lite must hold countries.tsv and loads every other table it holds; the ones it does not hold are cleared. Any other path is ignored.

Parameters
pathPath to the TSV file or the directory.
Exceptions
core::tsv_errorIf a file is malformed; the data is then unchanged.

Definition at line 2407 of file countrygen.hpp.

◆ load() [2/2]

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

Load a dataset tier, replacing all data and layers loaded before.

Loads countries.tsv, then every locale table of the tier it finds (a missing one is cleared). Each uses the compiled-in copy when the library is built with DASMIG_COUNTRY_EMBED (the countries) or DASMIG_COUNTRY_EMBED_LOCALE (the locale tables), otherwise searches resources/, ../resources, country-generator/resources and ../country-generator/resources. The locale tables are read from the first of those that has both the tier's countries.tsv and its locales.tsv, so another library's locales.tsv is never read.

Parameters
tierThe dataset size to load.
Returns
true if the tier's countries.tsv was found and loaded.
Exceptions
core::tsv_errorIf a file is malformed; the data is then unchanged.

Definition at line 2437 of file countrygen.hpp.

◆ locales()

std::vector< locale > dasmig::cntg::locales ( std::string_view  country) const
inline

Every locale of a country, largest share first, then by tag.

Parameters
countryISO 3166-1 alpha-2 code, any case.
Returns
The locales (seed 0); empty for a country with none.
Exceptions
std::runtime_errorIf no countries or no locale tables are loaded.
std::invalid_argumentFor an unknown country.

Definition at line 2118 of file countrygen.hpp.

◆ time_zones()

std::vector< time_zone > dasmig::cntg::time_zones ( std::string_view  country) const
inline

Every time zone of a country, largest share first, then by name, at the default reference date.

Parameters
countryISO 3166-1 alpha-2 code, any case.
Returns
The zones (seed 0); empty for a country with none.
Exceptions
std::runtime_errorIf no countries or no zone tables are loaded.
std::invalid_argumentFor an unknown country.

Definition at line 2278 of file countrygen.hpp.


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