stmm-games-doc  0.32.0
Public Member Functions | Protected Member Functions | List of all members
stmg::NamedObjIndex< T > Class Template Reference

Named objects indexed template class. More...

Inheritance diagram for stmg::NamedObjIndex< T >:
Inheritance graph
[legend]

Public Member Functions

 NamedObjIndex () noexcept
 Constructor. More...
 
 NamedObjIndex (const NamedObjIndex< T > &oSource) noexcept
 
 NamedObjIndex (NamedObjIndex< T > &&oSource) noexcept
 
int32_t size () const noexcept
 The number names in the named object index. More...
 
bool isIndex (int32_t nIndex) const noexcept
 Whether an index is associated with a named object. More...
 
const std::string & getName (int32_t nIndex) const noexcept
 Get the name associated with an index. More...
 
const T & getObj (int32_t nIndex) const noexcept
 Get the object associated with the index. More...
 
int32_t addNamedObj (const std::string &sName, const T &oT) noexcept
 Add a named object. More...
 
int32_t addNamedObj (std::string &&sName, T &&oT) noexcept
 Add a named object. More...
 
int32_t getIndex (const std::string &sName) const noexcept
 The index associated with a name. More...
 
int32_t findIndexNameStarts (const std::string &sStartOfName) const noexcept
 Find the first index with a name that starts with a string. More...
 

Protected Member Functions

NamedObjIndex< T > & operator= (const NamedObjIndex< T > &oSource) noexcept
 
NamedObjIndex< T > & operator= (NamedObjIndex< T > &&oSource) noexcept
 
T & getModifiableObj (int32_t nIndex) noexcept
 Get the modifiable object associated with the index. More...
 
void clear () noexcept
 Clear all objects. More...
 

Detailed Description

template<class T>
class stmg::NamedObjIndex< T >

Named objects indexed template class.

This class allows to uniquely associate a string with a number so that the number can be used to get the object instead of the string.

Uniqueness of the stored objects is not enforced. The requirements to objects (the template parameter class) is the same as for the objects in a std::vector.

Constructor & Destructor Documentation

◆ NamedObjIndex() [1/3]

template<class T >
stmg::NamedObjIndex< T >::NamedObjIndex ( )
noexcept

Constructor.

◆ NamedObjIndex() [2/3]

template<class T>
stmg::NamedObjIndex< T >::NamedObjIndex ( const NamedObjIndex< T > &  oSource)
noexcept

◆ NamedObjIndex() [3/3]

template<class T>
stmg::NamedObjIndex< T >::NamedObjIndex ( NamedObjIndex< T > &&  oSource)
noexcept

Member Function Documentation

◆ addNamedObj() [1/2]

template<class T>
int32_t stmg::NamedObjIndex< T >::addNamedObj ( const std::string &  sName,
const T &  oT 
)
noexcept

Add a named object.

If the name already exists the object is not overwritten. To do so use getModifiableObj().

Parameters
sNameThe name. Cannot be empty.
oTThe object.
Returns
The associated index. Is >= 0.

◆ addNamedObj() [2/2]

template<class T>
int32_t stmg::NamedObjIndex< T >::addNamedObj ( std::string &&  sName,
T &&  oT 
)
noexcept

Add a named object.

If the name already exists the object is not overwritten. To do so use getModifiableObj().

Parameters
sNameThe name. Cannot be empty.
oTThe object.
Returns
The associated index. Is >= 0.

◆ clear()

template<class T >
void stmg::NamedObjIndex< T >::clear ( )
protectednoexcept

Clear all objects.

◆ findIndexNameStarts()

template<class T >
int32_t stmg::NamedObjIndex< T >::findIndexNameStarts ( const std::string &  sStartOfName) const
noexcept

Find the first index with a name that starts with a string.

Parameters
sStartOfNameThe starting string. Cannot be empty.
Returns
The index or -1 if name not found.

◆ getIndex()

template<class T >
int32_t stmg::NamedObjIndex< T >::getIndex ( const std::string &  sName) const
noexcept

The index associated with a name.

Parameters
sNameThe name. Cannot be empty.
Returns
The index or -1 if name not found.

◆ getModifiableObj()

template<class T >
T & stmg::NamedObjIndex< T >::getModifiableObj ( int32_t  nIndex)
protectednoexcept

Get the modifiable object associated with the index.

If you need this function to be public use class AssignableNamedObjIndex.

Parameters
nIndexThe index. Must be >= 0 and < size().
Returns
The object reference.

◆ getName()

template<class T >
const std::string & stmg::NamedObjIndex< T >::getName ( int32_t  nIndex) const
noexcept

Get the name associated with an index.

Parameters
nIndexThe index. Must be >= 0 and < size().
Returns
The name. Is not empty.

◆ getObj()

template<class T >
const T & stmg::NamedObjIndex< T >::getObj ( int32_t  nIndex) const
noexcept

Get the object associated with the index.

Parameters
nIndexThe index. Must be >= 0 and < size().
Returns
The object.

◆ isIndex()

template<class T >
bool stmg::NamedObjIndex< T >::isIndex ( int32_t  nIndex) const
inlinenoexcept

Whether an index is associated with a named object.

Parameters
nIndexThe index.
Returns
Whether it is valid.

◆ operator=() [1/2]

template<class T>
NamedObjIndex< T > & stmg::NamedObjIndex< T >::operator= ( const NamedObjIndex< T > &  oSource)
protectednoexcept

◆ operator=() [2/2]

template<class T>
NamedObjIndex< T > & stmg::NamedObjIndex< T >::operator= ( NamedObjIndex< T > &&  oSource)
protectednoexcept

◆ size()

template<class T >
int32_t stmg::NamedObjIndex< T >::size ( ) const
inlinenoexcept

The number names in the named object index.

Returns
The size.