![]() |
City Generator 1.0.1
Procedural city generation for C++23
|
City generator that produces random cities from GeoNames data. More...
#include <citygen.hpp>
Public Member Functions | |
| cg ()=default | |
| Default constructor — creates an empty generator with no data. | |
| cg (const cg &)=delete | |
| Not copyable. | |
| cg & | operator= (const cg &)=delete |
| Not copyable. | |
| cg (cg &&)=default | |
| Move constructor. | |
| cg & | operator= (cg &&)=default |
| Move assignment. | |
| ~cg ()=default | |
| Default destructor. | |
| city | get_city () |
| Generate a random city. | |
| city | get_city (std::uint64_t call_seed) const |
| Generate a deterministic city using a specific seed. | |
| city | get_city (const std::string &country) |
| Generate a random city filtered by country code. | |
| city | get_city (const std::string &country, std::uint64_t call_seed) const |
| Generate a deterministic city filtered by country code. | |
| cg & | weighted (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 city data has been loaded. | |
| std::size_t | city_count () const |
| Return the number of loaded cities. | |
| void | load (const std::filesystem::path &tsv_path) |
| Load city data from a TSV file. | |
| bool | load (dataset tier) |
| Load a specific dataset tier from a base resources directory. | |
Seeding | |
| cg & | seed (std::uint64_t seed_value) |
| Seed the internal random engine for deterministic sequences. | |
| cg & | unseed () |
| Reseed the engine with a non-deterministic source. | |
Static Public Member Functions | |
| static cg & | instance () |
| Access the global singleton instance. | |
City generator that produces random cities from GeoNames data.
Generates cities using population-weighted random selection from GeoNames data. Larger cities are proportionally more likely to be selected, mirroring real-world population distributions.
Can be used as a singleton via instance() or constructed independently. Independent instances own their own data and random engine, making them safe for concurrent use without shared state.
Definition at line 139 of file citygen.hpp.
|
default |
Default constructor — creates an empty generator with no data.
Call load() to populate city data before generating.
|
inline |
|
inline |
Generate a random city.
By default, selection is population-weighted. Call weighted(false) to switch to uniform random selection.
| std::runtime_error | If no city data has been loaded. |
Definition at line 171 of file citygen.hpp.
|
inline |
Generate a random city filtered by country code.
| country | ISO-3166 two-letter country code (e.g., "BR", "US"). |
| std::runtime_error | If no city data has been loaded. |
| std::invalid_argument | If no cities match the country code. |
Definition at line 210 of file citygen.hpp.
|
inline |
Generate a deterministic city filtered by country code.
| country | ISO-3166 two-letter country code. |
| call_seed | Seed for reproducible results. |
| std::runtime_error | If no city data has been loaded. |
| std::invalid_argument | If no cities match the country code. |
Definition at line 222 of file citygen.hpp.
|
inline |
Generate a deterministic city using a specific seed.
Given the same loaded data and seed, this method always produces the same city. Retrieve the seed from a previous city via city::seed().
| call_seed | Seed for reproducible results. |
| std::runtime_error | If no city data has been loaded. |
Definition at line 185 of file citygen.hpp.
|
inline |
Check whether any city data has been loaded.
true if at least one city is available. Definition at line 303 of file citygen.hpp.
|
inlinestatic |
Access the global singleton instance.
The singleton auto-probes common resource paths on first access. For independent generators (e.g., inside an entity-generator component), prefer constructing a separate cg instance.
Definition at line 159 of file citygen.hpp.
|
inline |
Load city data from a TSV file.
Expects a tab-delimited file with a header row and 16 columns matching the GeoNames schema (as produced by scripts/prepare_geonames.py). Safe to call multiple times to add from different files.
| tsv_path | Path to the TSV file. |
Definition at line 323 of file citygen.hpp.
|
inline |
Load a specific dataset tier from a base resources directory.
Probes common base paths ("resources", "../resources", "city-generator/resources") and loads from the lite/ or full/ subfolder according to tier.
| tier | The dataset size to load (dataset::lite or dataset::full). |
true if a matching directory was found and loaded. Definition at line 376 of file citygen.hpp.
|
inline |
Seed the internal random engine for deterministic sequences.
Subsequent get_city() calls (without an explicit seed) draw per-call seeds from this engine, producing a reproducible sequence.
| seed_value | The seed value. |
*this for chaining. Definition at line 263 of file citygen.hpp.
|
inline |
Reseed the engine with a non-deterministic source.
Subsequent get_city() calls will produce non-reproducible results.
*this for chaining. Definition at line 273 of file citygen.hpp.
|
inline |
Query whether generation is population-weighted.
true if weighted (default), false if uniform. Definition at line 296 of file citygen.hpp.
|
inline |
Set whether generation is population-weighted or uniform.
When true (default), larger cities are proportionally more likely to be selected. When false, every city has an equal probability.
| enable | true for weighted, false for uniform. |
*this for chaining. Definition at line 288 of file citygen.hpp.