OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
openswmm::DefaultStateIOPlugin Class Reference

Default state-IO plugin: OpenSWMM binary + legacy SWMM5 hot-start. More...

#include <DefaultStateIOPlugin.hpp>

Inheritance diagram for openswmm::DefaultStateIOPlugin:
Collaboration diagram for openswmm::DefaultStateIOPlugin:

Public Member Functions

 DefaultStateIOPlugin ()=default
 
PluginState state () const noexcept override
 Query the current plugin state.
 
int initialize (const std::vector< std::string > &init_args, const IPluginComponentInfo *info) override
 Initialize from [PLUGINS] arguments.
 
int validate (const SimulationContext &ctx) override
 Validate configuration against the loaded model.
 
bool can_read (const std::string &path) const override
 Cheap format sniff used to dispatch a path to the right plugin.
 
int read_state (const std::string &path, SimulationContext &ctx) override
 Read state from a file and apply it to the simulation context.
 
int write_state (const std::string &path, const SimulationContext &ctx) override
 Write the current simulation state to a file.
 
std::vector< std::string > warnings () const override
 Non-fatal warnings accumulated during the last call.
 
int finalize (const SimulationContext &ctx) override
 Finalize and release resources.
 
const char * last_error_message () const noexcept override
 Get the last error message.
 
- Public Member Functions inherited from openswmm::IStateIOPlugin
virtual ~IStateIOPlugin ()=default
 

Detailed Description

Default state-IO plugin: OpenSWMM binary + legacy SWMM5 hot-start.

Constructor & Destructor Documentation

◆ DefaultStateIOPlugin()

openswmm::DefaultStateIOPlugin::DefaultStateIOPlugin ( )
default

Member Function Documentation

◆ can_read()

bool openswmm::DefaultStateIOPlugin::can_read ( const std::string &  path) const
overridevirtual

Cheap format sniff used to dispatch a path to the right plugin.

Implementations should peek at file extension and/or a small fixed-size header (magic number) and return true if this plugin can read the file. Must NOT perform a full parse — the engine calls this on every registered state plugin in registration order to pick the first match.

Parameters
pathPath to a candidate state file.
Returns
true if this plugin recognizes the file format.

Reimplemented from openswmm::IStateIOPlugin.

◆ finalize()

int openswmm::DefaultStateIOPlugin::finalize ( const SimulationContext ctx)
overridevirtual

Finalize and release resources.

Parameters
ctxSimulation context.
Returns
0 on success.
Postcondition
state() == PluginState::FINALIZED on success.

Implements openswmm::IStateIOPlugin.

◆ initialize()

int openswmm::DefaultStateIOPlugin::initialize ( const std::vector< std::string > &  init_args,
const IPluginComponentInfo info 
)
overridevirtual

Initialize from [PLUGINS] arguments.

Parameters
init_argsTokenized arguments from the [PLUGINS] line.
infoBack-pointer to IPluginComponentInfo.
Returns
0 on success.
Postcondition
state() == PluginState::INITIALIZED on success.

Implements openswmm::IStateIOPlugin.

◆ last_error_message()

const char * openswmm::DefaultStateIOPlugin::last_error_message ( ) const
inlineoverridevirtualnoexcept

Get the last error message.

Reimplemented from openswmm::IStateIOPlugin.

◆ read_state()

int openswmm::DefaultStateIOPlugin::read_state ( const std::string &  path,
SimulationContext ctx 
)
overridevirtual

Read state from a file and apply it to the simulation context.

Called BEFORE simulation start (engine in INITIALIZED state). Restores node depths/heads/volumes, link flows/depths/volumes, subcatchment runoff, and any solver-internal state (infiltration, groundwater, snowpack) exposed via SimulationContext accessors.

Missing objects (present in the file but not in the model, or vice versa) are reported via warnings() and do NOT cause a non-zero return — the caller decides how strict to be.

Parameters
pathPath to the state file.
ctxSimulation context to populate.
Returns
0 on success, non-zero error code on failure.

Implements openswmm::IStateIOPlugin.

Here is the call graph for this function:

◆ state()

PluginState openswmm::DefaultStateIOPlugin::state ( ) const
inlineoverridevirtualnoexcept

Query the current plugin state.

Implements openswmm::IStateIOPlugin.

◆ validate()

int openswmm::DefaultStateIOPlugin::validate ( const SimulationContext ctx)
overridevirtual

Validate configuration against the loaded model.

Parameters
ctxSimulation context (after input parsing).
Returns
0 on success.
Postcondition
state() == PluginState::VALIDATED on success.

Implements openswmm::IStateIOPlugin.

◆ warnings()

std::vector< std::string > openswmm::DefaultStateIOPlugin::warnings ( ) const
inlineoverridevirtual

Non-fatal warnings accumulated during the last call.

Typical contents: "node 'J3' present in hot-start file but not in model — skipped". Cleared at the start of each read_state()/write_state() call.

Returns
Vector of warning messages (empty by default).

Reimplemented from openswmm::IStateIOPlugin.

◆ write_state()

int openswmm::DefaultStateIOPlugin::write_state ( const std::string &  path,
const SimulationContext ctx 
)
overridevirtual

Write the current simulation state to a file.

Safe to call repeatedly during a run for scheduled checkpoints and once at the end for the final snapshot. Implementations should NOT hold the file open between calls — each call opens, writes, fsyncs, and closes.

Parameters
pathDestination path.
ctxSimulation context to serialize.
Returns
0 on success, non-zero error code on failure.

Implements openswmm::IStateIOPlugin.

Here is the call graph for this function:

The documentation for this class was generated from the following files: