3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
22 int Graph::bfs_init(int s, bool clear_visited)
27 Q_ = std::queue<int>();
30 fill(visited_.begin(), visited_.end(), false);
31 if (visited_[s] == false) {
40 Graph::getReachableTo(int target, bool clear_visited)
43 int const s = bfs_init(target, clear_visited);
48 int const i = Q_.front();
50 if (i != s || formats.get(target).name() != "lyx") {
54 vector<int>::iterator it = vertices_[i].in_vertices.begin();
55 vector<int>::iterator end = vertices_[i].in_vertices.end();
56 for (; it != end; ++it) {
69 Graph::getReachable(int from, bool only_viewable,
73 if (bfs_init(from, clear_visited) < 0)
77 int const i = Q_.front();
79 Format const & format = formats.get(i);
80 if (!only_viewable || !format.viewer().empty())
82 else if (format.isChildFormat()) {
83 Format const * const parent =
84 formats.getFormat(format.parentFormat());
85 if (parent && !parent->viewer().empty())
89 vector<int>::const_iterator cit =
90 vertices_[i].out_vertices.begin();
91 vector<int>::const_iterator end =
92 vertices_[i].out_vertices.end();
93 for (; cit != end; ++cit)
94 if (!visited_[*cit]) {
95 visited_[*cit] = true;
104 bool Graph::isReachable(int from, int to)
109 int const s = bfs_init(from);
113 while (!Q_.empty()) {
114 int const i = Q_.front();
119 vector<int>::const_iterator cit =
120 vertices_[i].out_vertices.begin();
121 vector<int>::const_iterator end =
122 vertices_[i].out_vertices.end();
123 for (; cit != end; ++cit) {
124 if (!visited_[*cit]) {
125 visited_[*cit] = true;
135 Graph::EdgePath const
136 Graph::getPath(int from, int t)
142 int const s = bfs_init(from);
146 vector<int> prev_edge(formats.size());
147 vector<int> prev_vertex(formats.size());
150 while (!Q_.empty()) {
151 int const i = Q_.front();
158 vector<int>::const_iterator beg =
159 vertices_[i].out_vertices.begin();
160 vector<int>::const_iterator cit = beg;
161 vector<int>::const_iterator end =
162 vertices_[i].out_vertices.end();
163 for (; cit != end; ++cit)
164 if (!visited_[*cit]) {
168 int const k = cit - beg;
169 prev_edge[j] = vertices_[i].out_edges[k];
177 path.push_back(prev_edge[t]);
180 reverse(path.begin(), path.end());
184 void Graph::init(int size)
186 vertices_ = vector<Vertex>(size);
187 visited_.resize(size);
191 void Graph::addEdge(int s, int t)
193 vertices_[t].in_vertices.push_back(s);
194 vertices_[s].out_vertices.push_back(t);
195 vertices_[s].out_edges.push_back(numedges_++);
198 vector<Graph::Vertex> Graph::vertices_;