Exemple #1
0
/** An edge to be added to the tree must not belong to any tree (including this one). */
void
Tree::add (Tree::Edge* e)
  throw (Tree::DuplicateEdge, Tree::EdgeInUse, Tree::EmptyEdge, Tree::SecondParent, Tree::EmptyEndPoint)
{
  if (e == 0)
    throw EmptyEdge();
  if (edge_set.find(e) != edge_set.end())
    throw DuplicateEdge(e);
  if (e->in_use)
    throw EdgeInUse(e);
  if ((e->child_node == 0) || (e->parent_node == 0))
    throw EmptyEndPoint(e);
  if (e->child_node->incoming != 0)
      throw SecondParent(e);

  // insert the nodes if they don't already exist in the graph
  if (node_set.find(e->parent_node) == node_set.end())
    add(e->parent_node);
  if (node_set.find(e->child_node) == node_set.end())
    add(e->child_node);

  // insert the edge in the corresponding lists of the two nodes
  e->parent_node->outgoing.push_back(e);
  e->child_node->incoming = e;

  // finally, insert the edge itself in the tree
  e->in_use = true;
  edge_set.insert(e);
  preorder_needed = postorder_needed = rpostorder_needed = true;
}
Exemple #2
0
/*! An edge to be added to the tree must not belong to any tree 
    (including this one). */
void
Tree::addEdge(OA_ptr<Tree::Edge>  e)
  throw (Tree::DuplicateEdge, Tree::EdgeInUse, Tree::EmptyEdge, Tree::SecondParent, Tree::EmptyEndPoint)
{
  if (e.ptrEqual(0)) {
    throw EmptyEdge();
  }
  if (edge_set->find(e) != edge_set->end()) {
    throw DuplicateEdge(e);
  }
  if (e->in_use) {
    throw EdgeInUse(e);
  }
  if ((e->child_node.ptrEqual(0)) || (e->parent_node.ptrEqual(0))) {
    throw EmptyEndPoint(e);
  }
  if (!e->child_node->incoming.ptrEqual(0)) {
      throw SecondParent(e);
  }

  // insert the nodes if they don't already exist in the graph
  if (node_set->find(e->parent_node) == node_set->end()) {
    addNode(e->parent_node);
  }
  if (node_set->find(e->child_node) == node_set->end()) {
    addNode(e->child_node);
  }

  // insert the edge in the corresponding lists of the two nodes
  e->parent_node->outgoing->push_back(e);
  e->child_node->incoming = e;

  // finally, insert the edge itself in the tree
  e->in_use = true;
  edge_set->insert(e);
  preorder_needed = postorder_needed = rpostorder_needed = true;
}