OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
GeoPackageOutputPlugin.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
26
27#ifndef OPENSWMM_GEOPACKAGE_OUTPUT_PLUGIN_HPP
28#define OPENSWMM_GEOPACKAGE_OUTPUT_PLUGIN_HPP
29
30#include "GpkgUtils.hpp"
32#include <string>
33#include <unordered_map>
34#include <vector>
35
36namespace openswmm::gpkg {
37
39public:
41
42 PluginState state() const noexcept override { return state_; }
43
44 int initialize(const std::vector<std::string>& init_args,
45 const IPluginComponentInfo* info) override;
46
47 int validate(const SimulationContext& ctx) override;
48 int prepare(const SimulationContext& ctx) override;
49 int update(const SimulationSnapshot& snapshot) override;
50 int finalize(const SimulationContext& ctx) override;
51
52 const char* last_error_message() const noexcept override {
53 return error_msg_.c_str();
54 }
55
56private:
58 std::string error_msg_;
59 std::string db_path_;
60 std::string simulation_id_;
61 DbPtr db_;
62 StmtPtr insert_stmt_;
63
64 // Cached variable IDs
65 std::unordered_map<std::string, int> variable_ids_;
66
67 // Batch buffer
68 struct ResultRow {
69 std::string object_type;
70 std::string object_id;
71 int variable_id;
72 double elapsed_time;
73 double value;
74 };
75 std::vector<ResultRow> buffer_;
76 static constexpr size_t FLUSH_THRESHOLD = 5000;
77
78 void flush_buffer();
79 int lookup_variable(const std::string& name, const std::string& obj_type);
80
91 int register_species_variables(const SimulationContext& ctx);
92
93 // Per-timestep results arrive pre-converted to display units (engine
94 // boundary), so no plugin-side unit-conversion factors are required.
95
96 // Per-object report flags, captured during prepare() from SimulationContext
97 std::vector<char> subcatch_rpt_flag_;
98 std::vector<char> node_rpt_flag_;
99 std::vector<char> link_rpt_flag_;
100};
101
102} // namespace openswmm::gpkg
103
104#endif // OPENSWMM_GEOPACKAGE_OUTPUT_PLUGIN_HPP
RAII wrappers and utilities for SQLite operations in GeoPackage I/O.
Interface for output-writing plugins.
Interface for output-writing plugins.
Definition IOutputPlugin.hpp:73
Describes a plugin component: metadata, capabilities, and factory methods.
Definition IPluginComponentInfo.hpp:195
int update(const SimulationSnapshot &snapshot) override
Write one output snapshot. Called from the IO thread.
Definition GeoPackageOutputPlugin.cpp:200
int initialize(const std::vector< std::string > &init_args, const IPluginComponentInfo *info) override
Definition GeoPackageOutputPlugin.cpp:117
int prepare(const SimulationContext &ctx) override
Open output file(s) and write headers.
Definition GeoPackageOutputPlugin.cpp:134
int validate(const SimulationContext &ctx) override
Validate plugin configuration against the simulation model.
Definition GeoPackageOutputPlugin.cpp:129
int finalize(const SimulationContext &ctx) override
Flush and close output file(s). Called from main thread.
Definition GeoPackageOutputPlugin.cpp:470
PluginState state() const noexcept override
Query the current plugin state.
Definition GeoPackageOutputPlugin.hpp:42
const char * last_error_message() const noexcept override
Get the last error message from this plugin instance.
Definition GeoPackageOutputPlugin.hpp:52
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:83
@ UNLOADED
Library not yet loaded (or was closed).
Definition PluginState.hpp:84
Definition ExternalContentReader.cpp:49
std::unique_ptr< sqlite3_stmt, StmtDeleter > StmtPtr
Definition GpkgUtils.hpp:103
std::unique_ptr< sqlite3, DbDeleter > DbPtr
Definition GpkgUtils.hpp:58
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:117
Central, reentrant simulation context.
Definition SimulationContext.hpp:353