![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
Bidirectional name↔index registry for SWMM objects. More...
#include <NameIndex.hpp>
Public Member Functions | |
| NameIndex ()=default | |
| Create an empty registry with no deferred-removal scope. | |
| int | add (const std::string &name) |
| Copy a new name and assign the next sequential index. | |
| int | try_add (const std::string &name) |
| Copy a new name, returning a duplicate sentinel instead of a duplicate exception. | |
| int | find (std::string_view name) const noexcept |
| Look up a borrowed name without allocating a temporary key. | |
| std::optional< int > | try_find (std::string_view name) const noexcept |
| Look up a borrowed name with an optional result. | |
| const std::string * | canonical (std::string_view name) const noexcept |
| Borrow the original spelling of an equivalent registry key. | |
| const std::string & | name_of (int idx) const |
| Borrow a registered name by its ordered index. | |
| int | size () const noexcept |
| Count names in the ordered vector. | |
| bool | empty () const noexcept |
| Test whether the ordered name vector is empty. | |
| void | reserve (std::size_t n) |
| Request capacity for the map and ordered name vector. | |
| void | clear () noexcept |
| Erase all names and map entries. | |
| void | pop_back () noexcept |
| Remove the most recently ordered name without renumbering earlier rows. | |
| bool | rename (int idx, const std::string &newName) noexcept |
| Replace one name while retaining its numeric index. | |
| void | remove_at (int idx) noexcept |
| Erase an ordered name and renumber following indices. | |
| void | begin_bulk_remove () noexcept |
| Enter a nestable scope that defers hash-map rebuilding. | |
| void | end_bulk_remove () |
| Close one deferred-removal scope and rebuild on the outermost close. | |
| const std::vector< std::string > & | names () const noexcept |
| Borrow ordered stored spellings. | |
Bidirectional name↔index registry for SWMM objects.
Maintains both a hash map (name→index) and a vector (index→name) so that either direction of lookup is O(1).
Lookups are CASE-INSENSITIVE (ASCII fold), matching the legacy engine's hash table (src/legacy/engine/hash.c UCHAR). Names are stored with their original spelling — name_of()/names() feed the .out ID tables, interface files, and the .inp/GeoPackage writers, which must round-trip the user's spelling byte-identically. Two names differing only in case are therefore the SAME entry; add() treats them as duplicates, exactly as legacy does.
|
default |
Create an empty registry with no deferred-removal scope.
|
inline |
Copy a new name and assign the next sequential index.
Caller serializes mutation and lookup, and keeps size representable as int. Invalidates vector-backed name views if insertion reallocates.
| std::invalid_argument | When an equivalent name already exists. |
| std::bad_alloc | On allocation; insertion is not strongly transactional if the map insert succeeds before the ordered-name append fails. |
| [in] | name | Borrowed name, matched by ASCII-insensitive byte comparison; empty names are accepted. |
|
inlinenoexcept |
Enter a nestable scope that defers hash-map rebuilding.
While any scope is active, only ordered-vector access/removal is valid; do not use find, try_find, canonical, rename, insertion or map-dependent pop_back. Must pair with end_bulk_remove(), including on exceptional paths. Caller serializes access.
|
inlinenoexcept |
Borrow the original spelling of an equivalent registry key.
Pointer can be invalidated by name-vector insertion, reserve, rename, erasure or clear. Do not call while a bulk-removal scope has made map indices stale.
| [in] | name | Borrowed name, matched by ASCII-insensitive byte comparison; empty names are accepted. |
|
inlinenoexcept |
Erase all names and map entries.
Invalidates borrowed names. Does not reset bulk_depth_; callers must still balance any active begin/end scope.
|
inlinenoexcept |
Test whether the ordered name vector is empty.
|
inline |
Close one deferred-removal scope and rebuild on the outermost close.
Unbalanced close is ignored. Outermost close rebuilds the entire map; allocation exceptions propagate and can leave a partial map after the nesting depth has returned to zero.
|
inlinenoexcept |
Look up a borrowed name without allocating a temporary key.
Not valid while a bulk-removal scope has left the hash map stale.
| [in] | name | Borrowed name, matched by ASCII-insensitive byte comparison; empty names are accepted. |
|
inline |
Borrow a registered name by its ordered index.
Works during deferred removal because the ordered vector stays current.
| std::out_of_range | When idx is not an existing row. |
| [in] | idx | Zero-based index in [0,size()); negative values fail the vector bounds check. |
|
inlinenoexcept |
Borrow ordered stored spellings.
Ordered access remains current while bulk map rebuilding is deferred.
|
inlinenoexcept |
Remove the most recently ordered name without renumbering earlier rows.
Empty is a no-op. Caller must not use this while map indices are stale from deferred removal. Copies the tail key before erasing; because this function is noexcept, allocation failure in that copy terminates.
|
inlinenoexcept |
Erase an ordered name and renumber following indices.
Within a bulk scope erases only names_, leaving the map stale. Outside a scope clears/rebuilds the map. Does not repair any model object references or enforce lifecycle. noexcept means allocation failure during rebuild terminates.
| [in] | idx | Zero-based ordered index; out-of-range is a no-op. |
|
inlinenoexcept |
Replace one name while retaining its numeric index.
Do not call during deferred removal. Borrowed names may be invalidated; no lifecycle validation is performed. This noexcept function can allocate during string/map replacement; allocation failure terminates.
| [in] | idx | Existing ordered index; invalid values return false without mutation. |
| [in] | newName | Copied replacement token; empty is accepted, case-only respelling allowed, collision with another row refused. |
|
inline |
Request capacity for the map and ordered name vector.
Can rehash the map and reallocate names_, invalidating map iterators/name references. Allocation exceptions propagate.
| [in] | n | Expected name count; no elements are inserted. |
|
inlinenoexcept |
Count names in the ordered vector.
|
inline |
Copy a new name, returning a duplicate sentinel instead of a duplicate exception.
Allocation exceptions still propagate; this function is not noexcept. Map insertion precedes ordered-vector append, so an allocation failure in the latter can leave stores inconsistent. Caller serializes access and keeps size representable as int.
| [in] | name | Borrowed name, matched by ASCII-insensitive byte comparison; empty names are accepted. |
|
inlinenoexcept |
Look up a borrowed name with an optional result.
Not valid while bulk removal defers map rebuild.
| [in] | name | Borrowed name, matched by ASCII-insensitive byte comparison; empty names are accepted. |