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 bool 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 if (!bfs_init(target
, clear_visited
))
48 int const current
= Q_
.front();
50 if (current
!= target
|| formats
.get(target
).name() != "lyx")
51 result
.push_back(current
);
53 vector
<int>::iterator it
= vertices_
[current
].in_vertices
.begin();
54 vector
<int>::iterator end
= vertices_
[current
].in_vertices
.end();
55 for (; it
!= end
; ++it
) {
68 Graph::getReachable(int from
, bool only_viewable
,
72 if (!bfs_init(from
, clear_visited
))
76 int const current
= Q_
.front();
78 Format
const & format
= formats
.get(current
);
79 if (!only_viewable
|| !format
.viewer().empty())
80 result
.push_back(current
);
81 else if (format
.isChildFormat()) {
82 Format
const * const parent
=
83 formats
.getFormat(format
.parentFormat());
84 if (parent
&& !parent
->viewer().empty())
85 result
.push_back(current
);
88 vector
<OutEdge
>::const_iterator cit
=
89 vertices_
[current
].out_arrows
.begin();
90 vector
<OutEdge
>::const_iterator end
=
91 vertices_
[current
].out_arrows
.end();
92 for (; cit
!= end
; ++cit
) {
93 int const cv
= cit
->vertex
;
105 bool Graph::isReachable(int from
, int to
)
110 if (to
< 0 || !bfs_init(from
))
113 while (!Q_
.empty()) {
114 int const current
= Q_
.front();
119 vector
<OutEdge
>::const_iterator cit
=
120 vertices_
[current
].out_arrows
.begin();
121 vector
<OutEdge
>::const_iterator end
=
122 vertices_
[current
].out_arrows
.end();
123 for (; cit
!= end
; ++cit
) {
124 int const cv
= cit
->vertex
;
136 Graph::EdgePath
const Graph::getPath(int from
, int to
)
142 if (to
< 0 || !bfs_init(from
))
145 vector
<int> prev_edge(formats
.size());
146 vector
<int> prev_vertex(formats
.size());
149 while (!Q_
.empty()) {
150 int const current
= Q_
.front();
157 vector
<OutEdge
>::const_iterator
const beg
=
158 vertices_
[current
].out_arrows
.begin();
159 vector
<OutEdge
>::const_iterator cit
= beg
;
160 vector
<OutEdge
>::const_iterator end
=
161 vertices_
[current
].out_arrows
.end();
162 for (; cit
!= end
; ++cit
) {
163 int const cv
= cit
->vertex
;
167 prev_edge
[cv
] = cit
->edge
;
168 prev_vertex
[cv
] = current
;
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_arrows
.push_back(OutEdge(to
, numedges_
++));
199 vector
<Graph::Vertex
> Graph::vertices_
;