Depends::Depends< ValueType > Class Template Reference

A simple, generic dependency tracker. More...

#include <Depends/Depends.h>

List of all members.

Public Types

typedef Storage::iterator iterator
 A random-access iterator into our storage.
typedef Storage::const_iterator const_iterator
 A random-access const_iterator into our storage.
typedef Storage::reverse_iterator reverse_iterator
 A random-access iterator into our storage.
typedef Storage::const_reverse_iterator const_reverse_iterator
 A random-access const_iterator into our storage.
typedef std::iterator_traits<
iterator >::value_type 
value_type
 The value-type as exposed.
typedef std::iterator_traits<
iterator >::reference 
reference
 The reference-type as exposed.
typedef std::iterator_traits<
const_iterator >::reference 
const_reference
 The const reference-type as exposed.
typedef std::iterator_traits<
iterator >::pointer 
pointer
 The pointer-type as exposed.
typedef std::iterator_traits<
iterator >::difference_type 
difference_type
 The difference type as exposed.
typedef Storage::size_type size_type
 The size-type as exposed.

Public Member Functions

 Depends ()
 Default-construct and empty tracker.
template<typename InputIterator>
 Depends (InputIterator begin, InputIterator end)
 Construct a tracker from a range of things convertible to ValueType.
bool empty () const throw ()
 Check whether the tracker is empty.
size_type size () const throw ()
iterator begin ()
 Get a random-access iterator to the start of our storage.
const_iterator begin () const
 Get a random-access iterator to the start of our storage.
iterator end ()
 Get a random-access iterator one past the end of our storage.
const_iterator end () const
 Get a random-access iterator one past the end of our storage.
reverse_iterator rbegin ()
 Get a random-access reverse iterator to the end of our storage.
const_reverse_iterator rbegin () const
 Get a random-access reverse iterator to the end of our storage.
reverse_iterator rend ()
 Get a random-access reverse iterator to the start of our storage.
const_reverse_iterator rend () const
 Get a random-access reverse iterator to the start of our storage.
template<typename V>
const_iterator find (const V &v) const throw ()
 find a value equivalent to v
template<typename V>
iterator find (const V &v) throw ()
template<typename InputIterator>
void insert (InputIterator begin, InputIterator end)
 Insert a range of elements into our storage.
std::pair< iterator, bool > insert (const value_type &v)
 Insert an element into our storage and return an iterator and a bool indicating whether there was an insertion.
iterator insert (const iterator &where, const value_type &what)
 Insert an element with a hint as to the location where that should be done. Note we don't use the hint.
template<typename V>
size_type erase (const V &v)
 Erase any value equivalent to v, return the amount of elements erased.
void erase (iterator where)
void erase (const iterator &begin, const iterator &end)
void clear ()
void select (const_iterator what)
 Select something in the tracker to track the dependencies for.
void select (const value_type &v)
 Select something in the tracker to track the dependencies for.
void addPrerequisite (const_iterator whence)
 Link the pointed-to value to the currently selected value as a prerequisite.
void addPrerequisite (const value_type &v)
 Link the value to the currently selected value as a prerequisite - the value is added to the tracker if need be.
void removePrerequisite (const_iterator whence)
 Remove the link between the pointed-to value and the currently selected one.
void removePrerequisite (const value_type &value)
 Remove the link between the give value and the currently selected one.
std::set< value_typegetPrerequisites (bool all=false) const
 Get the prerequisites of the currently selected value.
void addDependant (const_iterator whence)
 Link the pointed-to value to the currently selected value as a dependant.
void addDependant (const value_type &v)
 Link the value to the currently selected value as a dependant - the value is added to the tracker if need be.
void removeDependant (const_iterator whence)
 Remove the link between the pointed-to value and the currently selected one.
void removeDependant (const value_type &value)
 Remove the link between the pointed-to value and the currently selected one.
std::set< value_typegetDependants (bool all=false) const
 Get the dependants of the currently selected value.
bool depends (const_iterator target, const_iterator source) const
 check whether target depends on source
bool depends (const_iterator target, const value_type &source) const
 check whether target depends on source
bool depends (const value_type &target, const_iterator source) const
 check whether target depends on source
bool depends (const value_type &target, const value_type &source) const
 check whether target depends on source


Detailed Description

template<typename ValueType>
class Depends::Depends< ValueType >

A simple, generic dependency tracker.

The requirements this class has to meet are:

This dependency tracker, unlike the DAG class, is neither CopyConstructible nor Assignable and does, therefore, not completely emulate an STL container.

The dependency tracker contains an internal storage to which you can add elements, which (even) remain mutable. Its purpose is to track the dependencies between the items in that internal storage, for which it uses a DAG. The existance of that DAG, however, is hidden from you for most intents and purposes.

In order to track the dependencies between items in the tracker, you must first select the item in the tracker who's dependencies you want to track. You can then add either prerequisites or dependants

Prerequisites and Dependants

A prerequisite is something on which the currently selected item depends while a dependant is something that depends on the currently selected item. The following code creates a dependency tracker containing three integer values and defines '0' as a prerequisite of '1' (and thus defines '1' as a dependant of '0')
void test8()
{
        int i1[3] = { 0, 1, 2 };
        Depends::Depends< int > deps(i1, i1 + 3);
        deps.select(1);
        deps.addPrerequisite(0);
        assert(deps.depends(1, 0));
        assert(deps.depends(deps.find(1), 0));
        assert(deps.depends(1, deps.find(0)));
        assert(deps.depends(deps.find(1), deps.find(0)));
        assert(!deps.depends(0, 1));
        assert(!deps.depends(deps.find(0), 1));
        assert(!deps.depends(0, deps.find(1)));
        assert(!deps.depends(deps.find(0), deps.find(1)));
}
and the following does exactly the same thing:
void test9()
{
        int i1[3] = { 0, 1, 2 };
        Depends::Depends< int > deps(i1, i1 + 3);
        deps.select(0);
        deps.addDependant(1);
        assert(deps.depends(1, 0));
        assert(deps.depends(deps.find(1), 0));
        assert(deps.depends(1, deps.find(0)));
        assert(deps.depends(deps.find(1), deps.find(0)));
        assert(!deps.depends(0, 1));
        assert(!deps.depends(deps.find(0), 1));
        assert(!deps.depends(0, deps.find(1)));
        assert(!deps.depends(deps.find(0), deps.find(1)));
}

Similarly, it is possible to use the Depends::getDependants function to retrieve either all direct dependants of a given value:

void test11()
{
        int i1[3] = { 0, 1, 2 };
        Depends::Depends< int > deps(i1, i1 + 3);
        deps.select(0);
        deps.addDependant(1);
        deps.select(1);
        deps.addDependant(2);
        std::set< int > preqs(deps.getPrerequisites());
        assert(preqs.size() == 1);
        assert(preqs.find(0) != preqs.end());
        assert(preqs.find(2) == preqs.end());
}
or all dependants of a given value:
void test12()
{
        int i1[3] = { 0, 1, 2 };
        Depends::Depends< int > deps(i1, i1 + 3);
        deps.select(0);
        deps.addDependant(1);
        deps.select(1);
        deps.addDependant(2);
        deps.select(2);
        std::set< int > preqs(deps.getPrerequisites(true));
        assert(preqs.size() == 2);
        assert(preqs.find(0) != preqs.end());
        assert(preqs.find(1) != preqs.end());
        assert(preqs.find(2) == preqs.end());
}
The same is true for the getPrerequisites method.

Definition at line 101 of file Depends.h.


Member Function Documentation

template<typename ValueType>
void Depends::Depends< ValueType >::select ( const_iterator  what  )  [inline]

Select something in the tracker to track the dependencies for.

This method performs the selection by iterator.

Definition at line 267 of file Depends.h.

References Depends::Depends< ValueType >::end().

Referenced by Depends::Depends< ValueType >::select().

template<typename ValueType>
void Depends::Depends< ValueType >::select ( const value_type v  )  [inline]

Select something in the tracker to track the dependencies for.

This method tries to find the given value in the tracker and will insert it if it doesn't exist yet.

Definition at line 279 of file Depends.h.

References Depends::Depends< ValueType >::insert(), and Depends::Depends< ValueType >::select().

template<typename ValueType>
void Depends::Depends< ValueType >::removePrerequisite ( const_iterator  whence  )  [inline]

Remove the link between the pointed-to value and the currently selected one.

Warning:
Such a link can only be broken if it is a direct one!

Definition at line 298 of file Depends.h.

References Depends::Depends< ValueType >::end().

Referenced by Depends::Depends< ValueType >::removePrerequisite().

template<typename ValueType>
void Depends::Depends< ValueType >::removePrerequisite ( const value_type value  )  [inline]

Remove the link between the give value and the currently selected one.

Warning:
Such a link can only be broken if it is a direct one!

Definition at line 311 of file Depends.h.

References Depends::Depends< ValueType >::find(), and Depends::Depends< ValueType >::removePrerequisite().

template<typename ValueType>
std::set< value_type > Depends::Depends< ValueType >::getPrerequisites ( bool  all = false  )  const [inline]

Get the prerequisites of the currently selected value.

Parameters:
all set to true if you want all prerequisites, including those that are not direct prerequisites. If false (the default) only direct prerequisites will be returned.

Definition at line 319 of file Depends.h.

References Depends::Depends< ValueType >::end().

template<typename ValueType>
void Depends::Depends< ValueType >::removeDependant ( const_iterator  whence  )  [inline]

Remove the link between the pointed-to value and the currently selected one.

Warning:
Such a link can only be broken if it is a direct one!

Definition at line 366 of file Depends.h.

References Depends::Depends< ValueType >::end().

Referenced by Depends::Depends< ValueType >::removeDependant().

template<typename ValueType>
void Depends::Depends< ValueType >::removeDependant ( const value_type value  )  [inline]

Remove the link between the pointed-to value and the currently selected one.

Warning:
Such a link can only be broken if it is a direct one!

Definition at line 378 of file Depends.h.

References Depends::Depends< ValueType >::find(), and Depends::Depends< ValueType >::removeDependant().

template<typename ValueType>
std::set< value_type > Depends::Depends< ValueType >::getDependants ( bool  all = false  )  const [inline]

Get the dependants of the currently selected value.

Parameters:
all set to true if you want all dependants, including those that are not direct dependants. If false (the default) only direct dependants will be returned.

Definition at line 386 of file Depends.h.

References Depends::Depends< ValueType >::end().


The documentation for this class was generated from the following file:
Generated on Sat Aug 11 11:56:05 2007 for Depends by  doxygen 1.5.1