doc/graphs.dox
changeset 875 fda944f15ca7
parent 873 f3a30fda2e49
child 880 9d0bfd35b97c
     1.1 --- a/doc/graphs.dox	Thu Sep 16 19:24:15 2004 +0000
     1.2 +++ b/doc/graphs.dox	Thu Sep 16 19:51:28 2004 +0000
     1.3 @@ -60,8 +60,6 @@
     1.4  \todo Don't we need SmartNodeSet and SmartEdgeSet?
     1.5  \todo Some cross-refs are wrong.
     1.6  
     1.7 -\bug This file must be updated accordig to the new style iterators.
     1.8 -
     1.9  The graph structures itself can not store data attached
    1.10  to the edges and nodes. However they all provide
    1.11  \ref maps "map classes"
    1.12 @@ -97,8 +95,8 @@
    1.13    for (int i = 0; i < 3; i++)
    1.14      g.addNode();
    1.15    
    1.16 -  for (NodeIt i(g); g.valid(i); g.next(i))
    1.17 -    for (NodeIt j(g); g.valid(j); g.next(j))
    1.18 +  for (NodeIt i(g); i!=INVALID; ++i)
    1.19 +    for (NodeIt j(g); j!=INVALID; ++j)
    1.20        if (i != j) g.addEdge(i, j);
    1.21  \endcode
    1.22  
    1.23 @@ -107,31 +105,18 @@
    1.24  
    1.25  \code
    1.26    std::cout << "Nodes:";
    1.27 -  for (NodeIt i(g); g.valid(i); g.next(i))
    1.28 +  for (NodeIt i(g); i!=INVALID; ++i)
    1.29      std::cout << " " << g.id(i);
    1.30    std::cout << std::endl;
    1.31  \endcode
    1.32  
    1.33  Here we iterate through all nodes of the graph. We use a constructor of the
    1.34 -node iterator to initialize it to the first node. The next member function is
    1.35 -used to step to the next node, and valid is used to check if we have passed the
    1.36 -last one.
    1.37 +node iterator to initialize it to the first node. The operator++ is used to
    1.38 +step to the next node. Using operator++ on the iterator pointing to the last
    1.39 +node invalidates the iterator i.e. sets its value to
    1.40 +\ref hugo::INVALID "INVALID". This is what we exploit in the stop condition.
    1.41  
    1.42 -\code
    1.43 -  std::cout << "Nodes:";
    1.44 -  NodeIt n;
    1.45 -  for (g.first(n); n != INVALID; g.next(n))
    1.46 -    std::cout << " " << g.id(n);
    1.47 -  std::cout << std::endl;
    1.48 -\endcode
    1.49 -
    1.50 -Here you can see an alternative way to iterate through all nodes. Here we use a
    1.51 -member function of the graph to initialize the node iterator to the first node
    1.52 -of the graph. Using next on the iterator pointing to the last node invalidates
    1.53 -the iterator i.e. sets its value to INVALID. Checking for this value is
    1.54 -equivalent to using the valid member function.
    1.55 -
    1.56 -Both of the previous code fragments print out the same:
    1.57 +The previous code fragment prints out the following:
    1.58  
    1.59  \code
    1.60  Nodes: 2 1 0
    1.61 @@ -139,7 +124,7 @@
    1.62  
    1.63  \code
    1.64    std::cout << "Edges:";
    1.65 -  for (EdgeIt i(g); g.valid(i); g.next(i))
    1.66 +  for (EdgeIt i(g); i!=INVALID; ++i)
    1.67      std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")";
    1.68    std::cout << std::endl;
    1.69  \endcode
    1.70 @@ -155,12 +140,12 @@
    1.71    NodeIt first_node(g);
    1.72  
    1.73    std::cout << "Out-edges of node " << g.id(first_node) << ":";
    1.74 -  for (OutEdgeIt i(g, first_node); g.valid(i); g.next(i))
    1.75 +  for (OutEdgeIt i(g, first_node); i!=INVALID; ++i)
    1.76      std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")"; 
    1.77    std::cout << std::endl;
    1.78  
    1.79    std::cout << "In-edges of node " << g.id(first_node) << ":";
    1.80 -  for (InEdgeIt i(g, first_node); g.valid(i); g.next(i))
    1.81 +  for (InEdgeIt i(g, first_node); i!=INVALID; ++i)
    1.82      std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")"; 
    1.83    std::cout << std::endl;
    1.84  \endcode
    1.85 @@ -176,11 +161,11 @@
    1.86  \code
    1.87    Graph::EdgeMap<int> m(g);
    1.88  
    1.89 -  for (EdgeIt e(g); g.valid(e); g.next(e))
    1.90 +  for (EdgeIt e(g); e!=INVALID; ++e)
    1.91      m.set(e, 10 - g.id(e));
    1.92    
    1.93    std::cout << "Id Edge  Value" << std::endl;
    1.94 -  for (EdgeIt e(g); g.valid(e); g.next(e))
    1.95 +  for (EdgeIt e(g); e!=INVALID; ++e)
    1.96      std::cout << g.id(e) << "  (" << g.id(g.tail(e)) << "," << g.id(g.head(e))
    1.97        << ") " << m[e] << std::endl;
    1.98  \endcode