OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SpeciesRegistry.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
42
43#ifndef OPENSWMM_ENGINE_DATA_SPECIES_REGISTRY_HPP
44#define OPENSWMM_ENGINE_DATA_SPECIES_REGISTRY_HPP
45
46#include <string>
47#include <string_view>
48#include <vector>
49
50namespace openswmm {
51
60
62public:
63 void clear() {
64 name_.clear();
65 kind_.clear();
66 units_.clear();
67 n_pollutants_ = 0;
68 }
69
73 int add(std::string name, SpeciesKind kind, std::string units) {
74 if (find(name) >= 0) return -1;
75 name_.push_back(std::move(name));
76 kind_.push_back(kind);
77 units_.push_back(std::move(units));
78 if (kind == SpeciesKind::POLLUTANT) ++n_pollutants_;
79 return static_cast<int>(name_.size()) - 1;
80 }
81
82 int find(std::string_view name) const {
83 for (std::size_t i = 0; i < name_.size(); ++i)
84 if (name_[i] == name) return static_cast<int>(i);
85 return -1;
86 }
87
88 int count() const noexcept { return static_cast<int>(name_.size()); }
89 int pollutant_count() const noexcept { return n_pollutants_; }
90
100 int transported_count() const noexcept {
101 int n = 0;
102 for (const auto k : kind_)
106 ++n;
107 return n;
108 }
109
110 const std::string& name(int i) const { return name_[static_cast<std::size_t>(i)]; }
111 SpeciesKind kind(int i) const { return kind_[static_cast<std::size_t>(i)]; }
112 const std::string& units(int i) const { return units_[static_cast<std::size_t>(i)]; }
113
118 void truncate_to(int n) {
119 if (n < 0) n = 0;
120 if (n >= count()) return;
121 const auto un = static_cast<std::size_t>(n);
122 name_.resize(un);
123 kind_.resize(un);
124 units_.resize(un);
125 n_pollutants_ = 0;
126 for (const auto k : kind_)
127 if (k == SpeciesKind::POLLUTANT) ++n_pollutants_;
128 }
129
130private:
131 std::vector<std::string> name_;
132 std::vector<SpeciesKind> kind_;
133 std::vector<std::string> units_;
134 int n_pollutants_ = 0;
135};
136
137} // namespace openswmm
138
139#endif // OPENSWMM_ENGINE_DATA_SPECIES_REGISTRY_HPP
Definition SpeciesRegistry.hpp:61
int transported_count() const noexcept
Definition SpeciesRegistry.hpp:100
int pollutant_count() const noexcept
Definition SpeciesRegistry.hpp:89
int find(std::string_view name) const
Definition SpeciesRegistry.hpp:82
void truncate_to(int n)
Definition SpeciesRegistry.hpp:118
const std::string & name(int i) const
Definition SpeciesRegistry.hpp:110
void clear()
Definition SpeciesRegistry.hpp:63
int count() const noexcept
Definition SpeciesRegistry.hpp:88
int add(std::string name, SpeciesKind kind, std::string units)
Definition SpeciesRegistry.hpp:73
const std::string & units(int i) const
Definition SpeciesRegistry.hpp:112
SpeciesKind kind(int i) const
Definition SpeciesRegistry.hpp:111
Definition NodeCoupling.cpp:16
SpeciesKind
Constituent kinds (master plan ยง4.1).
Definition SpeciesRegistry.hpp:53
@ POLLUTANT
legacy [POLLUTANTS] entry
Definition SpeciesRegistry.hpp:54
@ MSX_BULK
reactions component BULK species (R1)
Definition SpeciesRegistry.hpp:57
@ RESERVED_AGE
WATER_AGE (phase A1)
Definition SpeciesRegistry.hpp:55
@ MSX_WALL
reactions component WALL species (R1)
Definition SpeciesRegistry.hpp:58
@ RESERVED_TEMPERATURE
TEMPERATURE (phase H1)
Definition SpeciesRegistry.hpp:56