OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
openswmm::NameIndex Class Reference

Bidirectional name↔index registry for SWMM objects. More...

#include <NameIndex.hpp>

Collaboration diagram for openswmm::NameIndex:

Public Member Functions

 NameIndex ()=default
 
int add (const std::string &name)
 Add a new name and assign the next sequential index.
 
int find (std::string_view name) const noexcept
 Look up the index for a name.
 
std::optional< int > try_find (std::string_view name) const noexcept
 Look up the index, returning std::optional.
 
const std::string & name_of (int idx) const
 Return the name for a given index.
 
int size () const noexcept
 Number of registered names.
 
bool empty () const noexcept
 True if no names are registered.
 
void reserve (std::size_t n)
 Pre-allocate for a known count (avoids rehash during input).
 
void clear () noexcept
 Remove all entries.
 
const std::vector< std::string > & names () const noexcept
 Read-only access to the ordered name list.
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ NameIndex()

openswmm::NameIndex::NameIndex ( )
default

Member Function Documentation

◆ add()

int openswmm::NameIndex::add ( const std::string &  name)
inline

Add a new name and assign the next sequential index.

Parameters
nameObject name (stored as-is; case sensitivity is caller's responsibility).
Returns
Assigned index (== size() before this call).
Exceptions
std::invalid_argumentif name is already registered.
Here is the caller graph for this function:

◆ clear()

void openswmm::NameIndex::clear ( )
inlinenoexcept

Remove all entries.

Here is the caller graph for this function:

◆ empty()

bool openswmm::NameIndex::empty ( ) const
inlinenoexcept

True if no names are registered.

◆ find()

int openswmm::NameIndex::find ( std::string_view  name) const
inlinenoexcept

Look up the index for a name.

Parameters
nameObject name.
Returns
Index, or -1 if not found.
Here is the caller graph for this function:

◆ name_of()

const std::string & openswmm::NameIndex::name_of ( int  idx) const
inline

Return the name for a given index.

Exceptions
std::out_of_rangeif idx is out of bounds.
Here is the caller graph for this function:

◆ names()

const std::vector< std::string > & openswmm::NameIndex::names ( ) const
inlinenoexcept

Read-only access to the ordered name list.

Here is the caller graph for this function:

◆ reserve()

void openswmm::NameIndex::reserve ( std::size_t  n)
inline

Pre-allocate for a known count (avoids rehash during input).

◆ size()

int openswmm::NameIndex::size ( ) const
inlinenoexcept

Number of registered names.

Here is the caller graph for this function:

◆ try_find()

std::optional< int > openswmm::NameIndex::try_find ( std::string_view  name) const
inlinenoexcept

Look up the index, returning std::optional.


The documentation for this class was generated from the following file: