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.
23 int Graph::bfs_init(int s, bool clear_visited)
31 fill(visited_.begin(), visited_.end(), false);
32 if (visited_[s] == false) {
41 Graph::getReachableTo(int target, bool clear_visited)
44 int const s = bfs_init(target, clear_visited);
49 int const i = Q_.front();
51 if (i != s || formats.get(target).name() != "lyx") {
55 vector<int>::iterator it = vertices_[i].in_vertices.begin();
56 vector<int>::iterator end = vertices_[i].in_vertices.end();
57 for (; it != end; ++it) {
70 Graph::getReachable(int from, bool only_viewable,
74 if (bfs_init(from, clear_visited) < 0)
78 int const i = Q_.front();
80 Format const & format = formats.get(i);
81 if (!only_viewable || !format.viewer().empty())
83 else if (format.isChildFormat()) {
84 Format const * const parent =
85 formats.getFormat(format.parentFormat());
86 if (parent && !parent->viewer().empty())
90 vector<int>::const_iterator cit =
91 vertices_[i].out_vertices.begin();
92 vector<int>::const_iterator end =
93 vertices_[i].out_vertices.end();
94 for (; cit != end; ++cit)
95 if (!visited_[*cit]) {
96 visited_[*cit] = true;
105 bool Graph::isReachable(int from, int to)
110 if (to < 0 || bfs_init(from) < 0)
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 Graph::getPath(int from, int to)
141 int const s = bfs_init(from);
145 vector<int> prev_edge(formats.size());
146 vector<int> prev_vertex(formats.size());
149 while (!Q_.empty()) {
150 int const i = Q_.front();
157 vector<int>::const_iterator const beg =
158 vertices_[i].out_vertices.begin();
159 vector<int>::const_iterator cit = beg;
160 vector<int>::const_iterator end =
161 vertices_[i].out_vertices.end();
162 for (; cit != end; ++cit)
163 if (!visited_[*cit]) {
167 int const k = cit - beg;
168 prev_edge[j] = vertices_[i].out_edges[k];
176 path.push_back(prev_edge[to]);
177 to = prev_vertex[to];
179 reverse(path.begin(), path.end());
184 void Graph::init(int size)
186 vertices_ = vector<Vertex>(size);
187 visited_.resize(size);
192 void Graph::addEdge(int from, int to)
194 vertices_[to].in_vertices.push_back(from);
195 vertices_[from].out_vertices.push_back(to);
196 vertices_[from].out_edges.push_back(numedges_++);
200 vector<Graph::Vertex> Graph::vertices_;