|
|
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 dependancies to that objects. A dependancy is some entity which is using a specific object in the Dependancy container. This entity is string represented.
For example, if a policy x uses set y, Set y will have x added in its dependancies. This means that x depends on y.
Having a consistent dependancy list allows objects to be deleted correctly.
typedef list<string> DependancyList | DependancyList |
typedef pair<T*,DependancyList> Pair | Pair |
typedef map<string,Pair*> Map | Map |
ObjPair (struct) | ObjPair |
DependancyError (class) | DependancyError |
Such as deleting an object which has a non empty dependancy list.
Dependancy ()
| Dependancy |
~Dependancy ()
| ~Dependancy |
void clear ()
| clear |
bool exists (const string& objectname)
| exists |
[const]
Checks if an object is present in the container.
Parameters:
objectname | name of the object. |
Returns: true if object is contained. False otherwise.
bool create (const string& objectname, T* object)
| create |
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.
Parameters:
objectname | name of the object. |
object | the actual object. |
Returns: true if creation was successful. False otherwise.
void remove (const string& objectname)
| remove |
Tries to remove and delete an object. Checks if object is in use [non empty dependancy list].
Throws an exception on failure.
Parameters:
objectname | object to remove and delete. |
void add_dependancy (const string& objectname, const string& dep)
| add_dependancy |
Adds dependancies to this object. A dependancy is another object which uses this object.
Throws an exception if object does not exist.
Parameters:
objectname | name of object to which dependancy should be added. |
dep | name of object which depends on objectname. |
void del_dependancy (const string& objectname, const string& dep)
| del_dependancy |
Deletes a dependancy on an object.
Throws an exception if object does not exist.
Parameters:
objectname | name of object to which dependancy should be removed. |
dep | name of dependancy to remove. |
T& find (const string& objectname)
| find |
[const]
Returns the object being searched for.
Parameters:
objectname | name of object to return. |
Returns: object requested.
T* find_ptr (const string& objectname)
| find_ptr |
[const]
Returns a pointer the object being searched for.
Parameters:
objectname | name of object to return. |
Returns: a pointer to the object requested if found, otherwise NULL.
void get_deps (const string& objectname, set<string>& deps)
| get_deps |
[const]
Obtains the dependancy list for an object.
Duplicates are removed, as it is a set.
Parameters:
objectname | name of object for which dependancy list is requested. |
deps | set of strings filled with dependancy list. |
void update_object (const string& objectname,T* obj)
| update_object |
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:
objectname | name of object to replace. |
obj | the new object. |
typename Map::const_iterator get_iterator ()
| get_iterator |
[const]
Obtain an iterator for this container.
Returns: iterator for Dependancy container.
bool has_next (const typename Map::const_iterator& i)
| has_next |
[const]
Checks if more objects are available with this iterator.
Parameters:
i | iterator to use. |
Returns: true if more objects are available. False otherwise.
ObjPair next (typename Map::const_iterator& i)
| next |
[const]
Returns the next object pair and increments the iterator.
An object pair consists of the object name, and the actual object.
Parameters:
i | iterator that points to object. Iterator is then incremented. |
Returns: the object pair associated with the iterator.