1 //===-- Support/GraphTraits.h - Graph traits template ------------*- C++ -*--=//
3 // This file defines the little GraphTraits<X> template class that should be
4 // specialized by classes that want to be iteratable by generic graph iterators.
6 // This file also defines the marker class Inverse that is used to iterate over
7 // graphs in a graph defined, inverse ordering...
9 //===----------------------------------------------------------------------===//
11 #ifndef SUPPORT_GRAPHTRAITS_H
12 #define SUPPORT_GRAPHTRAITS_H
14 // GraphTraits - This class should be specialized by different graph types...
15 // which is why the default version is empty.
17 template<class GraphType>
19 // Elements to provide:
21 // typedef NodeType - Type of Node in the graph
22 // typedef ChildIteratorType - Type used to iterate over children in graph
24 // static NodeType *getEntryNode(GraphType *)
25 // Return the entry node of the graph
27 // static ChildIteratorType child_begin(NodeType *)
28 // static ChildIteratorType child_end (NodeType *)
29 // Return iterators that point to the beginning and ending of the child
30 // node list for the specified node.
34 // typedef ...iterator nodes_iterator;
35 // static nodes_iterator nodes_begin(GraphType *G)
36 // static nodes_iterator nodes_end (GraphType *G)
38 // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
41 // If anyone tries to use this class without having an appropriate
42 // specialization, make an error. If you get this error, it's because you
43 // need to include the appropriate specialization of GraphTraits<> for your
44 // graph, or you need to define it for a new graph type. Either that or
45 // your argument to XXX_begin(...) is unknown or needs to have the proper .h
48 typedef typename GraphType::UnknownGraphTypeError NodeType;
52 // Inverse - This class is used as a little marker class to tell the graph
53 // iterator to iterate over the graph in a graph defined "Inverse" ordering.
54 // Not all graphs define an inverse ordering, and if they do, it depends on
55 // the graph exactly what that is. Here's an example of usage with the
58 // idf_iterator<Method*> I = idf_begin(M), E = idf_end(M);
59 // for (; I != E; ++I) { ... }
61 // Which is equivalent to:
62 // df_iterator<Inverse<Method*> > I = idf_begin(M), E = idf_end(M);
63 // for (; I != E; ++I) { ... }
65 template <class GraphType>
69 inline Inverse(GraphType &G) : Graph(G) {}