ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Utils::NumeratedContainer< T, index_type > Class Template Reference

Container for objects that are identified by a numeric id. More...

#include <NumeratedContainer.hpp>

Public Types

typedef std::unordered_map< index_type, T >::iterator iterator
 
typedef std::unordered_map< index_type, T >::const_iterator const_iterator
 
typedef std::unordered_map< index_type, T >::value_type value_type
 

Public Member Functions

 NumeratedContainer ()
 
 NumeratedContainer (std::initializer_list< value_type > l)
 Construct from list of key-value pairs.
 
index_type add (const T &c)
 Copy c into the container.
 
index_type add (T &&c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void remove (index_type i)
 Remove element from container.
 
T & operator[] (index_type i)
 Get element from container.
 
const T & operator[] (index_type i) const
 Get element from container.
 
iterator begin ()
 Get iterator to beginning of the container.
 
const_iterator begin () const
 Get a const iterator to beginning of the container.
 
iterator end ()
 Get an iterator to end of the container.
 
const_iterator end () const
 Get a const iterator to end of the container.
 
iterator find (int id)
 find object by id.
 
const_iterator find (int id) const
 find object by id.
 
std::size_t size () const
 

Detailed Description

template<class T, typename index_type = int>
class Utils::NumeratedContainer< T, index_type >

Container for objects that are identified by a numeric id.

This class implements a container that holds T instances and references them by an integral index. New elements get the lowest free index and indexes are reused. The Container keeps a copy of the objects added.

Definition at line 41 of file NumeratedContainer.hpp.

Member Typedef Documentation

◆ const_iterator

template<class T , typename index_type = int>
typedef std::unordered_map<index_type,T>::const_iterator Utils::NumeratedContainer< T, index_type >::const_iterator

Definition at line 45 of file NumeratedContainer.hpp.

◆ iterator

template<class T , typename index_type = int>
typedef std::unordered_map<index_type,T>::iterator Utils::NumeratedContainer< T, index_type >::iterator

Definition at line 43 of file NumeratedContainer.hpp.

◆ value_type

template<class T , typename index_type = int>
typedef std::unordered_map<index_type,T>::value_type Utils::NumeratedContainer< T, index_type >::value_type

Definition at line 46 of file NumeratedContainer.hpp.

Constructor & Destructor Documentation

◆ NumeratedContainer() [1/2]

template<class T , typename index_type = int>
Utils::NumeratedContainer< T, index_type >::NumeratedContainer ( )
inline

Definition at line 48 of file NumeratedContainer.hpp.

◆ NumeratedContainer() [2/2]

template<class T , typename index_type = int>
Utils::NumeratedContainer< T, index_type >::NumeratedContainer ( std::initializer_list< value_type l)
inlineexplicit

Construct from list of key-value pairs.

The keys have to be unique.

Definition at line 57 of file NumeratedContainer.hpp.

Member Function Documentation

◆ add() [1/2]

template<class T , typename index_type = int>
index_type Utils::NumeratedContainer< T, index_type >::add ( const T &  c)
inline

Copy c into the container.

Assign a free id to c and copy it into the container.

Parameters
cThe object to add.

Definition at line 80 of file NumeratedContainer.hpp.

◆ add() [2/2]

template<class T , typename index_type = int>
index_type Utils::NumeratedContainer< T, index_type >::add ( T &&  c)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 87 of file NumeratedContainer.hpp.

◆ begin() [1/2]

template<class T , typename index_type = int>
iterator Utils::NumeratedContainer< T, index_type >::begin ( )
inline

Get iterator to beginning of the container.

Definition at line 128 of file NumeratedContainer.hpp.

◆ begin() [2/2]

template<class T , typename index_type = int>
const_iterator Utils::NumeratedContainer< T, index_type >::begin ( ) const
inline

Get a const iterator to beginning of the container.

Definition at line 133 of file NumeratedContainer.hpp.

◆ end() [1/2]

template<class T , typename index_type = int>
iterator Utils::NumeratedContainer< T, index_type >::end ( )
inline

Get an iterator to end of the container.

Definition at line 138 of file NumeratedContainer.hpp.

◆ end() [2/2]

template<class T , typename index_type = int>
const_iterator Utils::NumeratedContainer< T, index_type >::end ( ) const
inline

Get a const iterator to end of the container.

Definition at line 143 of file NumeratedContainer.hpp.

◆ find() [1/2]

template<class T , typename index_type = int>
iterator Utils::NumeratedContainer< T, index_type >::find ( int  id)
inline

find object by id.

Parameters
idid of the object to find.
Returns
Iterator to the object if found or end().

Definition at line 151 of file NumeratedContainer.hpp.

◆ find() [2/2]

template<class T , typename index_type = int>
const_iterator Utils::NumeratedContainer< T, index_type >::find ( int  id) const
inline

find object by id.

Parameters
idid of the object to find.
Returns
Iterator to the object if found or end().

Definition at line 159 of file NumeratedContainer.hpp.

◆ operator[]() [1/2]

template<class T , typename index_type = int>
T & Utils::NumeratedContainer< T, index_type >::operator[] ( index_type  i)
inline

Get element from container.

Parameters
iThe object to get.
Returns
Reference to the object with id i.

Definition at line 115 of file NumeratedContainer.hpp.

◆ operator[]() [2/2]

template<class T , typename index_type = int>
const T & Utils::NumeratedContainer< T, index_type >::operator[] ( index_type  i) const
inline

Get element from container.

Parameters
iThe object to get.
Returns
Reference to the object with id i.

Definition at line 123 of file NumeratedContainer.hpp.

◆ remove()

template<class T , typename index_type = int>
void Utils::NumeratedContainer< T, index_type >::remove ( index_type  i)
inline

Remove element from container.

Remove element i and add i to the free indices.

Parameters
iThe object to remove.

Definition at line 101 of file NumeratedContainer.hpp.

◆ size()

template<class T , typename index_type = int>
std::size_t Utils::NumeratedContainer< T, index_type >::size ( ) const
inline

Definition at line 161 of file NumeratedContainer.hpp.


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