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
48inline bool c_to_internal_node_type(int c_type, NodeType& out_type) noexcept {
49 switch (c_type) {
50 case SWMM_NODE_JUNCTION: out_type = NodeType::JUNCTION; return true;
51 case SWMM_NODE_OUTFALL: out_type = NodeType::OUTFALL; return true;
52 case SWMM_NODE_STORAGE: out_type = NodeType::STORAGE; return true;
53 case SWMM_NODE_DIVIDER: out_type = NodeType::DIVIDER; return true;
54 default: return false;
55 }
56}
57
58inline int internal_to_c_node_type(NodeType type) noexcept {
59 switch (type) {
64 default: return SWMM_NODE_JUNCTION;
65 }
66}
67
68// ============================================================================
69// Link type mapping (C API and internal values match, but wrap for symmetry)
70// ============================================================================
71
72inline bool c_to_internal_link_type(int c_type, LinkType& out_type) noexcept {
73 switch (c_type) {
74 case SWMM_LINK_CONDUIT: out_type = LinkType::CONDUIT; return true;
75 case SWMM_LINK_PUMP: out_type = LinkType::PUMP; return true;
76 case SWMM_LINK_ORIFICE: out_type = LinkType::ORIFICE; return true;
77 case SWMM_LINK_WEIR: out_type = LinkType::WEIR; return true;
78 case SWMM_LINK_OUTLET: out_type = LinkType::OUTLET; return true;
79 default: return false;
80 }
81}
82
83inline int internal_to_c_link_type(LinkType type) noexcept {
84 switch (type) {
86 case LinkType::PUMP: return SWMM_LINK_PUMP;
88 case LinkType::WEIR: return SWMM_LINK_WEIR;
90 default: return SWMM_LINK_CONDUIT;
91 }
92}
93
94} // namespace openswmm
95
96#endif /* OPENSWMM_ENGINE_TYPE_HELPERS_HPP */
Structure-of-Arrays (SoA) storage for all node types.
Definition NodeCoupling.cpp:16
int internal_to_c_link_type(LinkType type) noexcept
Definition TypeHelpers.hpp:83
LinkType
Link type codes.
Definition LinkData.hpp:58
@ CONDUIT
Definition LinkData.hpp:59
@ PUMP
Definition LinkData.hpp:60
@ WEIR
Definition LinkData.hpp:62
@ ORIFICE
Definition LinkData.hpp:61
@ OUTLET
Definition LinkData.hpp:63
NodeType
Node type codes.
Definition NodeData.hpp:59
@ JUNCTION
Definition NodeData.hpp:60
@ DIVIDER
Definition NodeData.hpp:62
@ STORAGE
Definition NodeData.hpp:63
@ OUTFALL
Definition NodeData.hpp:61
bool c_to_internal_node_type(int c_type, NodeType &out_type) noexcept
Definition TypeHelpers.hpp:48
int internal_to_c_node_type(NodeType type) noexcept
Definition TypeHelpers.hpp:58
bool c_to_internal_link_type(int c_type, LinkType &out_type) noexcept
Definition TypeHelpers.hpp:72
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