#include <Hierarchy.hpp>
Inheritance diagram for Hierarchy:
The hierarchy is a tree (or a forest, see Internals), whose leaves correspond to the nodes of the underlying graph.
The edges of the underlying graph, though, are not included in the hierarchy (otherwise, it would not be a valid tree structure any more).
The edges in the Hierarchy class are top-down, that means: the source is the parent and the target is the child. (There was no special reason to do it either way, so the decision for this direction was made more or less randomly.)
The hierarchy is in fact not necessarily a tree, but a forest, there is no requirement of a single top node. We could not think of any reason why we should require this, so we decided that it would be better to leave this to the actual implementation. This means that all structures using the hierarchy should be prepared to work on a forest.
The hierarchy does not store any information which makes it easier for the view to collapse or expand nodes: It has no knowledge of the Views.
Public Member Functions | |
Hierarchy () | |
Empty constructor. | |
Hierarchy (ObservableGraph *g, PropertyFacility *p=NULL) | |
Constructor. | |
Hierarchy (const Hierarchy &h) | |
Copy constructor. | |
virtual | ~Hierarchy () |
Cleanup. | |
virtual void | node_id (Node n, NodeID id) |
Set the ID of a node and invoke an update message. | |
virtual void | edge_id (Edge e, EdgeID id) |
Set the ID of an edge and invoke an update message. | |
void | update (Subject *sub, long msg, Item item) |
Base graph update. | |
Node | step (std::vector< Node >::const_iterator children_begin, std::vector< Node >::const_iterator children_end, NodeID id=NodeID("")) |
Add a hierarchical node to the hierarchy. | |
Node | step (std::vector< Node > *children, NodeID id=NodeID("")) |
Add a hierarchical node to the hierarchy (calls overloaded step()). | |
void | unstep (Node node) |
Delete a hierarchical node from the graph. | |
void | connect (Node node, Node parent) |
Connect a (parentless) hierarchical node to a parent (which can't be in the base graph). | |
void | disconnect (Node node) |
Disconnect a hierarchical node from its parent. | |
Node | hierarchy_node (const Node node) const |
Returns the hierarchy node corresponding to the given graph node. | |
Node | graph_node (const Node node) const |
Returns the graph node corresponding to the given hierarchy node. | |
ObservableGraph * | get_graph () const |
Returns the base graph of the Hierarchy. | |
void | set_graph (ObservableGraph *g) |
Sets the base graph of the Hierarchy. | |
Private Member Functions | |
void | init (ObservableGraph *g, PropertyFacility *p) |
Initialize Hierarchy. | |
void | del_node_update (Node node) |
Base graph del node update. | |
Private Attributes | |
std::hash_map< Node, Node > * | graphnodes |
Maps Hierarchy nodes to Graph nodes. | |
std::hash_map< Node, Node > * | hierarchynodes |
Maps Graph nodes to Hierarchy nodes. | |
ObservableGraph * | obsgraph |
The underlying graph. | |
bool | own_obsgraph |
Documenting if the underlying graph was created (and should be deleted) by the Hierarchy. |
|
Empty constructor. This will create an ObservableGraph, which will be deleted when the Hierarchy is deleted. |
|
Constructor.
|
|
Copy constructor. This never creates an own graph. It will always be a hierarchy on the graph of the cloned hierarchy. |
|
Cleanup.
|
|
Connect a (parentless) hierarchical node to a parent (which can't be in the base graph). This connects a node (which has to have no parent in the hierarchy) to another node (which has to be a node not corresponding to a node in the underlying graph). The embraced preconditions are necessary to maintain a valid tree structure. If they do not hold, an exception is thrown. Connect is done by simply creating a new edge (constant time). Note that if a view is an observer of this hierarchy, this can lead to more actions in the view (see View::new_edge_update()).
|
|
Base graph del node update. When a node of the base graph was deleted, the hierarchy deletes it's corresponding hierarchy node, and all the parent nodes up until a parent which has children besides the deleted node. |
|
Disconnect a hierarchical node from its parent. The disconnect is done by simply deleting an edge (constant time). If the Hierarchy was a tree, it will be a forest after this operation. After disconnecting a Node, it can be connected to another Hierarchy node. Note that if a view is an observer of this hierarchy, this can lead to more actions in the view (see View::del_edge_update()).
|
|
Set the ID of an edge and invoke an update message. See ConstGraph::edge_id(e, id)
Reimplemented from ConstGraph. |
|
Returns the base graph of the Hierarchy.
|
|
Returns the graph node corresponding to the given hierarchy node. For a detailed explanation, check Hierarchy::hierarchy_node. Complexity (stl hash_map.find):
|
|
Returns the hierarchy node corresponding to the given graph node. To check if the returned node is valid, use ConstGraph::valid_node(Node node). Complexity (stl hash_map.find):
|
|
Initialize Hierarchy.
|
|
Set the ID of a node and invoke an update message. See ConstGraph::node_id(n, id)
Reimplemented from ConstGraph. |
|
Sets the base graph of the Hierarchy. This sets the graph on which the hierarchy is built. Before it does this, it unregisteres itself as an observer from the previous underlying graph (which is deleted if it was created by the hierarchy), and deletes all it's nodes and edges. A fresh hierarchy is then built on the new underlying graph. |
|
Add a hierarchical node to the hierarchy (calls overloaded step()).
|
|
Add a hierarchical node to the hierarchy. Behaviour:
The more generic approach of using two iterators to define the range was used, because there are cases in which just a range of a dataset should be used, and then it's more convenient to just pass two iterators instead of copying every node into a new array. In all other cases, it's easy to get the iterators (e.g. vector<Node>::begin(), vector<Node>::end() ). Complexity: Linear in the number of nodes to step Note that if a view is an observer of this hierarchy, this can lead to more actions in the view.
|
|
Delete a hierarchical node from the graph. This will delete a node from the hierarchy (if the node is not a node corresponding to the underlying graph). Also, if the node had a parent node, all it's children are attached to it's parent after the node was deleted. Complexity: O( degree(node) ) Note that if a view is an observer of this hierarchy, this can lead to more actions in the view.
|
|
Base graph update. This implementation listens only to changes to the nodes of the underlying graph. Edges of the base graph are not inportant for the Hierarchy. Implements Observer. |
|
Maps Hierarchy nodes to Graph nodes.
|
|
Maps Graph nodes to Hierarchy nodes.
|
|
The underlying graph.
|
|
Documenting if the underlying graph was created (and should be deleted) by the Hierarchy.
|