From 1a0852630af07b5a5d71eae6f03b385b6f4431ee Mon Sep 17 00:00:00 2001 From: Julien Rioux Date: Wed, 30 Mar 2011 22:24:30 +0000 Subject: [PATCH] optionally allow to exclude certain formats, by name, from the converter graph git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38166 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Converter.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/Converter.h | 6 ++++++ src/Graph.cpp | 24 ++++++++++++++++++++++-- src/Graph.h | 6 ++++++ 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/Converter.cpp b/src/Converter.cpp index f208b7415f..2b83b3d479 100644 --- a/src/Converter.cpp +++ b/src/Converter.cpp @@ -695,6 +695,43 @@ Converters::getReachable(string const & from, bool const only_viewable, } +vector const +Converters::getReachable(string const & from, bool const only_viewable, + bool const clear_visited, string const & exclude) +{ + vector const & reachables = + G_.getReachable(formats.getNumber(from), + only_viewable, + clear_visited, + formats.getNumber(exclude)); + + return intToFormat(reachables); +} + + +vector const +Converters::getReachable(string const & from, bool const only_viewable, + bool const clear_visited, vector const & excludes) +{ + vector excluded_numbers(excludes.size()); + + vector::const_iterator sit = excludes.begin(); + vector::const_iterator const end = excludes.end(); + vector::iterator it = excluded_numbers.begin(); + for ( ; sit != end; ++sit, ++it) { + *it = formats.getNumber(*sit); + } + + vector const & reachables = + G_.getReachable(formats.getNumber(from), + only_viewable, + clear_visited, + excluded_numbers); + + return intToFormat(reachables); +} + + bool Converters::isReachable(string const & from, string const & to) { return G_.isReachable(formats.getNumber(from), diff --git a/src/Converter.h b/src/Converter.h index 2b59541563..ed22406f10 100644 --- a/src/Converter.h +++ b/src/Converter.h @@ -98,6 +98,12 @@ public: std::vector const getReachable(std::string const & from, bool only_viewable, bool clear_visited); + std::vector const + getReachable(std::string const & from, bool only_viewable, + bool clear_visited, std::string const & exclude); + std::vector const + getReachable(std::string const & from, bool only_viewable, + bool clear_visited, std::vector const & excludes); std::vector importableFormats(); std::vector exportableFormats(bool only_viewable); diff --git a/src/Graph.cpp b/src/Graph.cpp index d7ea066dc3..c80f42caf6 100644 --- a/src/Graph.cpp +++ b/src/Graph.cpp @@ -83,7 +83,7 @@ Graph::EdgePath const Graph::EdgePath const Graph::getReachable(int from, bool only_viewable, - bool clear_visited) + bool clear_visited, vector excludes) { EdgePath result; queue Q; @@ -111,7 +111,8 @@ Graph::EdgePath const int const cv = (*cit)->to; if (!vertices_[cv].visited) { vertices_[cv].visited = true; - Q.push(cv); + if (find(excludes.begin(), excludes.end(), cv) == excludes.end()) + Q.push(cv); } } } @@ -120,6 +121,25 @@ Graph::EdgePath const } +Graph::EdgePath const + Graph::getReachable(int from, bool only_viewable, + bool clear_visited, int exclude) +{ + vector excludes; + excludes.push_back(exclude); + return getReachable(from, only_viewable, clear_visited, excludes); +} + + +Graph::EdgePath const + Graph::getReachable(int from, bool only_viewable, + bool clear_visited) +{ + vector excludes; + return getReachable(from, only_viewable, clear_visited, excludes); +} + + bool Graph::isReachable(int from, int to) { if (from == to) diff --git a/src/Graph.h b/src/Graph.h index 239cbcb90a..cd0110264c 100644 --- a/src/Graph.h +++ b/src/Graph.h @@ -34,6 +34,12 @@ public: /// \return a vector of the vertices that can be reached from "from" EdgePath const getReachable(int from, bool only_viewable, bool clear_visited); + /// \return a vector of the reachable vertices, avoiding "exclude" + EdgePath const getReachable(int from, bool only_viewable, + bool clear_visited, int exclude); + /// \return a vector of the reachable vertices, avoiding all "excludes" + EdgePath const getReachable(int from, bool only_viewable, + bool clear_visited, std::vector excludes); /// can "from" be reached from "to"? bool isReachable(int from, int to); /// find a path from "from" to "to". always returns one of the