xorp

Dependency< T > Class Template Reference

A class which relates objects and handles dependencies between them. More...

#include <dependency.hh>

Inheritance diagram for Dependency< T >:
NONCOPYABLE

List of all members.

Classes

class  DependencyError
 Exception thrown if an illegal action is requested. More...
struct  ObjPair

Public Types

typedef list< string > DependencyList
typedef pair< T *, DependencyList > Pair
typedef map< string, Pair * > Map
typedef set< string > KEYS

Public Member Functions

void clear ()
bool exists (const string &objectname) const
 Checks if an object is present in the container.
bool create (const string &objectname, T *object)
 Attempts to create an object.
void remove (const string &objectname)
 Tries to remove and delete an object.
void add_dependency (const string &objectname, const string &dep)
 Adds dependencies to this object.
void del_dependency (const string &objectname, const string &dep)
 Deletes a dependency on an object.
T & find (const string &objectname) const
 Returns the object being searched for.
T * find_ptr (const string &objectname) const
 Returns a pointer the object being searched for.
void get_deps (const string &objectname, set< string > &deps) const
 Obtains the dependency list for an object.
void update_object (const string &objectname, T *obj)
 Replaces an object.
Map::const_iterator get_iterator () const
 Obtain an iterator for this container.
bool has_next (const typename Map::const_iterator &i) const
 Checks if more objects are available with this iterator.
ObjPair next (typename Map::const_iterator &i) const
 Returns the next object pair and increments the iterator.
void keys (KEYS &out) const

Private Member Functions

Pair * findDepend (const string &objectname) const

Private Attributes

Map _map

Detailed Description

template<class T>
class Dependency< T >

A class which relates objects and handles dependencies between them.

This class is a container of objects [pointers]. It relates string object names to the actual objects. Also, it has the ability to add and remove dependencies to that objects. A dependency is some entity which is using a specific object in the Dependency container. This entity is string represented.

For example, if a policy x uses set y, Set y will have x added in its dependencies. This means that x depends on y.

Having a consistent dependency list allows objects to be deleted correctly.


Member Function Documentation

template<class T >
void Dependency< T >::add_dependency ( const string &  objectname,
const string &  dep 
)

Adds dependencies to this object.

A dependency is another object which uses this object.

Throws an exception if object does not exist.

Parameters:
objectnamename of object to which dependency should be added.
depname of object which depends on objectname.
template<class T>
bool Dependency< T >::create ( const string &  objectname,
T *  object 
)

Attempts to create an object.

If creation is successfull, the object ownership is transfered to this container. The caller should not modify / delete the object any more.

If object exists, creation fails.

Returns:
true if creation was successful. False otherwise.
Parameters:
objectnamename of the object.
objectthe actual object.
template<class T >
void Dependency< T >::del_dependency ( const string &  objectname,
const string &  dep 
)

Deletes a dependency on an object.

Throws an exception if object does not exist.

Parameters:
objectnamename of object to which dependency should be removed.
depname of dependency to remove.
template<class T >
bool Dependency< T >::exists ( const string &  objectname) const

Checks if an object is present in the container.

Returns:
true if object is contained. False otherwise.
Parameters:
objectnamename of the object.
template<class T >
T & Dependency< T >::find ( const string &  objectname) const

Returns the object being searched for.

Parameters:
objectnamename of object to return.
Returns:
object requested.
template<class T >
T * Dependency< T >::find_ptr ( const string &  objectname) const

Returns a pointer the object being searched for.

Parameters:
objectnamename of object to return.
Returns:
a pointer to the object requested if found, otherwise NULL.
template<class T >
void Dependency< T >::get_deps ( const string &  objectname,
set< string > &  deps 
) const

Obtains the dependency list for an object.

Duplicates are removed, as it is a set.

Parameters:
objectnamename of object for which dependency list is requested.
depsset of strings filled with dependency list.
template<class T >
Dependency< T >::Map::const_iterator Dependency< T >::get_iterator ( ) const

Obtain an iterator for this container.

Returns:
iterator for Dependency container.
template<class T >
bool Dependency< T >::has_next ( const typename Map::const_iterator &  i) const

Checks if more objects are available with this iterator.

Returns:
true if more objects are available. False otherwise.
Parameters:
iiterator to use.
template<class T >
Dependency< T >::ObjPair Dependency< T >::next ( typename Map::const_iterator &  i) const

Returns the next object pair and increments the iterator.

An object pair consists of the object name, and the actual object.

Returns:
the object pair associated with the iterator.
Parameters:
iiterator that points to object. Iterator is then incremented.
template<class T >
void Dependency< T >::remove ( const string &  objectname)

Tries to remove and delete an object.

Checks if object is in use [non empty dependency list].

Throws an exception on failure.

Parameters:
objectnameobject to remove and delete.
template<class T>
void Dependency< T >::update_object ( const string &  objectname,
T *  obj 
)

Replaces an object.

The previous one is deleted. Caller does not own object. Should not modify or delete it.

Throws an exception if object does not exist.

Parameters:
objectnamename of object to replace.
objthe new object.

The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Typedefs Enumerations