Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77455 - sandbox/icl/libs/xplore/br1/sqlbrowser
From: afojgo_at_[hidden]
Date: 2012-03-21 12:58:51


Author: jofaber
Date: 2012-03-21 12:58:49 EDT (Wed, 21 Mar 2012)
New Revision: 77455
URL: http://svn.boost.org/trac/boost/changeset/77455

Log:
Exploration of boost::graph.
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h | 62 ++++++++++++++++++++++++++++++---------
   sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h | 16 ++++++---
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 5 ++
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp | 19 ++++++++++++
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h | 4 ++
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp | 5 ++
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h | 1
   7 files changed, 89 insertions(+), 23 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-03-21 12:58:49 EDT (Wed, 21 Mar 2012)
@@ -21,34 +21,40 @@
     struct OnDiscoverVertex : public boost::base_visitor<OnDiscoverVertex>
     {
         OnDiscoverVertex(DagItem* curItem, QString* result, Dag::tAttributesMap& attrs)
- : p_curItem(curItem), p_result(result), r_attrs(attrs){}
+ : p_curItem(curItem), p_result(result), r_attrs(attrs)
+ {
+ r_attrs[0].setDagItem(p_curItem); //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(2); // 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
+ 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
- //JODO p_curItem is parent wrt. itemData.
- DagItem* newItem = new DagItem(itemData, p_curItem);
+ // 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 += " = " + newItem[dag::node::posName].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";
             }
-
- p_curItem = newItem;
         }
 
         //CL Example for iterating over edges.
@@ -74,20 +80,43 @@
     struct OnExamineEdge : public boost::base_visitor<OnExamineEdge>
     {
         OnExamineEdge(DagItem* curItem, QString* result, Dag::tAttributesMap& names)
- : p_curItem(curItem), p_result(result), r_attrs(names){}
+ : p_curItem(curItem), p_result(result), r_attrs(names)
+ {
+ 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)
         {
- int source_depth = r_attrs[source(edge, dag)].depth();
+ 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(edge, dag)].setDepth(target_depth);
+ 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);
+ }
 
             if(boost::out_degree(target(edge, dag), dag)==0)
             {
- *p_result += indentation(target_depth) + r_attrs[target(edge, dag)].name();
+ *p_result += indentation(target_depth) + r_attrs[target(edge, dag)].name() + " ?";
                 *p_result += "\n";
             }
         }
@@ -100,7 +129,10 @@
     struct OnFinishVertex : public boost::base_visitor<OnFinishVertex>
     {
         OnFinishVertex(DagItem* curItem, QString* result, Dag::tAttributesMap& names)
- : p_curItem(curItem), p_result(result), r_attrs(names){}
+ : p_curItem(curItem), p_result(result), r_attrs(names)
+ {
+ r_attrs[0].setDagItem(p_curItem); //Root node
+ }
 
         typedef boost::on_finish_vertex event_filter;
 
@@ -119,5 +151,5 @@
         Dag::tAttributesMap& r_attrs;
     };
 
-}; // StringVisitor
+}; // CreatorVisitor
 

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h 2012-03-21 12:58:49 EDT (Wed, 21 Mar 2012)
@@ -24,8 +24,8 @@
 {
 public:
     NodeAttributes(): m_name(), m_depth() {}
- NodeAttributes(const QString& name): m_name(name), m_depth() {}
- NodeAttributes(const QString& name, int depth): m_name(name), m_depth(depth) {}
+ NodeAttributes(const QString& name): m_name(name), m_depth(), p_dagItem() {}
+ NodeAttributes(const QString& name, int depth): m_name(name), m_depth(depth), p_dagItem() {}
 
     void setName(const QString& name) { m_name = name; }
     QString name()const { return m_name; }
@@ -33,11 +33,15 @@
     void setDepth(int depth){ m_depth = depth; }
     int depth()const { return m_depth; }
 
+ void setDagItem(DagItem* dagItem) { p_dagItem = dagItem; }
+ DagItem* dagItem()const { return p_dagItem; }
+
     int inc(){ return ++m_depth; }
 
 private:
- QString m_name;
- int m_depth;
+ QString m_name;
+ int m_depth;
+ DagItem* p_dagItem;
 };
 
 namespace dag
@@ -64,8 +68,8 @@
 
     inline void copyBoostNode2DagItem(const NodeAttributes& src, tVariVector& target)//JODO cpp
     {
- target[dag::node::posId] = 0;
- target[dag::node::posName] = src.name();
+ target[dag::node::posId] = QVariant(0);
+ target[dag::node::posName] = QVariant(src.name());
     }
 }//namespace dag
 

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-03-21 12:58:49 EDT (Wed, 21 Mar 2012)
@@ -94,9 +94,12 @@
     QMessageBox msgBox;
     //QString dagStr = dagmo->toString();
     //QString dagStr = dagmo->dagToString();
- QString dagStr = dagmo->setupDag();
+ QString dagStr = dagmo->setupDag();
+ QString dagStr2 = dagmo->rootItem()->toString();
     msgBox.setText(dagStr);
     msgBox.exec();
+ msgBox.setText(dagStr2);
+ msgBox.exec();
 
     model->setQuery(curQuery);
     //REV? model->setQuery(QSqlQuery(sqlEdit->toPlainText(), connectionWidget->currentDatabase()));

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.cpp 2012-03-21 12:58:49 EDT (Wed, 21 Mar 2012)
@@ -11,6 +11,7 @@
 
 #include <QStringList>
 
+#include "Dag.h"
 #include "dagitem.h"
 
 DagItem::DagItem(const QVector<QVariant> &data, DagItem *parent)
@@ -146,3 +147,21 @@
     return true;
 }
 
+
+QString DagItem::toString()
+{
+ if(childCount()==0)
+ return itemData[dag::node::posName].toString() + "\n";
+ else
+ {
+ QString children = "(";
+ children += itemData[dag::node::posName].toString() + "\n";
+
+ for(int idx=0; idx < childCount(); idx++)
+ children += child(idx)->toString() + "\n";
+
+ children += ")";
+ return children;
+ }
+}
+

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h 2012-03-21 12:58:49 EDT (Wed, 21 Mar 2012)
@@ -37,6 +37,10 @@
     void addChild(DagItem* child);
     bool isLeaf(int TypeId)const { return itemData[TypeId] == NodeType_Object; }
 
+ tVariVector data()const { return itemData; }
+
+ QString toString(); //DBG CL
+
 private:
     QList<DagItem*> childItems;
     tVariVector itemData;

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp 2012-03-21 12:58:49 EDT (Wed, 21 Mar 2012)
@@ -21,7 +21,10 @@
     foreach (QString header, headers)
         rootData << header;
 
- //m_rootItem = new DagItem(rootData);
+ rootData.resize(dag::node::sizeOf_node);
+ rootData[dag::node::posId] = QVariant(0);
+ rootData[dag::node::posName] = QVariant("NIL");
+ m_rootItem = new DagItem(rootData);
     //setupModelData(data.split(QString("\n")), m_rootItem);
 }
 

Modified: sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h
==============================================================================
--- sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h (original)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h 2012-03-21 12:58:49 EDT (Wed, 21 Mar 2012)
@@ -80,6 +80,7 @@
 
     QString nodeToString(DagItem* node, int depth)const;
 
+ DagItem* rootItem()const { return m_rootItem; } //CL DBG
 
 private:
     void setupModelData(const QStringList &lines, DagItem *parent);


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