]> git.lyx.org Git - features.git/commitdiff
Just some style, and some comments, as I try to figure this out.
authorRichard Heck <rgheck@comcast.net>
Mon, 9 Nov 2009 00:55:37 +0000 (00:55 +0000)
committerRichard Heck <rgheck@comcast.net>
Mon, 9 Nov 2009 00:55:37 +0000 (00:55 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31910 a592a061-630c-0410-9148-cb99ea01b6c8

src/Converter.cpp
src/Graph.cpp
src/Graph.h

index 9a849a4017ea19a48873ea609c04b7df9b4dcdb7..86ad195cbad622f274986c1a8c1a1eae682ace90 100644 (file)
@@ -635,13 +635,17 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command,
 
 void Converters::buildGraph()
 {
+       // clear graph's data structures
        G_.init(formats.size());
        ConverterList::iterator beg = converterlist_.begin();
        ConverterList::iterator const end = converterlist_.end();
+       // each of the converters knows how to convert one format to another
+       // so, for each of them, we create an arrow on the graph, going from 
+       // the one to the other
        for (ConverterList::iterator it = beg; it != end ; ++it) {
-               int const s = formats.getNumber(it->from);
-               int const t = formats.getNumber(it->to);
-               G_.addEdge(s,t);
+               int const from = formats.getNumber(it->from);
+               int const to   = formats.getNumber(it->to);
+               G_.addEdge(from, to);
        }
 }
 
index 379ec2966cbea5e066cc4695a9a21fb65330ed80..81883ae31e471e2781b21c7a41fed236425c2e1e 100644 (file)
@@ -107,8 +107,7 @@ bool Graph::isReachable(int from, int to)
        if (from == to)
                return true;
 
-       int const s = bfs_init(from);
-       if (s < 0 || to < 0)
+       if (to < 0 || bfs_init(from) < 0)
                return false;
 
        while (!Q_.empty()) {
@@ -133,15 +132,14 @@ bool Graph::isReachable(int from, int to)
 }
 
 
-Graph::EdgePath const
-Graph::getPath(int from, int t)
+Graph::EdgePath const Graph::getPath(int from, int to)
 {
        EdgePath path;
-       if (from == t)
+       if (from == to)
                return path;
 
        int const s = bfs_init(from);
-       if (s < 0 || t < 0)
+       if (s < 0 || to < 0)
                return path;
 
        vector<int> prev_edge(formats.size());
@@ -151,7 +149,7 @@ Graph::getPath(int from, int t)
        while (!Q_.empty()) {
                int const i = Q_.front();
                Q_.pop();
-               if (i == t) {
+               if (i == to) {
                        found = true;
                        break;
                }
@@ -174,14 +172,15 @@ Graph::getPath(int from, int t)
        if (!found)
                return path;
 
-       while (t != s) {
-               path.push_back(prev_edge[t]);
-               t = prev_vertex[t];
+       while (to != s) {
+               path.push_back(prev_edge[to]);
+               to = prev_vertex[to];
        }
        reverse(path.begin(), path.end());
        return path;
 }
 
+
 void Graph::init(int size)
 {
        vertices_ = vector<Vertex>(size);
@@ -189,13 +188,15 @@ void Graph::init(int size)
        numedges_ = 0;
 }
 
-void Graph::addEdge(int s, int t)
+
+void Graph::addEdge(int from, int to)
 {
-       vertices_[t].in_vertices.push_back(s);
-       vertices_[s].out_vertices.push_back(t);
-       vertices_[s].out_edges.push_back(numedges_++);
+       vertices_[to].in_vertices.push_back(from);
+       vertices_[from].out_vertices.push_back(to);
+       vertices_[from].out_edges.push_back(numedges_++);
 }
 
+
 vector<Graph::Vertex> Graph::vertices_;
 
 
index f2296b85a97b56d7c3f8cefa4017ea3c11cac415..3955c3e60c154c886de4be7affdcb0a1d00759f1 100644 (file)
@@ -24,20 +24,18 @@ public:
        Graph() : numedges_(0) {};
        ///
        typedef std::vector<int> EdgePath;
-       ///
-       std::vector<int> const
-       getReachableTo(int, bool clear_visited);
-       ///
+       /// \return a vector of the vertices from which "to" can be reached
+       std::vector<int> const getReachableTo(int to, bool clear_visited);
+       /// \return a vector of the vertices that can be reached from "from"
        std::vector<int> const
-       getReachable(int, bool only_viewable,
-                    bool clear_visited);
-       ///
-       bool isReachable(int, int);
-       ///
-       EdgePath const getPath(int, int);
-       ///
-       void addEdge(int s, int t);
-       ///
+               getReachable(int from, bool only_viewable, bool clear_visited);
+       /// Can "from" be reached from "to"?
+       bool isReachable(int from, int to);
+       /// Find a path from "from" to "to".
+       EdgePath const getPath(int from, int to);
+       /// Called repeatedly to build the graph.
+       void addEdge(int from, int to);
+       /// Reset the internal data structures.
        void init(int size);
 
 private:
@@ -52,8 +50,7 @@ private:
                std::vector<int> out_edges;
        };
        ///
-       static
-       std::vector<Vertex> vertices_;
+       static std::vector<Vertex> vertices_;
        ///
        std::vector<bool> visited_;
        ///