| Chris Lattner | 5de2204 | 2001-11-27 00:03:19 +0000 | [diff] [blame] | 1 | //===-- Support/GraphTraits.h - Graph traits template ------------*- C++ -*--=// | 
| Chris Lattner | 409bbec | 2001-09-28 22:59:14 +0000 | [diff] [blame] | 2 | // | 
|  | 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. | 
|  | 5 | // | 
|  | 6 | // This file also defines the marker class Inverse that is used to iterate over | 
|  | 7 | // graphs in a graph defined, inverse ordering... | 
|  | 8 | // | 
|  | 9 | //===----------------------------------------------------------------------===// | 
|  | 10 |  | 
|  | 11 | #ifndef LLVM_SUPPORT_GRAPH_TRAITS_H | 
|  | 12 | #define LLVM_SUPPORT_GRAPH_TRAITS_H | 
|  | 13 |  | 
|  | 14 | // GraphTraits - This class should be specialized by different graph types... | 
|  | 15 | // which is why the default version is empty. | 
|  | 16 | // | 
|  | 17 | template<class GraphType> | 
|  | 18 | struct GraphTraits { | 
|  | 19 | // Elements to provide: | 
|  | 20 |  | 
|  | 21 | // typedef NodeType          - Type of Node in the graph | 
|  | 22 | // typedef ChildIteratorType - Type used to iterate over children in graph | 
|  | 23 |  | 
|  | 24 | // static NodeType *getEntryNode(GraphType *) | 
|  | 25 | //    Return the entry node of the graph | 
|  | 26 |  | 
|  | 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. | 
|  | 31 | // | 
|  | 32 |  | 
|  | 33 |  | 
|  | 34 | // If anyone tries to use this class without having an appropriate | 
| Chris Lattner | 274aeb7 | 2001-10-01 13:34:22 +0000 | [diff] [blame] | 35 | // specialization, make an error.  If you get this error, it's because you | 
| Chris Lattner | 409bbec | 2001-09-28 22:59:14 +0000 | [diff] [blame] | 36 | // need to include the appropriate specialization of GraphTraits<> for your | 
| Chris Lattner | 274aeb7 | 2001-10-01 13:34:22 +0000 | [diff] [blame] | 37 | // graph, or you need to define it for a new graph type. Either that or | 
|  | 38 | // your argument to XXX_begin(...) is unknown or needs to have the proper .h | 
|  | 39 | // file #include'd. | 
| Chris Lattner | 409bbec | 2001-09-28 22:59:14 +0000 | [diff] [blame] | 40 | // | 
|  | 41 | typedef typename GraphType::UnknownGraphTypeError NodeType; | 
|  | 42 | }; | 
|  | 43 |  | 
|  | 44 |  | 
|  | 45 | // Inverse - This class is used as a little marker class to tell the graph | 
|  | 46 | // iterator to iterate over the graph in a graph defined "Inverse" ordering. | 
|  | 47 | // Not all graphs define an inverse ordering, and if they do, it depends on | 
|  | 48 | // the graph exactly what that is.  Here's an example of usage with the | 
|  | 49 | // df_iterator: | 
|  | 50 | // | 
| Chris Lattner | 274aeb7 | 2001-10-01 13:34:22 +0000 | [diff] [blame] | 51 | // idf_iterator<Method*> I = idf_begin(M), E = idf_end(M); | 
|  | 52 | // for (; I != E; ++I) { ... } | 
|  | 53 | // | 
|  | 54 | // Which is equivalent to: | 
|  | 55 | // df_iterator<Inverse<Method*> > I = idf_begin(M), E = idf_end(M); | 
| Chris Lattner | 409bbec | 2001-09-28 22:59:14 +0000 | [diff] [blame] | 56 | // for (; I != E; ++I) { ... } | 
|  | 57 | // | 
|  | 58 | template <class GraphType> | 
|  | 59 | struct Inverse { | 
|  | 60 | GraphType &Graph; | 
|  | 61 |  | 
|  | 62 | inline Inverse(GraphType &G) : Graph(G) {} | 
|  | 63 | }; | 
|  | 64 |  | 
|  | 65 | #endif |