OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
DefaultReportPlugin.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
34
35#ifndef OPENSWMM_ENGINE_DEFAULT_REPORT_PLUGIN_HPP
36#define OPENSWMM_ENGINE_DEFAULT_REPORT_PLUGIN_HPP
37
39
40#include <ctime>
41#include <string>
42
43namespace openswmm {
44
49class DefaultReportPlugin final : public IReportPlugin {
50public:
54 explicit DefaultReportPlugin(std::string rpt_path);
58 ~DefaultReportPlugin() override;
59
63 PluginState state() const noexcept override { return state_; }
64
69 int initialize(const std::vector<std::string>& init_args,
70 const IPluginComponentInfo* info) override;
71
75 int validate(const SimulationContext& ctx) override;
84 int prepare(const SimulationContext& ctx) override;
88 int update(const SimulationSnapshot& snapshot) override;
94 int finalize(const SimulationContext& ctx) override;
95
105 int write_summary(const SimulationContext& ctx) override;
106 // Managed sessions create a new report and never truncate a late collision.
109 void requireFreshOutput() noexcept { checkpoint_fresh_ = true; }
110
114 const char* last_error_message() const noexcept override { return last_error_.c_str(); }
115
116private:
117 std::string rpt_path_;
119 std::string last_error_;
120 bool checkpoint_fresh_ = false;
121
122 // Progressive write state
123 std::FILE* file_ = nullptr;
124 std::size_t warnings_written_ = 0;
125 std::size_t errors_written_ = 0;
126
132 void write_preamble(std::FILE* f, const SimulationContext& ctx);
133
140 void write_results(std::FILE* f, const SimulationContext& ctx);
141
148 void write_timing(std::FILE* f, const SimulationContext& ctx);
149};
150
151} /* namespace openswmm */
152
153#endif /* OPENSWMM_ENGINE_DEFAULT_REPORT_PLUGIN_HPP */
Interface for report-writing plugins.
void requireFreshOutput() noexcept
Require exclusive file creation for managed-session report paths. Sets a retained flag only; existing...
Definition DefaultReportPlugin.hpp:109
PluginState state() const noexcept override
Read the last assigned lifecycle marker without synchronization.
Definition DefaultReportPlugin.hpp:63
int write_summary(const SimulationContext &ctx) override
Write result/snow/timing sections and close the report stream.
Definition DefaultReportPlugin.cpp:315
int prepare(const SimulationContext &ctx) override
Open a progressive report, write its preamble and mark PREPARED.
Definition DefaultReportPlugin.cpp:238
int update(const SimulationSnapshot &snapshot) override
Mark UPDATING without writing per-step report content.
Definition DefaultReportPlugin.cpp:259
int validate(const SimulationContext &ctx) override
Mark VALIDATED without checking path or model data.
Definition DefaultReportPlugin.cpp:233
int finalize(const SimulationContext &ctx) override
Append outstanding errors/warnings, flush and mark FINALIZED.
Definition DefaultReportPlugin.cpp:293
DefaultReportPlugin(std::string rpt_path)
Store a report destination and start in LOADED state.
Definition DefaultReportPlugin.cpp:215
int initialize(const std::vector< std::string > &init_args, const IPluginComponentInfo *info) override
Mark INITIALIZED without opening the report.
Definition DefaultReportPlugin.cpp:227
~DefaultReportPlugin() override
Write an interruption marker, flush and close a report still open at destruction. No summary is gener...
Definition DefaultReportPlugin.cpp:218
const char * last_error_message() const noexcept override
Borrow the stored diagnostic text without clearing it.
Definition DefaultReportPlugin.hpp:114
Describes a plugin component: metadata, capabilities, and factory methods.
Definition IPluginComponentInfo.hpp:201
Interface for report-writing plugins.
Definition IReportPlugin.hpp:63
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:86
@ UNLOADED
Library not yet loaded (or was closed).
Definition PluginState.hpp:87
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:123