4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Dekel Tsur (original code)
8 * \author Richard Heck (re-implementation)
10 * Full author contact details are available in file CREDITS.
25 /// Represents a directed graph, possibly with multiple edges
26 /// connecting the vertices.
29 Graph() : numedges_(0) {}
31 typedef std::vector<int> EdgePath;
32 /// \return a vector of the vertices from which "to" can be reached
33 EdgePath const getReachableTo(int to, bool clear_visited);
34 /// \return a vector of the vertices that can be reached from "from"
36 getReachable(int from, bool only_viewable, bool clear_visited);
37 /// can "from" be reached from "to"?
38 bool isReachable(int from, int to);
39 /// find a path from "from" to "to". always returns one of the
40 /// shortest such paths.
41 EdgePath const getPath(int from, int to);
42 /// called repeatedly to build the graph
43 void addEdge(int from, int to);
44 /// reset the internal data structures
49 bool bfs_init(int, bool clear_visited, std::queue<int> & Q);
50 /// these represent the arrows connecting the nodes of the graph.
51 /// this is the basic representation of the graph: as a bunch of
55 Arrow(int f, int t, int i):
56 from(f), to(t), id(i) {}
57 /// the vertex at the tail of the arrow
59 /// the vertex at the head
61 /// an id for this arrow, e.g., for use in describing paths
65 /// a container for the arrows
66 /// we use a list because we want pointers to the arrows,
67 /// and a vector might invalidate them
68 typedef std::list<Arrow> Arrows;
70 /// Represents a vertex of the graph. Note that we could recover
71 /// the in_arrows and out_arrows from the Arrows, so these are in
72 /// effect a kind of cache.
74 /// arrows that point at this one
75 std::vector<Arrow *> in_arrows;
76 /// arrows out from here
77 std::vector<Arrow *> out_arrows;
78 /// used in the search routines
81 /// a container for the vertices
82 /// the index into the vector functions as the identifier by which
83 /// these are referenced in the Arrow struct
84 /// the code making use of the Graph must keep track of the relation
85 /// between these indices and the objects they represent. (in the case
86 /// of Format, this is easy, since the Format objects already have ints
88 std::vector<Vertex> vertices_;
90 /// a counter that we use to assign id's to the arrows
91 /// FIXME This technique assumes a correspondence between the
92 /// ids of the arrows and ids associated with Converters that
93 /// seems kind of fragile. Perhaps a better solution would be
94 /// to pass the ids as we create the arrows.