![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
Namespaces | |
| namespace | detail |
| namespace | formats |
Classes | |
| struct | DbDeleter |
| Unique-pointer deleter using SQLite deferred close semantics. More... | |
| struct | DecodedLinestring |
| struct | DecodedMultipolygon |
| struct | DecodedPoint |
| struct | FilePathPair |
Two-string carrier for any external file path that appears in a SWMM .inp file. More... | |
| class | GeoPackageInputPlugin |
| Own configuration and input IO state for a GeoPackage adapter. More... | |
| class | GeoPackageOutputPlugin |
| Own configuration and output IO state for a GeoPackage adapter. More... | |
| class | GeoPackagePluginInfo |
| IPluginComponentInfo for the GeoPackage I/O plugin. More... | |
| class | GeoPackageReportPlugin |
| Own configuration and report IO state for a GeoPackage adapter. More... | |
| class | GpkgError |
| Runtime-error carrier for owned GeoPackage/SQLite diagnostic text. More... | |
| struct | SimulationContext |
| Central, reentrant simulation context. More... | |
| struct | StmtDeleter |
| Unique-pointer deleter that finalizes prepared statements. More... | |
| class | Transaction |
| Noncopyable best-effort transaction guard borrowing one SQLite connection. More... | |
Typedefs | |
| using | DbPtr = std::unique_ptr<sqlite3, DbDeleter> |
| using | StmtPtr = std::unique_ptr<sqlite3_stmt, StmtDeleter> |
Enumerations | |
| enum | WkbType : uint32_t { WKB_POINT = 1 , WKB_LINESTRING = 2 , WKB_POLYGON = 3 , WKB_MULTIPOLYGON = 6 } |
| enum class | TableType |
| Type of data stored in a Table. More... | |
| enum class | FileMode |
Mode keyword for one [FILES] row — SAVE or USE. More... | |
| enum class | TableType |
| Type of data stored in a Table. More... | |
| enum class | FileMode |
Mode keyword for one [FILES] row — SAVE or USE. More... | |
Functions | |
| std::string | scratchDirFor (const std::string &gpkg_path) |
| Construct the portable sibling scratch-directory name for a GeoPackage path. | |
| void | read_external_content (sqlite3 *db, openswmm::SimulationContext &ctx, const std::string &simulation_id, const std::string &scratch_dir) |
| Hydrate model external slots from embedded GeoPackage content and scratch files. | |
| void | write_external_content (sqlite3 *db, const openswmm::SimulationContext &ctx, const std::string &simulation_id) |
| Populate embedded external-input content tables from a model's file slots. | |
| int | read_model (sqlite3 *db, SimulationContext &ctx, const std::string &simulation_id, const std::string &scratch_dir="") |
| Read a model definition from a GeoPackage into a SimulationContext. | |
| int | read_from_file (const std::string &path, SimulationContext &ctx, const std::string &simulation_id) |
| Convenience: open a GeoPackage file and read a model. | |
| void | create_schema (sqlite3 *db) |
| Create all GeoPackage metadata tables and OpenSWMM application tables. | |
| void | register_crs (sqlite3 *db, int srs_id, const std::string &org, int org_id, const std::string &srs_name, const std::string &wkt) |
| Register a CRS in gpkg_spatial_ref_sys (if not already present). | |
| void | register_feature_table (sqlite3 *db, const std::string &table_name, const std::string &geom_type, int srs_id, const std::string &identifier, const std::string &description, double min_x, double min_y, double max_x, double max_y) |
| Register a feature table in gpkg_contents and gpkg_geometry_columns. | |
| void | populate_default_variables (sqlite3 *db) |
| Pre-populate the variables catalog with known SWMM output variables. | |
| void | write_model (sqlite3 *db, const SimulationContext &ctx, const std::string &simulation_id, int srs_id=0) |
| Write the full model definition from a SimulationContext into a GeoPackage. | |
| int | write_to_file (const std::string &path, const SimulationContext &ctx, const std::string &simulation_id) |
| Convenience: create a new GeoPackage file, write schema + model. | |
| std::vector< uint8_t > | encode_point (double x, double y, int32_t srs_id) |
| Encode an XY point with a matching XY envelope. | |
| std::vector< uint8_t > | encode_linestring (const std::vector< double > &xs, const std::vector< double > &ys, int32_t srs_id) |
| Encode an XY LINESTRING. | |
| std::vector< uint8_t > | encode_multipolygon (const std::vector< double > &xs, const std::vector< double > &ys, int32_t srs_id) |
| Encode closed-ring spatial coordinates in MULTIPOLYGON form. | |
| std::vector< uint8_t > | encode_polygon (const std::vector< double > &xs, const std::vector< double > &ys, int32_t srs_id) |
| Encode a single exterior ring in POLYGON form. | |
| DecodedPoint | decode_point (const std::vector< uint8_t > &blob) |
| Decode POINT coordinates from a prevalidated native-endian GP blob. | |
| DecodedLinestring | decode_linestring (const std::vector< uint8_t > &blob) |
| Decode LINESTRING coordinates from a prevalidated native-endian GP blob. | |
| DecodedMultipolygon | decode_multipolygon (const std::vector< uint8_t > &blob) |
| Decode MULTIPOLYGON coordinates from a prevalidated native-endian GP blob. | |
| DbPtr | open_database (const std::string &path, int flags=SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE) |
| Open an owned connection and configure GeoPackage connection defaults. | |
| StmtPtr | prepare (sqlite3 *db, const std::string &sql) |
| Prepare the first SQL statement without stepping it. | |
| void | exec (sqlite3 *db, const std::string &sql) |
| Execute SQL text and discard all returned rows. | |
| void | bind_text (sqlite3_stmt *stmt, int col, const std::string &val) |
| Bind a copied SQL text parameter, discarding SQLite status. | |
| void | bind_double (sqlite3_stmt *stmt, int col, double val) |
| Bind a floating SQL parameter, discarding SQLite status. | |
| void | bind_int (sqlite3_stmt *stmt, int col, int val) |
| Bind an int SQL parameter, discarding SQLite status. | |
| void | bind_null (sqlite3_stmt *stmt, int col) |
| Bind SQL NULL, discarding SQLite status. | |
| void | bind_blob (sqlite3_stmt *stmt, int col, const void *data, int size) |
| Bind copied binary bytes, discarding SQLite status. | |
| std::string | column_text (sqlite3_stmt *stmt, int col) |
| Copy current-row text using NUL-terminated SQLite conversion. | |
| double | column_double (sqlite3_stmt *stmt, int col) |
| Read current-row SQLite numeric conversion as double. | |
| int | column_int (sqlite3_stmt *stmt, int col) |
| Read current-row SQLite numeric conversion as int. | |
| bool | column_is_null (sqlite3_stmt *stmt, int col) |
| Test the current-row SQLite column type for NULL. | |
| std::vector< uint8_t > | column_blob (sqlite3_stmt *stmt, int col) |
| Copy current-row blob bytes into owned storage. | |
| void | checked_model_step (sqlite3 *db, sqlite3_stmt *statement) |
| void | write_model_supplement (sqlite3 *db, const SimulationContext &ctx, const std::string &simulation) |
| bool | has_model_supplement (sqlite3 *db, const std::string &simulation) |
| void | read_model_supplement (sqlite3 *db, SimulationContext &ctx, const std::string &simulation) |
Variables | |
| constexpr uint8_t | WKB_LITTLE_ENDIAN = 1 |
| constexpr uint8_t | GP_MAGIC_1 = 0x47 |
| constexpr uint8_t | GP_MAGIC_2 = 0x50 |
| using openswmm::gpkg::DbPtr = std::unique_ptr<sqlite3, DbDeleter> |
| using openswmm::gpkg::StmtPtr = std::unique_ptr<sqlite3_stmt, StmtDeleter> |
|
strong |
Mode keyword for one [FILES] row — SAVE or USE.
NONE is the in-memory default for unconfigured slots so the writer can skip them. SAVE writes data out at simulation end; USE reads data in at simulation start.
|
strong |
Mode keyword for one [FILES] row — SAVE or USE.
NONE is the in-memory default for unconfigured slots so the writer can skip them. SAVE writes data out at simulation end; USE reads data in at simulation start.
|
strong |
|
strong |
| enum openswmm::gpkg::WkbType : uint32_t |
|
inline |
Bind copied binary bytes, discarding SQLite status.
SQLITE_TRANSIENT copies the block for statement ownership. Allocation/bind failure is not reported by this wrapper.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | One-based SQL parameter index; SQLite validates it, but this wrapper discards the return status. |
| [in] | data | Borrowed readable block of size bytes; nullptr requests SQL NULL. |
| [in] | size | Nonnegative byte count required for a non-null block; forwarded without validation. |
|
inline |
Bind a floating SQL parameter, discarding SQLite status.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | One-based SQL parameter index; SQLite validates it, but this wrapper discards the return status. |
| [in] | val | Numeric value forwarded without unit/range validation. |
|
inline |
Bind an int SQL parameter, discarding SQLite status.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | One-based SQL parameter index; SQLite validates it, but this wrapper discards the return status. |
| [in] | val | Integer value forwarded verbatim. |
|
inline |
Bind SQL NULL, discarding SQLite status.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | One-based SQL parameter index; SQLite validates it, but this wrapper discards the return status. |
|
inline |
Bind a copied SQL text parameter, discarding SQLite status.
Binding errors are not thrown or returned by this wrapper.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | One-based SQL parameter index; SQLite validates it, but this wrapper discards the return status. |
| [in] | val | Borrowed text bytes copied by SQLITE_TRANSIENT; length must fit int. Embedded NUL bytes are included in the bound byte count. |
|
inline |
|
inline |
Copy current-row blob bytes into owned storage.
Calls column_bytes then column_blob; conversion/SQLite errors are not separately reported, and vector allocation exceptions propagate.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | Zero-based result-column index valid for the current row; no wrapper bounds check. |
|
inline |
Read current-row SQLite numeric conversion as double.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | Zero-based result-column index valid for the current row; no wrapper bounds check. |
|
inline |
Read current-row SQLite numeric conversion as int.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | Zero-based result-column index valid for the current row; no wrapper bounds check. |
|
inline |
Test the current-row SQLite column type for NULL.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | Zero-based result-column index valid for the current row; no wrapper bounds check. |
|
inline |
Copy current-row text using NUL-terminated SQLite conversion.
SQLite numeric-to-text conversion may occur; this wrapper does not separately report conversion allocation errors.
| [in] | stmt | Non-null live prepared statement; caller serializes access and ensures required row/binding state. |
| [in] | col | Zero-based result-column index valid for the current row; no wrapper bounds check. |
| void openswmm::gpkg::create_schema | ( | sqlite3 * | db | ) |
Create all GeoPackage metadata tables and OpenSWMM application tables.
Creates (idempotently):
| db | Open SQLite database handle. |
| GpkgError | on failure. |
|
inline |
Decode LINESTRING coordinates from a prevalidated native-endian GP blob.
Reads native 32-bit/double values and ignores WKB byte-order markers; compatible little-endian encoding is required. No payload bounds/count-budget check is implemented; do not pass unvalidated truncated or excessive-count blobs.
| std::runtime_error | For checked GP-header or top-level WKB-type mismatch; allocations may also throw. |
| [in] | blob | Borrowed complete GP+WKB geometry. Caller verifies all advertised counts and byte ranges before entry; header length alone is insufficient. |
|
inline |
Decode MULTIPOLYGON coordinates from a prevalidated native-endian GP blob.
Reads native 32-bit/double values and ignores WKB byte-order markers; compatible little-endian encoding is required. All polygon rings are retained as concatenated, explicitly closed rings. Member counts are checked against the available payload. The top-level header still requires a prevalidated native-endian blob.
| std::runtime_error | For checked GP-header or top-level WKB-type mismatch; allocations may also throw. |
| [in] | blob | Borrowed complete GP+WKB geometry. Caller verifies all advertised counts and byte ranges before entry; header length alone is insufficient. |
|
inline |
Decode POINT coordinates from a prevalidated native-endian GP blob.
Reads native 32-bit/double values and ignores WKB byte-order markers; compatible little-endian encoding is required. No payload bounds/count-budget check is implemented; do not pass unvalidated truncated or excessive-count blobs.
| std::runtime_error | For checked GP-header or top-level WKB-type mismatch; allocations may also throw. |
| [in] | blob | Borrowed complete GP+WKB geometry. Caller verifies all advertised counts and byte ranges before entry; header length alone is insufficient. |
|
inline |
Encode an XY LINESTRING.
Little-endian native 32-bit/IEEE-double representation required. No coordinate finiteness, minimum point count, topology or ring orientation validation. Allocation failures propagate.
| [in] | xs | Borrowed X coordinates; count must fit the encoded uint32 length. |
| [in] | ys | Borrowed Y coordinates with at least xs.size() entries; extra entries are ignored. |
| [in] | srs_id | Copied spatial-reference identifier; coordinates remain in their input CRS units. |
|
inline |
Encode closed-ring spatial coordinates in MULTIPOLYGON form.
Little-endian native 32-bit/IEEE-double representation required. Appends the first point when last XY is not exactly equal to first. Closed rings delimit parts and holes; containment determines their nesting. No coordinate finiteness, minimum point count, topology or ring orientation validation. Allocation failures propagate.
| [in] | xs | Borrowed X coordinates; count must fit the encoded uint32 length including any automatically appended closure point. |
| [in] | ys | Borrowed Y coordinates with at least xs.size() entries; extra entries are ignored. |
| [in] | srs_id | Copied spatial-reference identifier; coordinates remain in their input CRS units. |
|
inline |
Encode an XY point with a matching XY envelope.
No CRS transform, unit conversion or geometry validity check.
| [in] | x | X coordinate in the selected CRS units; no finite validation. |
| [in] | y | Y coordinate in CRS units; no finite validation. |
| [in] | srs_id | Spatial-reference identifier copied into the GP header. |
|
inline |
Encode a single exterior ring in POLYGON form.
Little-endian native 32-bit/IEEE-double representation required. Appends the first point when last XY is not exactly equal to first; one polygon/ring only, no holes. No coordinate finiteness, minimum point count, topology or ring orientation validation. Allocation failures propagate.
| [in] | xs | Borrowed X coordinates; count must fit the encoded uint32 length including any automatically appended closure point. |
| [in] | ys | Borrowed Y coordinates with at least xs.size() entries; extra entries are ignored. |
| [in] | srs_id | Copied spatial-reference identifier; coordinates remain in their input CRS units. |
|
inline |
Execute SQL text and discard all returned rows.
No implicit transaction or rollback. Earlier statements can have succeeded when a later one fails.
| GpkgError | For any sqlite3_exec failure, including SQLite diagnostic and SQL source. |
| [in] | db | Non-null live SQLite connection borrowed for this call; caller serializes transaction/statement use. |
| [in] | sql | Borrowed NUL-terminated SQL string; may contain multiple statements and may mutate schema/data. |
|
inline |
|
inline |
Open an owned connection and configure GeoPackage connection defaults.
Enables foreign keys and sets a 5000 ms busy timeout after that pragma. No schema creation or transaction begins here. The timeout setup return status is ignored.
| GpkgError | For open failure or foreign-key pragma failure; partially opened connection is closed by RAII. |
| [in] | path | Borrowed SQLite filename token copied into sqlite3_open_v2; default flags allow creation. |
| [in] | flags | SQLite open flags, default READWRITE|CREATE; caller selects additional mutex/URI policy as needed. |
| void openswmm::gpkg::populate_default_variables | ( | sqlite3 * | db | ) |
Pre-populate the variables catalog with known SWMM output variables.
| db | Open database handle. |
|
inline |
Prepare the first SQL statement without stepping it.
Connection remains externally owned; parameter bindings/execution are separate.
| GpkgError | When sqlite3_prepare_v2 returns a failure code. |
| [in] | db | Non-null live SQLite connection borrowed for this call; caller serializes transaction/statement use. |
| [in] | sql | Borrowed SQL text; byte count must fit int. Remaining SQL tail is ignored because no tail pointer is requested. |
| void openswmm::gpkg::read_external_content | ( | sqlite3 * | db, |
| openswmm::SimulationContext & | ctx, | ||
| const std::string & | simulation_id, | ||
| const std::string & | scratch_dir ) |
Hydrate model external slots from embedded GeoPackage content and scratch files.
Hydrates time series, rain gages, climate, routing interfaces then hot starts. Writes per-role scratch files, stores resolved scratch paths and original <gpkg:...> sentinels; SAVE pending hot-start slots receive future paths. Caller owns scratch-directory lifetime/cleanup. Throws GpkgError on checked schema/materializer failures; earlier files/context bindings remain on later failure. Does not initialize the simulation or guarantee every legacy text writer detects late IO errors.
| [in,out] | db | Borrowed open connection with schema-compatible Part D content and model rows; no transaction is begun here. |
| [in,out] | ctx | Coherent parsed model whose matching external file slots and selected metadata are rebound incrementally. |
| [in] | simulation_id | Simulation key used to select only this model's embedded rows. |
| [in] | scratch_dir | UTF-8 materialization directory created as needed; empty makes the entire call a no-op. |
| int openswmm::gpkg::read_from_file | ( | const std::string & | path, |
| SimulationContext & | ctx, | ||
| const std::string & | simulation_id ) |
Convenience: open a GeoPackage file and read a model.
| path | Path to the .gpkg file. |
| ctx | Simulation context to populate. |
| simulation_id | Which model instance to load. |
| int openswmm::gpkg::read_model | ( | sqlite3 * | db, |
| SimulationContext & | ctx, | ||
| const std::string & | simulation_id, | ||
| const std::string & | scratch_dir = "" ) |
Read a model definition from a GeoPackage into a SimulationContext.
When scratch_dir is non-empty (Slice IO-8), the reader also walks the Part D content tables (raingage_data, climate_data, routing_interface_*, hotstart_*) and materialises one scratch file per role under scratch_dir. Each ctx external-file slot's FilePathPair.absolute is then bound to the matching scratch path so legacy fopen sites keep working. See ExternalContentReader.hpp for details.
| db | Open SQLite database handle. |
| ctx | Simulation context to populate. |
| simulation_id | Which model instance to load. |
| scratch_dir | Directory for materialised scratch files (sibling of the source .gpkg). Pass empty to skip Part D hydration. |
|
inline |
| void openswmm::gpkg::register_crs | ( | sqlite3 * | db, |
| int | srs_id, | ||
| const std::string & | org, | ||
| int | org_id, | ||
| const std::string & | srs_name, | ||
| const std::string & | wkt ) |
Register a CRS in gpkg_spatial_ref_sys (if not already present).
| db | Open database handle. |
| srs_id | Numeric SRS ID (e.g., 4326). |
| org | Organization name (e.g., "EPSG"). |
| org_id | Organization CRS ID (e.g., 4326). |
| srs_name | Human-readable name (e.g., "WGS 84"). |
| wkt | WKT definition string. |
| void openswmm::gpkg::register_feature_table | ( | sqlite3 * | db, |
| const std::string & | table_name, | ||
| const std::string & | geom_type, | ||
| int | srs_id, | ||
| const std::string & | identifier, | ||
| const std::string & | description, | ||
| double | min_x, | ||
| double | min_y, | ||
| double | max_x, | ||
| double | max_y ) |
Register a feature table in gpkg_contents and gpkg_geometry_columns.
| db | Open database handle. |
| table_name | Table name (e.g., "nodes"). |
| geom_type | Geometry type name (e.g., "POINT", "LINESTRING", "MULTIPOLYGON"). |
| srs_id | SRS ID from gpkg_spatial_ref_sys. |
| identifier | Human-readable identifier. |
| description | Table description. |
| min_x,min_y,max_x,max_y | Bounding box. |
| std::string openswmm::gpkg::scratchDirFor | ( | const std::string & | gpkg_path | ) |
Construct the portable sibling scratch-directory name for a GeoPackage path.
Pure lexical transformation: does not canonicalize, create or check the directory; allocation/path conversion may throw.
| [in] | gpkg_path | Borrowed UTF-8 source path, relative or absolute. |
| void openswmm::gpkg::write_external_content | ( | sqlite3 * | db, |
| const openswmm::SimulationContext & | ctx, | ||
| const std::string & | simulation_id ) |
Populate embedded external-input content tables from a model's file slots.
Reads time-series/rain/climate files, then routing interfaces and hot starts; source text units/layout are preserved through format adapters. Missing USE-direction files or hard parse failures throw GpkgError; SAVE hot starts may register pending state before a run. Writes incrementally without its own rollback, so caller wraps a transaction when atomic model replacement is required. Does not execute a model or materialize output scratch files; legacy adapters may accept empty/malformed rows or miss late IO errors.
| [in,out] | db | Borrowed writable schema-compatible SQLite connection; caller has already created model/pollutant catalogue rows and owns transaction boundaries. |
| [in] | ctx | Borrowed model with resolved file slots, or original tokens usable from current cwd when no absolute cache exists. |
| [in] | simulation_id | Owning simulation key used for embedded content foreign keys. |
| void openswmm::gpkg::write_model | ( | sqlite3 * | db, |
| const SimulationContext & | ctx, | ||
| const std::string & | simulation_id, | ||
| int | srs_id = 0 ) |
Write the full model definition from a SimulationContext into a GeoPackage.
Creates the schema if needed, registers the CRS, and writes all SWMM input sections as feature/attribute tables. The simulation_id groups all written data for this model instance.
| db | Open SQLite database handle (schema must exist or will be created). |
| ctx | Simulation context containing the parsed model. |
| simulation_id | Unique ID for this model instance. |
| srs_id | SRS ID to use for geometry encoding (default: 0 = undefined). |
|
inline |
| int openswmm::gpkg::write_to_file | ( | const std::string & | path, |
| const SimulationContext & | ctx, | ||
| const std::string & | simulation_id ) |
Convenience: create a new GeoPackage file, write schema + model.
| path | Output file path (created or overwritten). |
| ctx | Simulation context. |
| simulation_id | Unique ID for this model instance. |
|
constexpr |
|
constexpr |
|
constexpr |