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 reachable vertices, avoiding "exclude"
35 EdgePath const getReachable(int from, bool only_viewable,
36 bool clear_visited, int exclude);
37 /// \return a vector of the reachable vertices, avoiding all "excludes"
38 EdgePath const getReachable(int from, bool only_viewable,
39 bool clear_visited, std::vector<int> excludes);
40 /// can "from" be reached from "to"?
41 bool isReachable(int from, int to);
42 /// find a path from "from" to "to". always returns one of the
43 /// shortest such paths.
44 EdgePath const getPath(int from, int to);
45 /// called repeatedly to build the graph
46 void addEdge(int from, int to);
47 /// reset the internal data structures
52 bool bfs_init(int, bool clear_visited, std::queue<int> & Q);
53 /// these represent the arrows connecting the nodes of the graph.
54 /// this is the basic representation of the graph: as a bunch of
58 Arrow(int f, int t, int i):
59 from(f), to(t), id(i) {}
60 /// the vertex at the tail of the arrow
62 /// the vertex at the head
64 /// an id for this arrow, e.g., for use in describing paths
68 /// a container for the arrows
69 /// we use a list because we want pointers to the arrows,
70 /// and a vector might invalidate them
71 typedef std::list<Arrow> Arrows;
73 /// Represents a vertex of the graph. Note that we could recover
74 /// the in_arrows and out_arrows from the Arrows, so these are in
75 /// effect a kind of cache.
77 /// arrows that point at this one
78 std::vector<Arrow *> in_arrows;
79 /// arrows out from here
80 std::vector<Arrow *> out_arrows;
81 /// used in the search routines
84 /// a container for the vertices
85 /// the index into the vector functions as the identifier by which
86 /// these are referenced in the Arrow struct
87 /// the code making use of the Graph must keep track of the relation
88 /// between these indices and the objects they represent. (in the case
89 /// of Format, this is easy, since the Format objects already have ints
91 std::vector<Vertex> vertices_;
93 /// a counter that we use to assign id's to the arrows
94 /// FIXME This technique assumes a correspondence between the
95 /// ids of the arrows and ids associated with Converters that
96 /// seems kind of fragile. Perhaps a better solution would be
97 /// to pass the ids as we create the arrows.