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 {
56}
57
58namespace openswmm::input {
59
72 std::function<void(SimulationContext&, const std::vector<std::string>& /*lines*/
73 )>;
74
87public:
91 SectionRegistry() = default;
95 ~SectionRegistry() = default;
96
97 // -----------------------------------------------------------------------
98 // Registration
99 // -----------------------------------------------------------------------
100
112 void register_builtin(std::string_view tag, SectionHandler handler);
113
125 void register_custom(std::string_view tag, SectionHandler handler);
126
127 // -----------------------------------------------------------------------
128 // Query
129 // -----------------------------------------------------------------------
130
138 bool has(std::string_view tag) const;
139
147 bool is_custom(std::string_view tag) const;
148
149 // -----------------------------------------------------------------------
150 // Dispatch
151 // -----------------------------------------------------------------------
152
167 void dispatch(std::string_view tag, SimulationContext& ctx,
168 const std::vector<std::string>& lines) const;
169
170 // -----------------------------------------------------------------------
171 // Enumeration
172 // -----------------------------------------------------------------------
173
178 std::vector<std::string> registered_tags() const;
179
180private:
181 std::unordered_map<std::string, SectionHandler> builtin_;
182 std::unordered_map<std::string, SectionHandler> custom_;
183
191 std::string normalize_tag(std::string_view tag) const;
192};
193
194} /* namespace openswmm::input */
195
196#endif /* OPENSWMM_ENGINE_SECTION_REGISTRY_HPP */
~SectionRegistry()=default
Destroy owned handler function objects and any captures they own.
SectionRegistry()=default
Create empty built-in/custom handler maps.
void register_custom(std::string_view tag, SectionHandler handler)
Store or replace a callback that takes precedence over a built-in.
Definition SectionRegistry.cpp:50
bool is_custom(std::string_view tag) const
Test whether the normalized custom map contains a tag.
Definition SectionRegistry.cpp:63
std::vector< std::string > registered_tags() const
Copy the union of normalized built-in/custom tags.
Definition SectionRegistry.cpp:97
void dispatch(std::string_view tag, SimulationContext &ctx, const std::vector< std::string > &lines) const
Invoke a custom callback first, otherwise a built-in, otherwise no-op.
Definition SectionRegistry.cpp:71
bool has(std::string_view tag) const
Test whether either normalized handler map contains a tag.
Definition SectionRegistry.cpp:58
void register_builtin(std::string_view tag, SectionHandler handler)
Store or replace one built-in section callback.
Definition SectionRegistry.cpp:46
Definition CatchmentHandler.cpp:70
std::function< void(SimulationContext &, const std::vector< std::string > &)> SectionHandler
Handler function type for input file sections.
Definition SectionRegistry.hpp:71
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390