OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SectionRegistry.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
44
45#ifndef OPENSWMM_ENGINE_SECTION_REGISTRY_HPP
46#define OPENSWMM_ENGINE_SECTION_REGISTRY_HPP
47
48#include <string>
49#include <string_view>
50#include <vector>
51#include <functional>
52#include <unordered_map>
53
54namespace openswmm {
55 struct SimulationContext;
56}
57
58namespace openswmm::input {
59
71using SectionHandler = std::function<void(
73 const std::vector<std::string>& /*lines*/
74)>;
75
88public:
89 SectionRegistry() = default;
90 ~SectionRegistry() = default;
91
92 // -----------------------------------------------------------------------
93 // Registration
94 // -----------------------------------------------------------------------
95
103 void register_builtin(std::string_view tag, SectionHandler handler);
104
126 void register_custom(std::string_view tag, SectionHandler handler);
127
128 // -----------------------------------------------------------------------
129 // Query
130 // -----------------------------------------------------------------------
131
137 bool has(std::string_view tag) const;
138
144 bool is_custom(std::string_view tag) const;
145
146 // -----------------------------------------------------------------------
147 // Dispatch
148 // -----------------------------------------------------------------------
149
160 void dispatch(
161 std::string_view tag,
163 const std::vector<std::string>& lines
164 ) const;
165
166 // -----------------------------------------------------------------------
167 // Enumeration
168 // -----------------------------------------------------------------------
169
173 std::vector<std::string> registered_tags() const;
174
175private:
176 std::unordered_map<std::string, SectionHandler> builtin_;
177 std::unordered_map<std::string, SectionHandler> custom_;
178
179 std::string normalize_tag(std::string_view tag) const;
180};
181
182} /* namespace openswmm::input */
183
184#endif /* OPENSWMM_ENGINE_SECTION_REGISTRY_HPP */
void register_custom(std::string_view tag, SectionHandler handler)
Register a custom (user-defined) section handler. (R09)
Definition SectionRegistry.cpp:50
bool is_custom(std::string_view tag) const
Check if a section tag is a custom (non-builtin) handler.
Definition SectionRegistry.cpp:63
std::vector< std::string > registered_tags() const
List all registered section tags (built-in + custom).
Definition SectionRegistry.cpp:100
void dispatch(std::string_view tag, SimulationContext &ctx, const std::vector< std::string > &lines) const
Dispatch a section to its handler.
Definition SectionRegistry.cpp:71
bool has(std::string_view tag) const
Check if a section tag has a registered handler.
Definition SectionRegistry.cpp:58
void register_builtin(std::string_view tag, SectionHandler handler)
Register a built-in section handler.
Definition SectionRegistry.cpp:46
Definition CatchmentHandler.cpp:69
std::function< void( SimulationContext &, const std::vector< std::string > &)> SectionHandler
Handler function type for input file sections.
Definition SectionRegistry.hpp:71
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353