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:
69 void clear() {
70 name_.clear();
71 kind_.clear();
72 units_.clear();
73 n_pollutants_ = 0;
74 }
75
87 int add(std::string name, SpeciesKind kind, std::string units) {
88 if (find(name) >= 0)
89 return -1;
90 name_.push_back(std::move(name));
91 kind_.push_back(kind);
92 units_.push_back(std::move(units));
94 ++n_pollutants_;
95 return static_cast<int>(name_.size()) - 1;
96 }
97
104 int find(std::string_view name) const {
105 for (std::size_t i = 0; i < name_.size(); ++i)
106 if (name_[i] == name)
107 return static_cast<int>(i);
108 return -1;
109 }
110
115 int count() const noexcept { return static_cast<int>(name_.size()); }
121 int pollutant_count() const noexcept { return n_pollutants_; }
122
131 int transported_count() const noexcept {
132 int n = 0;
133 for (const auto k : kind_)
136 ++n;
137 return n;
138 }
139
146 const std::string& name(int i) const { return name_[static_cast<std::size_t>(i)]; }
153 SpeciesKind kind(int i) const { return kind_[static_cast<std::size_t>(i)]; }
160 const std::string& units(int i) const { return units_[static_cast<std::size_t>(i)]; }
161
172 void truncate_to(int n) {
173 if (n < 0)
174 n = 0;
175 if (n >= count())
176 return;
177 const auto un = static_cast<std::size_t>(n);
178 name_.resize(un);
179 kind_.resize(un);
180 units_.resize(un);
181 n_pollutants_ = 0;
182 for (const auto k : kind_)
183 if (k == SpeciesKind::POLLUTANT)
184 ++n_pollutants_;
185 }
186
187private:
188 std::vector<std::string> name_;
189 std::vector<SpeciesKind> kind_;
190 std::vector<std::string> units_;
191 int n_pollutants_ = 0;
192};
193
194} // namespace openswmm
195
196#endif // OPENSWMM_ENGINE_DATA_SPECIES_REGISTRY_HPP
Definition SpeciesRegistry.hpp:61
int transported_count() const noexcept
Count mesh-transported constituent kinds.
Definition SpeciesRegistry.hpp:131
int pollutant_count() const noexcept
Count registered entries marked POLLUTANT.
Definition SpeciesRegistry.hpp:121
int find(std::string_view name) const
Find the first byte-exact species name.
Definition SpeciesRegistry.hpp:104
void truncate_to(int n)
Drop registry entries from a specified index onward.
Definition SpeciesRegistry.hpp:172
const std::string & name(int i) const
Borrow a species identifier.
Definition SpeciesRegistry.hpp:146
void clear()
Erase all species and reset the pollutant count.
Definition SpeciesRegistry.hpp:69
int count() const noexcept
Count registered constituents of all kinds.
Definition SpeciesRegistry.hpp:115
int add(std::string name, SpeciesKind kind, std::string units)
Append a uniquely named species across all kinds.
Definition SpeciesRegistry.hpp:87
const std::string & units(int i) const
Borrow a species unit label.
Definition SpeciesRegistry.hpp:160
SpeciesKind kind(int i) const
Read a species category.
Definition SpeciesRegistry.hpp:153
Definition ExchangeLaw.hpp:60
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