OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
ProcessComponentRegistry.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
46
47#ifndef OPENSWMM_ENGINE_PLUGINS_PROCESS_COMPONENT_REGISTRY_HPP
48#define OPENSWMM_ENGINE_PLUGINS_PROCESS_COMPONENT_REGISTRY_HPP
49
50#include <functional>
51#include <map>
52#include <string>
53#include <vector>
54
55namespace openswmm {
58}
59
60namespace openswmm::components {
61
66 std::string source_path;
67 std::vector<std::pair<std::string, std::vector<std::string>>> sections;
68
70 const std::vector<std::string>* find(const std::string& upper_tag) const {
71 for (const auto& s : sections)
72 if (s.first == upper_tag) return &s.second;
73 return nullptr;
74 }
75};
76
87std::string read_component_config(const std::string& path,
88 const std::string& base_dir,
89 ComponentConfigSections& out);
90
94std::string parse_component_config_text(const std::string& text,
95 const std::string& label,
96 ComponentConfigSections& out);
97
101 std::function<void(SimulationContext& ctx,
102 const ProcessComponentSpec& spec,
103 const ComponentConfigSections& config,
104 std::vector<std::string>& errors)>;
105
130 std::function<std::string(const SimulationContext& ctx,
131 const ProcessComponentSpec& spec)>;
132
142
151class ProcessComponentRegistry {
152public:
153 static ProcessComponentRegistry& instance();
154
159 void register_component(const std::string& id, std::string description,
161 ComponentConfigSave save = nullptr);
162
163 const ProcessComponentEntry* find(const std::string& id) const;
164 std::vector<std::string> known_ids() const;
165
166private:
167 ProcessComponentRegistry();
168 std::map<std::string, ProcessComponentEntry> entries_;
169};
170
180std::vector<std::string> resolve_process_components(SimulationContext& ctx,
181 const std::string& base_dir);
182
183} // namespace openswmm::components
184
185#endif // OPENSWMM_ENGINE_PLUGINS_PROCESS_COMPONENT_REGISTRY_HPP
void register_component(const std::string &id, std::string description, ComponentConfigApply apply, ComponentConfigSave save=nullptr)
Definition ProcessComponentRegistry.cpp:168
std::vector< std::string > known_ids() const
Definition ProcessComponentRegistry.cpp:183
static ProcessComponentRegistry & instance()
Definition ProcessComponentRegistry.cpp:163
const ProcessComponentEntry * find(const std::string &id) const
Definition ProcessComponentRegistry.cpp:177
Definition ProcessComponentRegistry.cpp:36
std::string read_component_config(const std::string &path, const std::string &base_dir, ComponentConfigSections &out)
Parse a component configuration file (phase IO2).
Definition ProcessComponentRegistry.cpp:118
std::function< void(SimulationContext &ctx, const ProcessComponentSpec &spec, const ComponentConfigSections &config, std::vector< std::string > &errors)> ComponentConfigApply
Definition ProcessComponentRegistry.hpp:100
std::string parse_component_config_text(const std::string &text, const std::string &label, ComponentConfigSections &out)
Definition ProcessComponentRegistry.cpp:109
std::vector< std::string > resolve_process_components(SimulationContext &ctx, const std::string &base_dir)
Resolve every [PROCESS_COMPONENTS] spec (phase IO1): look up the id, read its config file,...
Definition ProcessComponentRegistry.cpp:194
std::function< std::string(const SimulationContext &ctx, const ProcessComponentSpec &spec)> ComponentConfigSave
Save hook (IO3a): render this component's CURRENT engine state back to config-file text — the inverse...
Definition ProcessComponentRegistry.hpp:129
Definition NodeCoupling.cpp:16
One row of [PROCESS_COMPONENTS] (Unified Transport suite, D-UT8).
Definition SimulationContext.hpp:154
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition ProcessComponentRegistry.hpp:65
const std::vector< std::string > * find(const std::string &upper_tag) const
First section with this tag, or nullptr.
Definition ProcessComponentRegistry.hpp:70
std::vector< std::pair< std::string, std::vector< std::string > > > sections
Definition ProcessComponentRegistry.hpp:67
std::string source_path
resolved absolute/effective path
Definition ProcessComponentRegistry.hpp:66
Definition ProcessComponentRegistry.hpp:133
ComponentConfigApply apply
Definition ProcessComponentRegistry.hpp:136
std::string description
short human-readable description
Definition ProcessComponentRegistry.hpp:134
std::string pending_phase
non-empty ⇒ planned, not yet implemented
Definition ProcessComponentRegistry.hpp:135
ComponentConfigSave save
Definition ProcessComponentRegistry.hpp:140