|
Address Generator 2.1.2
Postal addresses with real streets by place, laid out in each country's format for C++23
|
Address Generator: postal addresses with real streets by place. More...
#include <addressgen.hpp>
Public Member Functions | |
| adg () | |
| Default constructor — creates an empty generator with no data. | |
| adg (const adg &)=delete | |
| Not copyable. | |
| adg & | operator= (const adg &)=delete |
| Not copyable. | |
| adg (adg &&) noexcept=default | |
| Movable. | |
| adg & | operator= (adg &&) noexcept=default |
| Movable. | |
| ~adg ()=default | |
| Destructor. | |
| address | get_address (const address_request &request) |
| Generate a random address. Use address_request{} for the defaults. | |
| address | get_address (const address_request &request, std::uint64_t call_seed) const |
| Generate a deterministic address. | |
| street | get_street (const street_request &request) |
| Generate a random street. Use street_request{} for the defaults. | |
| street | get_street (const street_request &request, std::uint64_t call_seed) const |
| Generate a deterministic street. | |
| std::vector< street > | get_street_batch (const street_request &request, const core::batch_options &options) |
| Generate a batch of streets from a seed drawn like get_street() draws its own. | |
| std::vector< street > | get_street_batch (const street_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
| Generate a batch of streets, deterministically. | |
| template<typename Sink > | |
| void | for_each_street (const street_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| Stream a batch of streets to a sink without holding the whole batch. | |
| template<typename Sink > | |
| void | for_each_street (const street_request &request, const core::batch_options &options, Sink &&sink) |
| Stream a batch of streets with a batch seed drawn like get_street() draws its own. | |
| std::string | get_postcode (const postcode_request &request) |
| Generate a random postcode in the country's format. Use postcode_request{} for the defaults. | |
| std::string | get_postcode (const postcode_request &request, std::uint64_t call_seed) const |
| Generate a deterministic postcode. | |
| std::vector< std::string > | get_postcode_batch (const postcode_request &request, const core::batch_options &options) |
| Generate a batch of postcodes from a seed drawn like get_postcode() draws its own. | |
| std::vector< std::string > | get_postcode_batch (const postcode_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
| Generate a batch of postcodes, deterministically. | |
| template<typename Sink > | |
| void | for_each_postcode (const postcode_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| Stream a batch of postcodes to a sink without holding the whole batch. | |
| template<typename Sink > | |
| void | for_each_postcode (const postcode_request &request, const core::batch_options &options, Sink &&sink) |
| Stream a batch of postcodes with a batch seed drawn like get_postcode() draws its own. | |
| std::vector< address > | get_address_batch (const address_request &request, const core::batch_options &options) |
| Generate a batch of address results from a seed drawn like get_address() draws its own. | |
| std::vector< address > | get_address_batch (const address_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
| Generate a batch of address results, deterministically. | |
| template<typename Sink > | |
| void | for_each_address (const address_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| Stream a batch of address results to a sink without holding the whole batch. | |
| template<typename Sink > | |
| void | for_each_address (const address_request &request, const core::batch_options &options, Sink &&sink) |
| Stream a batch of address results with a batch seed drawn like get_address() draws its own. | |
| bool | has_data () const |
| Check whether any data has been loaded. | |
| std::size_t | place_count () const |
| Return the number of loaded places. | |
| std::size_t | country_count () const |
| Return the number of countries that have places. | |
| const std::vector< std::string > & | countries () const |
| The countries that have places, sorted. | |
| bool | has_streets (std::string_view code) const |
| Whether a country has real streets for at least one place. | |
| bool | load_streets (std::string_view code) const |
| Load the street data of one country now, instead of on the first call that needs it. | |
| bool | streets_loaded (std::string_view code) const |
| Whether a country's street data is in memory. | |
| void | load (const std::filesystem::path &dir) |
| Load data from a resource directory, replacing all data and layers loaded before. | |
| bool | load (dataset tier) |
| Load a dataset tier, replacing all data and layers loaded before. | |
| void | extend (const std::filesystem::path &path, core::layer_mode mode=core::layer_mode::override) |
| Add data layers from a directory or a file. | |
| const core::layer_info & | extend (address_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_from_string (address_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 (for example from a WebAssembly host). | |
| const std::vector< core::layer_info > & | layers (address_table which) const |
| The layers in effect for one table, in order. | |
| std::uint64_t | data_hash () const |
| Hash of the loaded data (all tables), recorded in each result's signature(). | |
Static Public Member Functions | |
| static adg & | instance () |
| Access the global singleton instance. | |
Address Generator: postal addresses with real streets by place.
A call draws a country (by population), a place in it (by population), a street of that place (by address count), a house number, a unit and a postcode, each from a stream split from the call seed ("country", "place", "street", "number", "unit", "postcode"), and lays the address out in the country's order. Places without street data get a composed street. Output is identical on every compiler and platform (dasmig-core).
Can be used as a singleton via instance() or constructed independently.
full country's street file; calls that use the instance engine, loading and extending require external synchronisation. Definition at line 311 of file addressgen.hpp.
|
inline |
Default constructor — creates an empty generator with no data.
Definition at line 316 of file addressgen.hpp.
|
inline |
The countries that have places, sorted.
Definition at line 671 of file addressgen.hpp.
|
inline |
Return the number of countries that have places.
Definition at line 667 of file addressgen.hpp.
|
inline |
Hash of the loaded data (all tables), recorded in each result's signature().
Definition at line 849 of file addressgen.hpp.
|
inline |
Add a data layer to one table.
Rows are keyed by the table's key columns (see 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.
| which | The table. |
| doc | TSV with that table's columns. |
| mode | How the layer combines with the data loaded before. |
| core::tsv_error | If a row is invalid; the data is unchanged. |
Definition at line 815 of file addressgen.hpp.
|
inline |
Add data layers from a directory or a file.
A directory may hold any of the table files (see address_table); all are applied together or, if any fails, none. A file must have one of those names.
| path | Directory or file. |
| mode | How the layers combine with the data loaded before. |
| core::tsv_error | If a file cannot be read or a row is invalid; the data is then unchanged. |
| std::invalid_argument | If path is a file with another name. |
Definition at line 784 of file addressgen.hpp.
|
inline |
Add a data layer to one table from TSV text (for example from a WebAssembly host).
| which | The table. |
| text | TSV with that table's columns. |
| source | Name used in errors. |
| mode | How the layer combines with the data loaded before. |
| core::tsv_error | If a row is invalid; the data is unchanged. |
Definition at line 832 of file addressgen.hpp.
|
inline |
Stream a batch of address results with a batch seed drawn like get_address() draws its own.
| Sink | Callable taking (std::uint64_t, address&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 649 of file addressgen.hpp.
|
inline |
Stream a batch of address results to a sink without holding the whole batch.
Generates the same items as get_address_batch() and calls sink(index, item) in index order on the calling thread; index includes options.first.
| Sink | Callable taking (std::uint64_t, address&); for example core::jsonl_writer or core::csv_writer. |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items. |
Definition at line 634 of file addressgen.hpp.
|
inline |
Stream a batch of postcodes with a batch seed drawn like get_postcode() draws its own.
| Sink | Callable taking (std::uint64_t, std::string&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 575 of file addressgen.hpp.
|
inline |
Stream a batch of postcodes to a sink without holding the whole batch.
| Sink | Callable taking (std::uint64_t, std::string&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items, in index order, on the calling thread. |
Definition at line 561 of file addressgen.hpp.
|
inline |
Stream a batch of streets with a batch seed drawn like get_street() draws its own.
| Sink | Callable taking (std::uint64_t, street&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| sink | Receives the items. |
Definition at line 493 of file addressgen.hpp.
|
inline |
Stream a batch of streets to a sink without holding the whole batch.
| Sink | Callable taking (std::uint64_t, street&). |
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
| batch_seed | Seed of the whole batch. |
| sink | Receives the items, in index order, on the calling thread. |
Definition at line 479 of file addressgen.hpp.
|
inline |
Generate a random address. Use address_request{} for the defaults.
| request | What to generate. |
| std::runtime_error | If no data has been loaded. |
| std::invalid_argument | If the request names an unknown country or place. |
Definition at line 344 of file addressgen.hpp.
|
inline |
Generate a deterministic address.
| request | What to generate. |
| call_seed | Seed; the same request, seed and data give the same result. Does not touch the instance engine. |
| std::runtime_error | If no data has been loaded. |
| std::invalid_argument | If the request names an unknown country or place. |
Definition at line 357 of file addressgen.hpp.
|
inline |
Generate a batch of address results from a seed drawn like get_address() draws its own.
Item i is get_address(request, core::item_seed(batch_seed, options.first + i)) for the drawn batch seed; see the seeded overload.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 591 of file addressgen.hpp.
|
inline |
Generate a batch of address results, deterministically.
Item i is exactly get_address(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.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (see core::unique_rule; the rule must be made for address). |
| batch_seed | Seed of the whole batch. |
| std::invalid_argument | If the request or options are invalid. |
| std::runtime_error | If no data has been loaded, or a unique batch runs out of attempts. |
Definition at line 612 of file addressgen.hpp.
|
inline |
Generate a random postcode in the country's format. Use postcode_request{} for the defaults.
| request | What to generate. |
| std::runtime_error | If no data has been loaded. |
| std::invalid_argument | If the request names an unknown country or place. |
Definition at line 504 of file addressgen.hpp.
|
inline |
Generate a deterministic postcode.
Draws from the same streams as get_address(), so for the same request fields and seed it is the postcode of that address.
| request | What to generate. |
| call_seed | Seed; does not touch the instance engine. |
| std::runtime_error | If no data has been loaded. |
| std::invalid_argument | If the request names an unknown country or place. |
Definition at line 519 of file addressgen.hpp.
|
inline |
Generate a batch of postcodes from a seed drawn like get_postcode() draws its own.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 532 of file addressgen.hpp.
|
inline |
Generate a batch of postcodes, deterministically.
Item i is get_postcode(request, core::item_seed(batch_seed, options.first + i)).
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (a rule made for std::string). |
| batch_seed | Seed of the whole batch. |
Definition at line 546 of file addressgen.hpp.
|
inline |
Generate a random street. Use street_request{} for the defaults.
| request | What to generate. |
| std::runtime_error | If no data has been loaded. |
| std::invalid_argument | If the request names an unknown country or place. |
Definition at line 414 of file addressgen.hpp.
|
inline |
Generate a deterministic street.
Draws from the same streams as get_address(), so for the same request fields and seed it is the street of that address.
| request | What to generate. |
| call_seed | Seed; does not touch the instance engine. |
| std::runtime_error | If no data has been loaded. |
| std::invalid_argument | If the request names an unknown country or place. |
Definition at line 429 of file addressgen.hpp.
|
inline |
Generate a batch of streets from a seed drawn like get_street() draws its own.
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness. |
Definition at line 450 of file addressgen.hpp.
|
inline |
Generate a batch of streets, deterministically.
Item i is get_street(request, core::item_seed(batch_seed, options.first + i)).
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (a rule made for street). |
| batch_seed | Seed of the whole batch. |
Definition at line 464 of file addressgen.hpp.
|
inline |
Check whether any data has been loaded.
Definition at line 659 of file addressgen.hpp.
|
inline |
Whether a country has real streets for at least one place.
| code | ISO 3166-1 alpha-2. |
Definition at line 676 of file addressgen.hpp.
|
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/.
Definition at line 329 of file addressgen.hpp.
|
inline |
The layers in effect for one table, in order.
| which | The table. |
Definition at line 841 of file addressgen.hpp.
|
inline |
Load data from a resource directory, replacing all data and layers loaded before.
The directory must contain places.tsv; the other tables are read when present. A path without places.tsv is ignored.
| dir | Directory such as resources/lite. |
| core::tsv_error | If a file is malformed; the data is then unchanged. |
Definition at line 720 of file addressgen.hpp.
|
inline |
Load a dataset tier, replacing all data and layers loaded before.
Uses the compiled-in copy when the library is built with DASMIG_ADDRESS_EMBED, otherwise searches resources/, ../resources, address-generator/resources and ../address-generator/resources.
| tier | The tier. |
| core::tsv_error | If a file is malformed. |
Definition at line 748 of file addressgen.hpp.
|
inline |
Load the street data of one country now, instead of on the first call that needs it.
Only the full tier keeps its streets in one file per country; for the other data this does nothing. Safe to call from several threads.
| code | ISO 3166-1 alpha-2. |
| std::runtime_error | If the country's file is missing or does not match streets.manifest.tsv. |
| core::tsv_error | If the file is malformed. |
Definition at line 693 of file addressgen.hpp.
|
inline |
Return the number of loaded places.
Definition at line 663 of file addressgen.hpp.
|
inline |
Whether a country's street data is in memory.
| code | ISO 3166-1 alpha-2. |
lite data (always loaded) and for a full country once a call or load_streets() has read its file. Definition at line 704 of file addressgen.hpp.