stmm-games-doc  0.32.0
Public Member Functions | Protected Member Functions | List of all members
stmg::NamedIndex Class Reference

Named indexes class. More...

Inheritance diagram for stmg::NamedIndex:
Inheritance graph
[legend]

Public Member Functions

 NamedIndex () noexcept
 Default constructor. More...
 
 NamedIndex (const NamedIndex &oSource) noexcept
 
 NamedIndex (NamedIndex &&oSource) noexcept
 
int32_t size () const noexcept
 Returns the number of names. More...
 
bool isIndex (int32_t nIndex) const noexcept
 Whether an index is valid. More...
 
const std::string & getName (int32_t nIndex) const noexcept
 The name associated with a given index. More...
 
int32_t addName (const std::string &sName) noexcept
 Adds a name. More...
 
int32_t getIndex (const std::string &sName) const noexcept
 The index of a name. More...
 
int32_t findIndexNameStarts (const std::string &sStartOfName) const noexcept
 The first index of a name starting with a certain string. More...
 
void dump () const noexcept
 

Protected Member Functions

NamedIndexoperator= (const NamedIndex &oSource) noexcept
 The assignment operator. More...
 
NamedIndexoperator= (NamedIndex &&oSource) noexcept
 
void clear () noexcept
 Clear all names. More...
 

Detailed Description

Named indexes class.

This class allows to uniquely associate a string with a number so that the number can be used instead of the string. Names cannot be removed from this class unless it is assigned (operator=()) or NamedIndex::clear() is called. This ensures that the index associated with the string is always >= 0 and < size().

Constructor & Destructor Documentation

◆ NamedIndex() [1/3]

stmg::NamedIndex::NamedIndex ( )
noexcept

Default constructor.

◆ NamedIndex() [2/3]

stmg::NamedIndex::NamedIndex ( const NamedIndex oSource)
noexcept

◆ NamedIndex() [3/3]

stmg::NamedIndex::NamedIndex ( NamedIndex &&  oSource)
noexcept

Member Function Documentation

◆ addName()

int32_t stmg::NamedIndex::addName ( const std::string &  sName)
noexcept

Adds a name.

If the name already exists nothing is added and the index of the existing name is returned.

Parameters
sNameThe name to be added.
Returns
The index of the added name.

◆ clear()

void stmg::NamedIndex::clear ( )
protectednoexcept

Clear all names.

If you want to allow assignment you have to subclass NamedIndex and make this function public.

◆ dump()

void stmg::NamedIndex::dump ( ) const
noexcept

◆ findIndexNameStarts()

int32_t stmg::NamedIndex::findIndexNameStarts ( const std::string &  sStartOfName) const
noexcept

The first index of a name starting with a certain string.

Parameters
sStartOfNameThe start of the name to match
Returns
The index or -1 if not found.

◆ getIndex()

int32_t stmg::NamedIndex::getIndex ( const std::string &  sName) const
noexcept

The index of a name.

Parameters
sNameThe name to lookup.
Returns
The index or -1 if not found.

◆ getName()

const std::string& stmg::NamedIndex::getName ( int32_t  nIndex) const
noexcept

The name associated with a given index.

Parameters
nIndexThe index of the name. Must be valid.
Returns
The string.

◆ isIndex()

bool stmg::NamedIndex::isIndex ( int32_t  nIndex) const
inlinenoexcept

Whether an index is valid.

Index is always >= 0 and < size().

◆ operator=() [1/2]

NamedIndex& stmg::NamedIndex::operator= ( const NamedIndex oSource)
protectednoexcept

The assignment operator.

If you want to allow assignment you have to subclass NamedIndex and make this function public.

◆ operator=() [2/2]

NamedIndex& stmg::NamedIndex::operator= ( NamedIndex &&  oSource)
protectednoexcept

◆ size()

int32_t stmg::NamedIndex::size ( ) const
inlinenoexcept

Returns the number of names.