Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79822 - in sandbox/icl/libs/xplore/br1/sqlbrowser: . Dag
From: afojgo_at_[hidden]
Date: 2012-07-31 12:26:25


Author: jofaber
Date: 2012-07-31 12:26:25 EDT (Tue, 31 Jul 2012)
New Revision: 79822
URL: http://svn.boost.org/trac/boost/changeset/79822

Log:
Adapting visitor for dag representation.
Binary files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/objects1.db
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h | 143 ++++++++++++++++++++++++++++++++++++++++
   sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbBasedGraph.h | 7 +
   sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor2.h | 55 ++++++++++++++
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 6 +
   4 files changed, 205 insertions(+), 6 deletions(-)

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h 2012-07-31 12:26:25 EDT (Tue, 31 Jul 2012)
@@ -155,3 +155,146 @@
 
 }; // CreatorVisitor
 
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+struct CreatorVisitor2
+{
+ //--------------------------------------------------------------------------
+ // Visitors
+ struct OnDiscoverVertex : public boost::base_visitor<OnDiscoverVertex>
+ {
+ OnDiscoverVertex(DagItem* curItem, QString* result, Dag::tAttributesMap& attrs)
+ : p_curItem(curItem), p_result(result), r_attrs(attrs)
+ {
+ r_attrs[0].setDagItem(p_curItem); //Root node
+ r_attrs[0].setParentItem(0); //Root node
+ }
+
+ typedef boost::on_discover_vertex event_filter;
+
+ template<class Vertex, class Graph>
+ void operator()(Vertex node, Graph& dag)
+ {
+ // "Visitation by descent". All nodes are reached through this function on
+ // descend, which is always done first for "depth first search. Therefore
+ // we can create all nodes for the Qt DagModel in this functor:
+ //
+ // Create a DagItem. The node that has been visited last should be the parent.
+ // While we are descending, we build a chain going "down".
+
+ tVariVector itemData(dag::node::sizeOf_node); // ItemData node(id, name, ..)
+ // will only by a part of the data from sql that represented
+ // edges. Via r_attrs we only obtain associated node data
+ // from the boost::graph
+ dag::copyBoostNode2DagItem(r_attrs[node], itemData);
+
+ // Discoverage is always on the way down. So we should maintain the invariant
+ // p_curItem should be initialized to the DagModel's DatItem* rootItem
+
+ if(boost::out_degree(node, dag) > 0)
+ {
+ *p_result += indentation(r_attrs[node].depth()) + "(";
+ *p_result += r_attrs[node].name();
+ *p_result += QString(" d:%1").arg(r_attrs[node].depth());
+ *p_result += " -> " + (p_curItem==0 ? QString("{}") : p_curItem->data()[dag::node::posName].toString());
+ *p_result += "\n";
+ }
+ }
+
+ //CL Example for iterating over edges.
+ template<class Vertex, class Graph>
+ int edge_count(Vertex node, Graph& dag)
+ {
+ typedef graph_traits<Graph> GraphTraits;
+ typename GraphTraits::out_edge_iterator out_i, out_end;
+ typename GraphTraits::edge_descriptor ed;
+
+ int edge_cnt = 0;
+ for(boost::tie(out_i, out_end) = boost::out_edges(node, dag); out_i != out_end; ++out_i)
+ ++edge_cnt;
+
+ return edge_cnt;
+ }
+
+ DagItem* p_curItem;
+ QString* p_result;
+ Dag::tAttributesMap& r_attrs;
+ };
+
+ struct OnExamineEdge : public boost::base_visitor<OnExamineEdge>
+ {
+ OnExamineEdge(DagItem* curItem, QString* result, Dag::tAttributesMap& names)
+ : p_curItem(curItem), p_result(result), r_attrs(names)
+ {
+ //CL r_attrs[0].setDagItem(p_curItem); //Root node
+ }
+
+ typedef boost::on_examine_edge event_filter;
+
+ template<class Edge, class Graph>
+ void operator()(Edge edge, Graph& dag)
+ {
+ Dag::vertex_descriptor source_node = source(edge, dag);
+ Dag::vertex_descriptor target_node = target(edge, dag);
+ int source_depth = r_attrs[source_node].depth();
+ int target_depth = source_depth + 1;
+ r_attrs[target_node].setDepth(target_depth);
+ DagItem* sourceDagItem = r_attrs[source_node].dagItem();
+ DagItem* targetDagItem = r_attrs[target_node].dagItem();
+
+ Q_ASSERT(sourceDagItem);
+
+ if(p_curItem != sourceDagItem)
+ p_curItem = sourceDagItem;
+
+ if(targetDagItem)
+ sourceDagItem->addChild(targetDagItem);
+ else
+ {
+ tVariVector itemData(dag::node::sizeOf_node);
+ dag::copyBoostNode2DagItem(r_attrs[target_node], itemData);
+ DagItem* newDagItem = new DagItem(itemData, p_curItem);
+ sourceDagItem->addChild(newDagItem);
+ r_attrs[target_node].setDagItem(newDagItem);
+ newDagItem->setData(dag::node::posParentId, newDagItem->parent()->data(dag::node::posId));
+ newDagItem->setData(dag::node::posParentName, newDagItem->parent()->data(dag::node::posName));
+ }
+
+ if(boost::out_degree(target(edge, dag), dag)==0)
+ {
+ *p_result += indentation(target_depth) + r_attrs[target(edge, dag)].name() + " ?";
+ *p_result += "\n";
+ }
+ }
+
+ DagItem* p_curItem;
+ QString* p_result;
+ Dag::tAttributesMap& r_attrs;
+ };
+
+ struct OnFinishVertex : public boost::base_visitor<OnFinishVertex>
+ {
+ OnFinishVertex(DagItem* curItem, QString* result, Dag::tAttributesMap& names)
+ : p_curItem(curItem), p_result(result), r_attrs(names)
+ {
+ }
+
+ typedef boost::on_finish_vertex event_filter;
+
+ template<class Vertex, class Graph>
+ void operator()(Vertex node, Graph& dag)
+ {
+ if(boost::out_degree(node, dag) > 0)
+ {
+ *p_result += indentation(r_attrs[node].depth()) + ")";
+ *p_result += "\n";
+ }
+ }
+
+ DagItem* p_curItem;
+ QString* p_result;
+ Dag::tAttributesMap& r_attrs;
+ };
+
+}; // CreatorVisitor2
+

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbBasedGraph.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbBasedGraph.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/Dag/DbBasedGraph.h 2012-07-31 12:26:25 EDT (Tue, 31 Jul 2012)
@@ -108,9 +108,10 @@
         boost::depth_first_search(
             m_aGraph
           , boost::visitor(make_dfs_visitor(boost::make_list(
- StringVisitor2<DbBasedGraph>::OnDiscoverVertex(&tygraAsString, vertexDepth)
- , StringVisitor2<DbBasedGraph>::OnExamineEdge (&tygraAsString, vertexDepth)
- , StringVisitor2<DbBasedGraph>::OnFinishVertex (&tygraAsString, vertexDepth)
+ StringVisitor2<DbBasedGraph>::OnDiscoverVertex (&tygraAsString, vertexDepth)
+ , StringVisitor2<DbBasedGraph>::OnExamineEdge (&tygraAsString, vertexDepth)
+ , StringVisitor2<DbBasedGraph>::OnForwardOrCrossEdge(&tygraAsString, vertexDepth)
+ , StringVisitor2<DbBasedGraph>::OnFinishVertex (&tygraAsString, vertexDepth)
                                                 )
                           ))
         );

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor2.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor2.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor2.h 2012-07-31 12:26:25 EDT (Tue, 31 Jul 2012)
@@ -35,7 +35,8 @@
             if(boost::out_degree(node, graph) > 0) //MEMO out_degree(node, graph) == outgoing node count
             { //MEMO in_degree(node, graph) == ingoing node count | only for BiDiectionalGraph
                 *p_result += indentation(depth(node))
- + "(" + QString("%1 ").arg(boost::out_degree(node, graph));
+ + "(" + QString("*%1 ").arg(boost::out_degree(node, graph))
+ + QString("%1 ").arg(graph[node].key());
                 *p_result += graph[node].name();
                 *p_result += "\n";
             }
@@ -76,10 +77,56 @@
 
             if(boost::out_degree(target(edge, graph), graph)==0)
             {
- *p_result += indentation(target_depth) + "(0 " + graph[target(edge, graph)].name() + ")"
- + graph[edge].typeName();
+ *p_result += indentation(target_depth)
+ + QString("<%1>").arg(graph[edge].typeName())
+ + QString("(%1 %2)").arg(graph[target(edge, graph)].key())
+ .arg(graph[target(edge, graph)].name())
+ ;
                 *p_result += "\n";
             }
+ else
+ {
+ *p_result += indentation(target_depth)
+ + "<" + graph[edge].typeName() + ">\n";
+ }
+ }
+
+ template<class Vertex>
+ int depth(Vertex& node)
+ {
+ tVertex2Depth::iterator node_ = r_vertexDepth.find(node);
+ return node_ == r_vertexDepth.end() ? 0 : (*node_).second;
+ }
+
+ QString* p_result;
+ tVertex2Depth& r_vertexDepth;
+ };
+
+ struct OnForwardOrCrossEdge : public boost::base_visitor<OnForwardOrCrossEdge>
+ {
+ OnForwardOrCrossEdge(QString* result, tVertex2Depth& vertexDepth)
+ : p_result(result), r_vertexDepth(vertexDepth){}
+
+ typedef boost::on_forward_or_cross_edge event_filter;
+
+ template<class Edge, class Graph>
+ void operator()(Edge edge, Graph& graph)
+ {
+ //int source_depth = graph[source(edge, graph)].depth();
+ vertex_descriptor sourceVertex = source(edge, graph);
+ vertex_descriptor targetVertex = target(edge, graph);
+ tVertex2Depth::iterator sourceVertex_ = r_vertexDepth.find(sourceVertex);
+ int source_depth = sourceVertex_ == r_vertexDepth.end() ? 0 : (*sourceVertex_).second ;
+
+ //CL int source_depth = vertexDepth[source(edge, graph)];
+ int target_depth = source_depth + 1;
+
+ *p_result += indentation(target_depth)
+ + QString("[%1<%2>%3]\n").arg(graph[sourceVertex].key())
+ .arg(graph[edge].typeName())
+ .arg(graph[targetVertex].key());
+ // When contructing a QTreeModel I have to copy the node associated to
+ // graph[targetVertex] (e.g. graph[targetVertex].QtModel
         }
 
         template<class Vertex>
@@ -93,6 +140,7 @@
         tVertex2Depth& r_vertexDepth;
     };
 
+
     struct OnFinishVertex : public boost::base_visitor<OnFinishVertex>
     {
         OnFinishVertex(QString* result, tVertex2Depth& vertexDepth)
@@ -121,6 +169,7 @@
         tVertex2Depth& r_vertexDepth;
     };
 
+
     template<class Vertex, class Graph>
     void initialize_vertex(Vertex& node, Graph& gra)
     {

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp 2012-07-31 12:26:25 EDT (Tue, 31 Jul 2012)
@@ -249,6 +249,12 @@
     util::launchMsgBox(ogra.toString());
     util::launchMsgBox(ogra.depthFirstString());
 
+ //--------------------------------------------------------------------------
+ DagModel* dagmo = new DagModel(); // Dag-Model
+ //dagmo->setDag(ogra); //Make the Model from a boost::graph internally
+ //dagmo->makeDagModel();
+ //--------------------------------------------------------------------------
+
     if(success)
         emit statusMessage(tr("Test executed successfully."));
     else

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/objects1.db
==============================================================================
Binary files. No diff available.


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk