Added LLVM notice.
[oota-llvm.git] / include / llvm / ADT / GraphTraits.h
1 //===-- Support/GraphTraits.h - Graph traits template -----------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the little GraphTraits<X> template class that should be 
11 // specialized by classes that want to be iteratable by generic graph iterators.
12 //
13 // This file also defines the marker class Inverse that is used to iterate over
14 // graphs in a graph defined, inverse ordering...
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef SUPPORT_GRAPHTRAITS_H
19 #define SUPPORT_GRAPHTRAITS_H
20
21 // GraphTraits - This class should be specialized by different graph types...
22 // which is why the default version is empty.
23 //
24 template<class GraphType>
25 struct GraphTraits {
26   // Elements to provide:
27
28   // typedef NodeType          - Type of Node in the graph
29   // typedef ChildIteratorType - Type used to iterate over children in graph
30
31   // static NodeType *getEntryNode(GraphType *)
32   //    Return the entry node of the graph
33
34   // static ChildIteratorType child_begin(NodeType *)
35   // static ChildIteratorType child_end  (NodeType *)
36   //    Return iterators that point to the beginning and ending of the child 
37   //    node list for the specified node.
38   //  
39
40
41   // typedef  ...iterator nodes_iterator;
42   // static nodes_iterator nodes_begin(GraphType *G)
43   // static nodes_iterator nodes_end  (GraphType *G)
44   //
45   //    nodes_iterator/begin/end - Allow iteration over all nodes in the graph
46
47
48   // If anyone tries to use this class without having an appropriate
49   // specialization, make an error.  If you get this error, it's because you
50   // need to include the appropriate specialization of GraphTraits<> for your
51   // graph, or you need to define it for a new graph type. Either that or 
52   // your argument to XXX_begin(...) is unknown or needs to have the proper .h
53   // file #include'd.
54   //
55   typedef typename GraphType::UnknownGraphTypeError NodeType;
56 };
57
58
59 // Inverse - This class is used as a little marker class to tell the graph
60 // iterator to iterate over the graph in a graph defined "Inverse" ordering.
61 // Not all graphs define an inverse ordering, and if they do, it depends on
62 // the graph exactly what that is.  Here's an example of usage with the
63 // df_iterator:
64 //
65 // idf_iterator<Method*> I = idf_begin(M), E = idf_end(M);
66 // for (; I != E; ++I) { ... }
67 //
68 // Which is equivalent to:
69 // df_iterator<Inverse<Method*> > I = idf_begin(M), E = idf_end(M);
70 // for (; I != E; ++I) { ... }
71 //
72 template <class GraphType>
73 struct Inverse {
74   GraphType &Graph;
75
76   inline Inverse(GraphType &G) : Graph(G) {}
77 };
78
79 #endif