DiaDes  0.1
DIAgnosis of Discrete-Event System
Public Types | Public Member Functions | Private Attributes | List of all members
Diades::Utils::Dispatcher< Size > Class Template Reference

#include <Dispatcher.hh>

Public Types

using Array = std::array< unsigned, Size >
 

Public Member Functions

 Dispatcher (unsigned n)
 
const Arrayinit ()
 
const Arraynext ()
 
bool hasNext () const
 
bool empty () const
 
unsigned nbElements () const
 
const long unsigned int size () const
 

Private Attributes

Array _current
 
std::stack< std::pair< unsigned, unsigned > > _stack
 
unsigned _n
 

Detailed Description

template<long unsigned int Size>
class Diades::Utils::Dispatcher< Size >

A Dispatcher is a class that implements a simple dispatch algorithm. Suppose that there is n elements and M boxes. A dispatch is the assignment of the n elements in the m boxes. Basically, to use the dispatcher,

unsigned n = 1;
const unsigned M = 3;
if(!dispatcher.empty())
{
const auto & current = dispatcher.init();
// do something with current
while(dispatcher.hasNext())
{
const auto & current = dispatcher.next();
// do something with current
}
}

Definition at line 49 of file Dispatcher.hh.

Member Typedef Documentation

◆ Array

template<long unsigned int Size>
using Diades::Utils::Dispatcher< Size >::Array = std::array<unsigned, Size>

Definition at line 54 of file Dispatcher.hh.

Constructor & Destructor Documentation

◆ Dispatcher()

template<long unsigned int Size>
Diades::Utils::Dispatcher< Size >::Dispatcher ( unsigned  n)
inline

Constructor

Parameters
nthe number of elements to dispatch

Definition at line 61 of file Dispatcher.hh.

Member Function Documentation

◆ empty()

template<long unsigned int Size>
bool Diades::Utils::Dispatcher< Size >::empty ( ) const
inline
Returns
if there is no dispatch (basically, it is the case only when n=0)

Definition at line 137 of file Dispatcher.hh.

◆ hasNext()

template<long unsigned int Size>
bool Diades::Utils::Dispatcher< Size >::hasNext ( ) const
inline
Returns
true if there is still another dispatch to enumerate

Definition at line 129 of file Dispatcher.hh.

◆ init()

template<long unsigned int Size>
const Array& Diades::Utils::Dispatcher< Size >::init ( )
inline

Initialise the enumeration of the possible dispatches

Returns
the first dispatch of the enumeration

Definition at line 68 of file Dispatcher.hh.

◆ nbElements()

template<long unsigned int Size>
unsigned Diades::Utils::Dispatcher< Size >::nbElements ( ) const
inline
Returns
the number of elements to dispatch

Definition at line 146 of file Dispatcher.hh.

◆ next()

template<long unsigned int Size>
const Array& Diades::Utils::Dispatcher< Size >::next ( )
inline

Compute the next dispatch or the enumeration

Returns
the new current dispatch
Postcondition
if hasNext() the dispatch is a new dispatch from the enumeration but if not hasNext the result is undetermined

Definition at line 84 of file Dispatcher.hh.

◆ size()

template<long unsigned int Size>
const long unsigned int Diades::Utils::Dispatcher< Size >::size ( ) const
inline
Returns
the size of the container (it is Size)

Definition at line 155 of file Dispatcher.hh.

Member Data Documentation

◆ _current

template<long unsigned int Size>
Diades::Utils::Dispatcher< Size >::_current
private

This array contains the current dispatch

Definition at line 166 of file Dispatcher.hh.

◆ _n

template<long unsigned int Size>
unsigned Diades::Utils::Dispatcher< Size >::_n
private

Definition at line 180 of file Dispatcher.hh.

◆ _stack

template<long unsigned int Size>
Diades::Utils::Dispatcher< Size >::_stack
private

This is the stack that is used to perform the enumeration of the dispatches An element of the stack is a pair

<k,l>

where k is the number of elements that is dispatched at this level and l is the number of remaining elements to dispatch in higher level of the stack. The size of the stack is in the worst case Size.

Definition at line 175 of file Dispatcher.hh.


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