Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77435 - sandbox/icl/libs/xplore/br1/sqlbrowser
From: afojgo_at_[hidden]
Date: 2012-03-20 14:03:06


Author: jofaber
Date: 2012-03-20 14:03:04 EDT (Tue, 20 Mar 2012)
New Revision: 77435
URL: http://svn.boost.org/trac/boost/changeset/77435

Log:
Exploration of boost::graph.
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h | 31 ++++++++++++++++++++------
   sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h | 46 ++++++++++++++++++++++++++++++++++++---
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 3 +
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagitem.h | 11 +++++----
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp | 15 +++++++-----
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h | 2
   6 files changed, 83 insertions(+), 25 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-20 14:03:04 EDT (Tue, 20 Mar 2012)
@@ -20,23 +20,35 @@
     // Visitors
     struct OnDiscoverVertex : public boost::base_visitor<OnDiscoverVertex>
     {
- OnDiscoverVertex(QString* result, Dag::tAttributesMap& names)
- : p_result(result), r_attrs(names){}
+ OnDiscoverVertex(DagItem* curItem, QString* result, Dag::tAttributesMap& attrs)
+ : p_curItem(curItem), p_result(result), r_attrs(attrs){}
 
         typedef boost::on_discover_vertex event_filter;
 
         template<class Vertex, class Graph>
         void operator()(Vertex node, Graph& dag)
         {
- // Create a DagItem. The node that has been visited last
- // should be the parent
+ // 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
+ 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);
 
             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 += "\n";
             }
+
+ p_curItem = newItem;
         }
 
         //CL Example for iterating over edges.
@@ -54,14 +66,15 @@
             return edge_cnt;
         }
 
+ DagItem* p_curItem;
         QString* p_result;
         Dag::tAttributesMap& r_attrs;
     };
 
     struct OnExamineEdge : public boost::base_visitor<OnExamineEdge>
     {
- OnExamineEdge(QString* result, Dag::tAttributesMap& names)
- : p_result(result), r_attrs(names){}
+ OnExamineEdge(DagItem* curItem, QString* result, Dag::tAttributesMap& names)
+ : p_curItem(curItem), p_result(result), r_attrs(names){}
 
         typedef boost::on_examine_edge event_filter;
 
@@ -79,14 +92,15 @@
             }
         }
 
+ DagItem* p_curItem;
         QString* p_result;
         Dag::tAttributesMap& r_attrs;
     };
 
     struct OnFinishVertex : public boost::base_visitor<OnFinishVertex>
     {
- OnFinishVertex(QString* result, Dag::tAttributesMap& names)
- : p_result(result), r_attrs(names){}
+ OnFinishVertex(DagItem* curItem, QString* result, Dag::tAttributesMap& names)
+ : p_curItem(curItem), p_result(result), r_attrs(names){}
 
         typedef boost::on_finish_vertex event_filter;
 
@@ -100,6 +114,7 @@
             }
         }
 
+ DagItem* p_curItem;
         QString* p_result;
         Dag::tAttributesMap& r_attrs;
     };

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-20 14:03:04 EDT (Tue, 20 Mar 2012)
@@ -10,8 +10,16 @@
 #include <boost/graph/depth_first_search.hpp>
 #include <boost/graph/graph_utility.hpp>
 
+#include "dagitem.h"
 
-// An object to collect results on graph traversal
+
+// An object to collect results on graph traversal.
+// The object stores all the information, that shall be associated to graph nodes.
+// Because we encapsulate various attributes in this class, we only need to extend
+// this class, to add more information to graph nodes.
+//
+// The contents of this class is associated to the graph using tags:
+// attribute_tag, boost::property<attribute_tag, NodeAttributes>
 class NodeAttributes
 {
 public:
@@ -32,12 +40,42 @@
     int m_depth;
 };
 
+namespace dag
+{
+ namespace edge
+ {
+ enum { posParentId = 0
+ , posChildId
+ , posTypeId
+ , posParentName
+ , posChildName
+ , posChildType
+ , sizeOf_edge
+ };
+ }
+
+ namespace node
+ {
+ enum { posId = 0
+ , posName
+ , sizeOf_node
+ };
+ }
+
+ inline void copyBoostNode2DagItem(const NodeAttributes& src, tVariVector& target)//JODO cpp
+ {
+ target[dag::node::posId] = 0;
+ target[dag::node::posName] = src.name();
+ }
+}//namespace dag
 
 struct Dag
 {
     // The kind of attribute_tag is a vertex_property_tag
     struct attribute_tag { typedef boost::vertex_property_tag kind; };
 
+ // Here we associate a real type for content 'NodeAttributes' to the tag type
+ // attribute_tag -> NodeAttributes
     typedef boost::property<attribute_tag, NodeAttributes> tAttributeTag;
 
     typedef boost::adjacency_list
@@ -51,10 +89,10 @@
     typedef DagType::vertex_descriptor vertex_descriptor;
     typedef DagType::edge_descriptor edge_descriptor;
 
- typedef boost::property_map<Dag::type, attribute_tag>::type
- tAttributesMap;
+ //
+ typedef boost::property_map<Dag::type, attribute_tag>::type tAttributesMap;
 
- typedef std::map<vertex_descriptor, vertex_descriptor> tParentMap;
+ typedef std::map<vertex_descriptor, vertex_descriptor> tParentMap;//CL
 };
 
 

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-20 14:03:04 EDT (Tue, 20 Mar 2012)
@@ -93,7 +93,8 @@
 
     QMessageBox msgBox;
     //QString dagStr = dagmo->toString();
- QString dagStr = dagmo->dagToString();
+ //QString dagStr = dagmo->dagToString();
+ QString dagStr = dagmo->setupDag();
     msgBox.setText(dagStr);
     msgBox.exec();
 

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-20 14:03:04 EDT (Tue, 20 Mar 2012)
@@ -11,12 +11,15 @@
 #include <QVector>
 
 
+typedef QVector<QVariant> tVariVector;
+
 class DagItem
 {
 public:
+
     static const int NodeType_Object = 2;
 
- DagItem(const QVector<QVariant> &data, DagItem *parent = 0);
+ DagItem(const tVariVector &data, DagItem *parent = 0);
     ~DagItem();
 
     DagItem *child(int number);
@@ -36,10 +39,8 @@
 
 private:
     QList<DagItem*> childItems;
- QVector<QVariant> itemData;
- DagItem *parentItem;
- // int m_selectedParent;
- // QList<DagItem*> m_parentItems;
+ tVariVector itemData;
+ DagItem *parentItem;
 };
 
 #endif

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-20 14:03:04 EDT (Tue, 20 Mar 2012)
@@ -9,6 +9,7 @@
 #include "dagitem.h"
 #include "dagmodel.h"
 #include "StringVisitor.h"
+#include "CreatorVisitor.h"
 
 using namespace boost;
 
@@ -263,19 +264,21 @@
     }
 }
 
-void DagModel::setupDag(DagItem *parent)
+QString DagModel::setupDag()
 {
- /*JODO CONT
+ QString dagAsString; //JODO CL
+
     boost::depth_first_search(
         m_dag
       , boost::visitor(make_dfs_visitor(boost::make_list(
- creater::node_start(m_rootItem, m_nodeAttributes)
- , creater::OnExamineEdge(m_rootItem, m_nodeAttributes)
- , creater::node_stop (m_rootItem, m_nodeAttributes)
+ CreatorVisitor::OnDiscoverVertex(m_rootItem, &dagAsString, m_nodeAttributes)
+ , CreatorVisitor::OnExamineEdge (m_rootItem, &dagAsString, m_nodeAttributes)
+ , CreatorVisitor::OnFinishVertex (m_rootItem, &dagAsString, m_nodeAttributes)
                                             )
                       ))
     );
- */
+
+ return dagAsString;
 }
 
 void DagModel::getEdges(QSqlQuery& query)

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-20 14:03:04 EDT (Tue, 20 Mar 2012)
@@ -71,6 +71,7 @@
     void makeDag();
 
     QString dagToString();
+ QString setupDag();
 
     DagItem* fromSql(QSqlQuery& query, DagItem* node, int depth);
 
@@ -82,7 +83,6 @@
 
 private:
     void setupModelData(const QStringList &lines, DagItem *parent);
- void setupDag(DagItem *parent);
 
     DagItem *getItem(const QModelIndex &index) const;
 


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