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:
51 explicit DefaultReportPlugin(std::string rpt_path);
52 ~DefaultReportPlugin() override;
53
54 PluginState state() const noexcept override { return state_; }
55
56 int initialize(const std::vector<std::string>& init_args,
57 const IPluginComponentInfo* info) override;
58
59 int validate (const SimulationContext& ctx) override;
60 int prepare (const SimulationContext& ctx) override;
61 int update (const SimulationSnapshot& snapshot) override;
62 int finalize (const SimulationContext& ctx) override;
63
65 int write_summary(const SimulationContext& ctx) override;
66
67 const char* last_error_message() const noexcept override {
68 return last_error_.c_str();
69 }
70
71private:
72 std::string rpt_path_;
74 std::string last_error_;
75
76 // Progressive write state
77 std::FILE* file_ = nullptr;
78 std::size_t warnings_written_ = 0;
79 std::size_t errors_written_ = 0;
80
82 void write_preamble(std::FILE* f, const SimulationContext& ctx);
83
85 void write_results(std::FILE* f, const SimulationContext& ctx);
86
88 void write_timing(std::FILE* f, const SimulationContext& ctx);
89};
90
91} /* namespace openswmm */
92
93#endif /* OPENSWMM_ENGINE_DEFAULT_REPORT_PLUGIN_HPP */
Interface for report-writing plugins.
PluginState state() const noexcept override
Query the current plugin state.
Definition DefaultReportPlugin.hpp:54
int write_summary(const SimulationContext &ctx) override
Write the summary statistics table to the .rpt file.
Definition DefaultReportPlugin.cpp:221
int prepare(const SimulationContext &ctx) override
Open report file(s) and write any headers.
Definition DefaultReportPlugin.cpp:177
int update(const SimulationSnapshot &snapshot) override
Accumulate data from one output step. Called from IO thread.
Definition DefaultReportPlugin.cpp:193
int validate(const SimulationContext &ctx) override
Validate configuration against the loaded model.
Definition DefaultReportPlugin.cpp:172
int finalize(const SimulationContext &ctx) override
Flush and close report file(s).
Definition DefaultReportPlugin.cpp:198
DefaultReportPlugin(std::string rpt_path)
Definition DefaultReportPlugin.cpp:152
int initialize(const std::vector< std::string > &init_args, const IPluginComponentInfo *info) override
Definition DefaultReportPlugin.cpp:166
~DefaultReportPlugin() override
Definition DefaultReportPlugin.cpp:157
const char * last_error_message() const noexcept override
Get the last error message.
Definition DefaultReportPlugin.hpp:67
Describes a plugin component: metadata, capabilities, and factory methods.
Definition IPluginComponentInfo.hpp:195
Interface for report-writing plugins.
Definition IReportPlugin.hpp:61
PluginState
Plugin lifecycle states.
Definition PluginState.hpp:83
@ UNLOADED
Library not yet loaded (or was closed).
Definition PluginState.hpp:84
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Complete simulation state snapshot at one output time step.
Definition SimulationSnapshot.hpp:117