DependencySorter< ElementType_t > Class Template Reference

A class to return data sorted by dependency. More...

Classes

struct  ElementAndDepencies
 A structure containing an element and the list of its dependencies. More...
 

Public Types

typedef QList< ElementAndDepenciesElementAndDepenciesList
 The type for the list of elements and dependencies. More...
 
typedef ElementType_t ElementType
 The type of elements used in the class. More...
 

Public Member Functions

 DependencySorter ()
 Constructor. More...
 
 DependencySorter (const DependencySorter< ElementType > &other)
 Copy constructor. More...
 
 ~DependencySorter ()
 Destructor. More...
 
void add (ElementType e, ElementType d)
 Adds an element with a single dependency. More...
 
void add (ElementType e, QList< ElementType > d)
 Adds an element with a list of dependencies. More...
 
void add (ElementType e, QSet< ElementType > d)
 Adds an element with a list of dependencies. More...
 
const QMap< ElementType, QSet< ElementType > > elements () const
 Returns the list of elements and their dependencies. More...
 
DependencySorteroperator= (const DependencySorter< ElementType > &other)
 Copy operator. More...
 
QList< ElementTypesort () const
 Returns the sorted list of elements. More...
 
ElementAndDepenciesList sortWithDependencies () const
 Returns the sorted list of elements with dependencies. More...
 

Detailed Description

template<class ElementType_t>
class farsa::DependencySorter< ElementType_t >

A class to return data sorted by dependency.

This class is filled with a list of elements and their dependencies and then returns a list of sorted elements. It is guaranteed that an element in the sorted list comes after all the elements on which it depends (and that are present). The elements can be of any type provided that they can be put into a QMap and QSet (which are used internally). To insert elements use one of the add() functions. If an element is already present, only the list of its dependencies is modified (so that new dependencies are add). To get the sorted list call sort() or sortWithDependencies(). The difference between the two functions is simply that the latter returns a list where each element is the sorted element plus the list of its dependencies, whereas the former simply returns a list of sorted elements

Note
This class is not very efficient, the implementation is intentionally simple

Definition at line 53 of file dependencysorter.h.

Member Typedef Documentation

The type for the list of elements and dependencies.

Definition at line 96 of file dependencysorter.h.

typedef ElementType_t ElementType

The type of elements used in the class.

Definition at line 59 of file dependencysorter.h.

Constructor & Destructor Documentation

DependencySorter ( )
inline

Constructor.

Definition at line 101 of file dependencysorter.h.

DependencySorter ( const DependencySorter< ElementType > &  other)
inline

Copy constructor.

Parameters
otherthe object to copy

Definition at line 111 of file dependencysorter.h.

~DependencySorter ( )
inline

Destructor.

Definition at line 136 of file dependencysorter.h.

Member Function Documentation

void add ( ElementType  e,
ElementType  d 
)
inline

Adds an element with a single dependency.

Parameters
ethe element to add
dthe element on which e depends

Definition at line 157 of file dependencysorter.h.

void add ( ElementType  e,
QList< ElementType d 
)
inline

Adds an element with a list of dependencies.

Parameters
ethe element to add
dthe list of elements on which e depends

Definition at line 168 of file dependencysorter.h.

void add ( ElementType  e,
QSet< ElementType d 
)
inline

Adds an element with a list of dependencies.

Parameters
ethe element to add
dthe list of elements on which e depends

Definition at line 179 of file dependencysorter.h.

const QMap<ElementType, QSet<ElementType> > elements ( ) const
inline

Returns the list of elements and their dependencies.

Returns
a map having the elements as keys and the set of dependencies of each element as value

Definition at line 146 of file dependencysorter.h.

DependencySorter& operator= ( const DependencySorter< ElementType > &  other)
inline

Copy operator.

Parameters
otherthe object to copy
Returns
a reference to this

Definition at line 122 of file dependencysorter.h.

QList<ElementType> sort ( ) const
inline

Returns the sorted list of elements.

Returns
the sorted list of elements

Definition at line 189 of file dependencysorter.h.

Referenced by DependencySorter< ElementType_t >::sortWithDependencies().

ElementAndDepenciesList sortWithDependencies ( ) const
inline

Returns the sorted list of elements with dependencies.

Returns
the sorted list of elements with dependencies

Definition at line 256 of file dependencysorter.h.

References DependencySorter< ElementType_t >::sort().


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