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
73 const std::vector<std::string>* find(const std::string& upper_tag) const {
74 for (const auto& s : sections)
75 if (s.first == upper_tag)
76 return &s.second;
77 return nullptr;
78 }
79};
80
90std::string read_component_config(const std::string& path, const std::string& base_dir,
91 ComponentConfigSections& out);
92
102std::string parse_component_config_text(const std::string& text, const std::string& label,
103 ComponentConfigSections& out);
104
108 std::function<void(SimulationContext& ctx, const ProcessComponentSpec& spec,
109 const ComponentConfigSections& config, std::vector<std::string>& errors)>;
110
135 std::function<std::string(const SimulationContext& ctx, const ProcessComponentSpec& spec)>;
136
146
155class ProcessComponentRegistry {
156public:
160 static ProcessComponentRegistry& instance();
161
171 void register_component(const std::string& id, std::string description,
172 ComponentConfigApply apply, ComponentConfigSave save = nullptr);
173
178 const ProcessComponentEntry* find(const std::string& id) const;
181 std::vector<std::string> known_ids() const;
182
183private:
186 ProcessComponentRegistry();
187 std::map<std::string, ProcessComponentEntry> entries_;
188};
189
200std::vector<std::string> resolve_process_components(SimulationContext& ctx,
201 const std::string& base_dir);
202
203} // namespace openswmm::components
204
205#endif // OPENSWMM_ENGINE_PLUGINS_PROCESS_COMPONENT_REGISTRY_HPP
void register_component(const std::string &id, std::string description, ComponentConfigApply apply, ComponentConfigSave save=nullptr)
Insert or replace a complete component-hook entry and clear its pending phase.
Definition ProcessComponentRegistry.cpp:185
std::vector< std::string > known_ids() const
Copy every registered key, including planned entries without apply hooks.
Definition ProcessComponentRegistry.cpp:197
static ProcessComponentRegistry & instance()
Access the process-global lazily constructed builtin hook registry.
Definition ProcessComponentRegistry.cpp:180
const ProcessComponentEntry * find(const std::string &id) const
Borrow one exact component registry entry.
Definition ProcessComponentRegistry.cpp:192
Definition ProcessComponentRegistry.cpp:37
std::string read_component_config(const std::string &path, const std::string &base_dir, ComponentConfigSections &out)
Clear sections, resolve a UTF-8 config path and parse the component dialect.
Definition ProcessComponentRegistry.cpp:129
std::string parse_component_config_text(const std::string &text, const std::string &label, ComponentConfigSections &out)
Parse component configuration text using the same section/comment rules as files.
Definition ProcessComponentRegistry.cpp:121
std::vector< std::string > resolve_process_components(SimulationContext &ctx, const std::string &base_dir)
Validate specs, parse each config and apply implemented builtin hooks in order.
Definition ProcessComponentRegistry.cpp:209
std::function< void(SimulationContext &ctx, const ProcessComponentSpec &spec, const ComponentConfigSections &config, std::vector< std::string > &errors)> ComponentConfigApply
Definition ProcessComponentRegistry.hpp:107
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:134
Definition ExchangeLaw.hpp:60
One row of [PROCESS_COMPONENTS] (Unified Transport suite, D-UT8).
Definition SimulationContext.hpp:158
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition ProcessComponentRegistry.hpp:65
const std::vector< std::string > * find(const std::string &upper_tag) const
Borrow the first exact section-tag match.
Definition ProcessComponentRegistry.hpp:73
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:137
ComponentConfigApply apply
Definition ProcessComponentRegistry.hpp:140
std::string description
short human-readable description
Definition ProcessComponentRegistry.hpp:138
std::string pending_phase
non-empty ⇒ planned, not yet implemented
Definition ProcessComponentRegistry.hpp:139
ComponentConfigSave save
Definition ProcessComponentRegistry.hpp:144