OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
TypeHelpers.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
33
34#ifndef OPENSWMM_ENGINE_TYPE_HELPERS_HPP
35#define OPENSWMM_ENGINE_TYPE_HELPERS_HPP
36
37#include "../data/NodeData.hpp"
38#include "../data/LinkData.hpp"
41
42namespace openswmm {
43
44// ============================================================================
45// Node type mapping
46// ============================================================================
47
58inline bool c_to_internal_node_type(int c_type, NodeType& out_type) noexcept {
59 switch (c_type) {
61 out_type = NodeType::JUNCTION;
62 return true;
64 out_type = NodeType::OUTFALL;
65 return true;
67 out_type = NodeType::STORAGE;
68 return true;
70 out_type = NodeType::DIVIDER;
71 return true;
72 default:
73 return false;
74 }
75}
76
83inline int internal_to_c_node_type(NodeType type) noexcept {
84 switch (type) {
86 return SWMM_NODE_JUNCTION;
88 return SWMM_NODE_OUTFALL;
90 return SWMM_NODE_DIVIDER;
92 return SWMM_NODE_STORAGE;
93 default:
94 return SWMM_NODE_JUNCTION;
95 }
96}
97
98// ============================================================================
99// Link type mapping (C API and internal values match, but wrap for symmetry)
100// ============================================================================
101
112inline bool c_to_internal_link_type(int c_type, LinkType& out_type) noexcept {
113 switch (c_type) {
115 out_type = LinkType::CONDUIT;
116 return true;
117 case SWMM_LINK_PUMP:
118 out_type = LinkType::PUMP;
119 return true;
121 out_type = LinkType::ORIFICE;
122 return true;
123 case SWMM_LINK_WEIR:
124 out_type = LinkType::WEIR;
125 return true;
126 case SWMM_LINK_OUTLET:
127 out_type = LinkType::OUTLET;
128 return true;
129 default:
130 return false;
131 }
132}
133
140inline int internal_to_c_link_type(LinkType type) noexcept {
141 switch (type) {
143 return SWMM_LINK_CONDUIT;
144 case LinkType::PUMP:
145 return SWMM_LINK_PUMP;
147 return SWMM_LINK_ORIFICE;
148 case LinkType::WEIR:
149 return SWMM_LINK_WEIR;
150 case LinkType::OUTLET:
151 return SWMM_LINK_OUTLET;
152 default:
153 return SWMM_LINK_CONDUIT;
154 }
155}
156
157} // namespace openswmm
158
159#endif /* OPENSWMM_ENGINE_TYPE_HELPERS_HPP */
Structure-of-Arrays (SoA) storage for all node types.
Definition ExchangeLaw.hpp:60
int internal_to_c_link_type(LinkType type) noexcept
Translate an internal link type into its public C enum.
Definition TypeHelpers.hpp:140
LinkType
Link type codes.
Definition LinkData.hpp:58
@ CONDUIT
Definition LinkData.hpp:58
@ PUMP
Definition LinkData.hpp:58
@ WEIR
Definition LinkData.hpp:58
@ ORIFICE
Definition LinkData.hpp:58
@ OUTLET
Definition LinkData.hpp:58
NodeType
Node type codes.
Definition NodeData.hpp:65
@ JUNCTION
Definition NodeData.hpp:65
@ DIVIDER
Definition NodeData.hpp:65
@ STORAGE
Definition NodeData.hpp:65
@ OUTFALL
Definition NodeData.hpp:65
bool c_to_internal_node_type(int c_type, NodeType &out_type) noexcept
Translate a public C node type into its internal enum.
Definition TypeHelpers.hpp:58
int internal_to_c_node_type(NodeType type) noexcept
Translate an internal node type into its public C enum.
Definition TypeHelpers.hpp:83
bool c_to_internal_link_type(int c_type, LinkType &out_type) noexcept
Translate a public C link type into its internal enum.
Definition TypeHelpers.hpp:112
OpenSWMM Engine — Node C API.
@ SWMM_NODE_JUNCTION
Definition openswmm_nodes.h:49
@ SWMM_NODE_OUTFALL
Definition openswmm_nodes.h:50
@ SWMM_NODE_DIVIDER
Definition openswmm_nodes.h:52
@ SWMM_NODE_STORAGE
Definition openswmm_nodes.h:51