OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
SectionRegistry.hpp
Go to the documentation of this file.
1
29#ifndef OPENSWMM_ENGINE_SECTION_REGISTRY_HPP
30#define OPENSWMM_ENGINE_SECTION_REGISTRY_HPP
31
32#include <string>
33#include <string_view>
34#include <vector>
35#include <functional>
36#include <unordered_map>
37
38namespace openswmm {
39 struct SimulationContext;
40}
41
42namespace openswmm::input {
43
55using SectionHandler = std::function<void(
57 const std::vector<std::string>& /*lines*/
58)>;
59
72public:
73 SectionRegistry() = default;
74 ~SectionRegistry() = default;
75
76 // -----------------------------------------------------------------------
77 // Registration
78 // -----------------------------------------------------------------------
79
87 void register_builtin(std::string_view tag, SectionHandler handler);
88
110 void register_custom(std::string_view tag, SectionHandler handler);
111
112 // -----------------------------------------------------------------------
113 // Query
114 // -----------------------------------------------------------------------
115
121 bool has(std::string_view tag) const;
122
128 bool is_custom(std::string_view tag) const;
129
130 // -----------------------------------------------------------------------
131 // Dispatch
132 // -----------------------------------------------------------------------
133
144 void dispatch(
145 std::string_view tag,
147 const std::vector<std::string>& lines
148 ) const;
149
150 // -----------------------------------------------------------------------
151 // Enumeration
152 // -----------------------------------------------------------------------
153
157 std::vector<std::string> registered_tags() const;
158
159private:
160 std::unordered_map<std::string, SectionHandler> builtin_;
161 std::unordered_map<std::string, SectionHandler> custom_;
162
163 std::string normalize_tag(std::string_view tag) const;
164};
165
166} /* namespace openswmm::input */
167
168#endif /* OPENSWMM_ENGINE_SECTION_REGISTRY_HPP */
Registry that maps section tags (e.g., "[JUNCTIONS]") to handlers.
Definition SectionRegistry.hpp:71
void register_custom(std::string_view tag, SectionHandler handler)
Register a custom (user-defined) section handler. (R09)
Definition SectionRegistry.cpp:34
bool is_custom(std::string_view tag) const
Check if a section tag is a custom (non-builtin) handler.
Definition SectionRegistry.cpp:47
std::vector< std::string > registered_tags() const
List all registered section tags (built-in + custom).
Definition SectionRegistry.cpp:84
void dispatch(std::string_view tag, SimulationContext &ctx, const std::vector< std::string > &lines) const
Dispatch a section to its handler.
Definition SectionRegistry.cpp:55
bool has(std::string_view tag) const
Check if a section tag has a registered handler.
Definition SectionRegistry.cpp:42
void register_builtin(std::string_view tag, SectionHandler handler)
Register a built-in section handler.
Definition SectionRegistry.cpp:30
Definition CatchmentHandler.cpp:44
std::function< void(SimulationContext &, const std::vector< std::string > &)> SectionHandler
Handler function type for input file sections.
Definition SectionRegistry.hpp:58
Definition Controls.cpp:24
Central, reentrant simulation context.
Definition SimulationContext.hpp:141