Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77402 - sandbox/icl/libs/xplore/br1/sqlbrowser
From: afojgo_at_[hidden]
Date: 2012-03-19 12:55:30


Author: jofaber
Date: 2012-03-19 12:55:28 EDT (Mon, 19 Mar 2012)
New Revision: 77402
URL: http://svn.boost.org/trac/boost/changeset/77402

Log:
Exploration of boost::graph.
Added:
   sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h (contents, props changed)
   sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h (contents, props changed)
   sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor.h (contents, props changed)
   sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro (contents, props changed)
Text files modified:
   sandbox/icl/libs/xplore/br1/sqlbrowser/browser.cpp | 1
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.cpp | 12 +-
   sandbox/icl/libs/xplore/br1/sqlbrowser/dagmodel.h | 141 +--------------------------------------
   3 files changed, 13 insertions(+), 141 deletions(-)

Added: sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h
==============================================================================
--- (empty file)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/CreatorVisitor.h 2012-03-19 12:55:28 EDT (Mon, 19 Mar 2012)
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+**
+****************************************************************************/
+
+#pragma once
+
+#include <boost/graph/graph_traits.hpp>
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/depth_first_search.hpp>
+#include <boost/graph/graph_utility.hpp>
+
+#include "Dag.h"
+
+
+
+struct CreatorVisitor
+{
+ //--------------------------------------------------------------------------
+ // Visitors
+ struct OnDiscoverVertex : public boost::base_visitor<OnDiscoverVertex>
+ {
+ OnDiscoverVertex(QString* result, Dag::tAttributesMap& names)
+ : p_result(result), r_attrs(names){}
+
+ 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
+
+ if(boost::out_degree(node, dag) > 0)
+ {
+ *p_result += indentation(r_attrs[node].depth()) + "(";
+ *p_result += r_attrs[node].name();
+ *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;
+ }
+
+ 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){}
+
+ 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();
+ int target_depth = source_depth + 1;
+ r_attrs[target(edge, dag)].setDepth(target_depth);
+
+ if(boost::out_degree(target(edge, dag), dag)==0)
+ {
+ *p_result += indentation(target_depth) + r_attrs[target(edge, dag)].name();
+ *p_result += "\n";
+ }
+ }
+
+ 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){}
+
+ 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";
+ }
+ }
+
+ QString* p_result;
+ Dag::tAttributesMap& r_attrs;
+ };
+
+}; // StringVisitor
+

Added: sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h
==============================================================================
--- (empty file)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/Dag.h 2012-03-19 12:55:28 EDT (Mon, 19 Mar 2012)
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+**
+****************************************************************************/
+
+#pragma once
+
+#include <boost/graph/graph_traits.hpp>
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/depth_first_search.hpp>
+#include <boost/graph/graph_utility.hpp>
+
+
+// An object to collect results on graph traversal
+class NodeAttributes
+{
+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) {}
+
+ void setName(const QString& name) { m_name = name; }
+ QString name()const { return m_name; }
+
+ void setDepth(int depth){ m_depth = depth; }
+ int depth()const { return m_depth; }
+
+ int inc(){ return ++m_depth; }
+
+private:
+ QString m_name;
+ int m_depth;
+};
+
+
+struct Dag
+{
+ // The kind of attribute_tag is a vertex_property_tag
+ struct attribute_tag { typedef boost::vertex_property_tag kind; };
+
+ typedef boost::property<attribute_tag, NodeAttributes> tAttributeTag;
+
+ typedef boost::adjacency_list
+ < boost::vecS
+ , boost::vecS
+ , boost::directedS
+ , tAttributeTag
+ > DagType;
+
+ typedef DagType type;
+ typedef DagType::vertex_descriptor vertex_descriptor;
+ typedef DagType::edge_descriptor edge_descriptor;
+
+ typedef boost::property_map<Dag::type, attribute_tag>::type
+ tAttributesMap;
+
+ typedef std::map<vertex_descriptor, vertex_descriptor> tParentMap;
+};
+
+

Added: sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor.h
==============================================================================
--- (empty file)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/StringVisitor.h 2012-03-19 12:55:28 EDT (Mon, 19 Mar 2012)
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+**
+****************************************************************************/
+
+#pragma once
+
+#include <boost/graph/graph_traits.hpp>
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/depth_first_search.hpp>
+#include <boost/graph/graph_utility.hpp>
+
+#include "Dag.h"
+
+
+inline QString indentation(int depth)
+{
+ QString indent;
+ for(int idx=0; idx < depth; idx++)
+ indent += " ";
+ return indent;
+}
+
+
+struct StringVisitor
+{
+ //--------------------------------------------------------------------------
+ // Visitors
+ struct OnDiscoverVertex : public boost::base_visitor<OnDiscoverVertex>
+ {
+ OnDiscoverVertex(QString* result, Dag::tAttributesMap& names)
+ : p_result(result), r_attrs(names){}
+
+ typedef boost::on_discover_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 += r_attrs[node].name();
+ *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;
+ }
+
+ QString* p_result;
+ Dag::tAttributesMap& r_attrs;
+ };
+
+ struct OnExamineEdge : public boost::base_visitor<OnExamineEdge>
+ {
+ OnExamineEdge(QString* result, Dag::tAttributesMap& names, Dag::tParentMap& parents)
+ : p_result(result), r_attrs(names), r_parents(parents){}
+
+ 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();
+ int target_depth = source_depth + 1;
+ r_attrs[target(edge, dag)].setDepth(target_depth);
+ //CL r_parents stuff
+ Dag::vertex_descriptor child = target(edge, dag);
+ Dag::vertex_descriptor parent = source(edge, dag);
+ r_parents[child] = parent;
+
+ if(boost::out_degree(target(edge, dag), dag)==0)
+ {
+ *p_result += indentation(target_depth) + r_attrs[target(edge, dag)].name();
+ *p_result += "\n";
+ }
+ }
+
+ QString* p_result;
+ Dag::tAttributesMap& r_attrs;
+ Dag::tParentMap& r_parents;
+ };
+
+ struct OnFinishVertex : public boost::base_visitor<OnFinishVertex>
+ {
+ OnFinishVertex(QString* result, Dag::tAttributesMap& names)
+ : 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";
+ }
+ }
+
+ QString* p_result;
+ Dag::tAttributesMap& r_attrs;
+ };
+
+ /*CL
+ struct OnTreeEdge : public boost::base_visitor<OnTreeEdge>
+ {
+ OnTreeEdge(QString* result, Dag::tAttributesMap& names)
+ : p_result(result), r_attrs(names){}
+
+ typedef boost::on_tree_edge event_filter;
+
+ template<class Edge, class Graph>
+ void operator()(Edge edge, Graph& dag)
+ {
+ int source_depth = r_attrs[source(edge, dag)].depth();
+ int target_depth = source_depth + 1;
+ r_attrs[target(edge, dag)].setDepth(target_depth);
+
+ *p_result += ".";
+ }
+
+ QString* p_result;
+ Dag::tAttributesMap& r_attrs;
+ };
+ */
+
+}; // StringVisitor
+

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-19 12:55:28 EDT (Mon, 19 Mar 2012)
@@ -86,7 +86,6 @@
     QString dbg_query = QString(sqlEdit->toPlainText());
     xpQuery.exec(sqlEdit->toPlainText());
 
- int dbg_size = xpQuery.size();
     // Populate the Dag Model from an sql-Query
     //JODO dagmo->fromSql(xpQuery);
     dagmo->getEdges(xpQuery);

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-19 12:55:28 EDT (Mon, 19 Mar 2012)
@@ -8,6 +8,7 @@
 
 #include "dagitem.h"
 #include "dagmodel.h"
+#include "StringVisitor.h"
 
 using namespace boost;
 
@@ -269,7 +270,7 @@
         m_dag
       , boost::visitor(make_dfs_visitor(boost::make_list(
                                               creater::node_start(m_rootItem, m_nodeAttributes)
- , creater::edge_visit(m_rootItem, m_nodeAttributes)
+ , creater::OnExamineEdge(m_rootItem, m_nodeAttributes)
                                             , creater::node_stop (m_rootItem, m_nodeAttributes)
                                             )
                       ))
@@ -306,7 +307,7 @@
 
 void DagModel::makeDag()
 {
- m_nodeAttributes = get(attribute_tag(), m_dag);
+ m_nodeAttributes = get(Dag::attribute_tag(), m_dag);
 
     for(tEdgeList::iterator iter = m_edges.begin(); iter != m_edges.end(); iter++)
     {
@@ -328,9 +329,10 @@
     boost::depth_first_search(
         m_dag
       , boost::visitor(make_dfs_visitor(boost::make_list(
- node_arrival(&dagAsString, m_nodeAttributes)
- , edge_visit(&dagAsString, m_nodeAttributes)
- , node_final(&dagAsString, m_nodeAttributes)
+ StringVisitor::OnDiscoverVertex(&dagAsString, m_nodeAttributes)
+ , StringVisitor::OnExamineEdge(&dagAsString, m_nodeAttributes, m_parentMap)
+ , StringVisitor::OnFinishVertex(&dagAsString, m_nodeAttributes)
+ //, boost::record_predecessors(parentMap.begin(), boost::on_tree_edge())
                                             )
                       ))
     );

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-19 12:55:28 EDT (Mon, 19 Mar 2012)
@@ -6,6 +6,8 @@
 #ifndef DAGMODEL_H
 #define DAGMODEL_H
 
+#include <map>
+
 #include <boost/graph/graph_traits.hpp>
 #include <boost/graph/adjacency_list.hpp>
 #include <boost/graph/depth_first_search.hpp>
@@ -15,16 +17,8 @@
 #include <QModelIndex>
 #include <QVariant>
 
-#include <map>
-
+#include "Dag.h"
 
-inline QString indentation(int depth)
-{
- QString indent;
- for(int idx=0; idx < depth; idx++)
- indent += " ";
- return indent;
-}
 
 
 typedef std::map<int, int> daggy; //CL?
@@ -32,27 +26,6 @@
 class QSqlQuery;
 class DagItem;
 
-// An object to collect results on graph traversal
-class NodeAttributes
-{
-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) {}
-
- void setName(const QString& name) { m_name = name; }
- QString name()const { return m_name; }
-
- void setDepth(int depth){ m_depth = depth; }
- int depth()const { return m_depth; }
-
- int inc(){ return ++m_depth; }
-
-private:
- QString m_name;
- int m_depth;
-};
-
 class DagModel : public QAbstractItemModel
 {
     Q_OBJECT
@@ -130,111 +103,9 @@
 
     //==========================================================================
     // Graph
- struct attribute_tag {
- typedef boost::vertex_property_tag kind;
- };
-
- typedef boost::property<attribute_tag, NodeAttributes> tAttributeTag;
-
- typedef boost::adjacency_list
- < boost::vecS
- , boost::vecS
- , boost::directedS
- , tAttributeTag
- > tDag;
-
- tDag m_dag;
-
- typedef boost::property_map<tDag, attribute_tag>::type
- tAttributesMap;
-
- tAttributesMap m_nodeAttributes;
-
- //--------------------------------------------------------------------------
- // Visitors
- struct node_arrival : public boost::base_visitor<node_arrival>
- {
- node_arrival(QString* result, tAttributesMap& names)
- : p_result(result), r_attrs(names){}
-
- typedef boost::on_discover_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 += r_attrs[node].name();
- *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;
- }
-
- QString* p_result;
- tAttributesMap& r_attrs;
- };
-
- struct edge_visit : public boost::base_visitor<edge_visit>
- {
- edge_visit(QString* result, tAttributesMap& names)
- : p_result(result), r_attrs(names){}
-
- 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();
- int target_depth = source_depth + 1;
- r_attrs[target(edge, dag)].setDepth(target_depth);
-
- if(boost::out_degree(target(edge, dag), dag)==0)
- {
- *p_result += indentation(target_depth) + r_attrs[target(edge, dag)].name();
- *p_result += "\n";
- }
- }
-
- QString* p_result;
- tAttributesMap& r_attrs;
- };
-
- struct node_final : public boost::base_visitor<node_final>
- {
- node_final(QString* result, tAttributesMap& names)
- : 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";
- }
- }
-
- QString* p_result;
- tAttributesMap& r_attrs;
- };
-
+ Dag::type m_dag;
+ Dag::tAttributesMap m_nodeAttributes;
+ Dag::tParentMap m_parentMap;
 };
 
 #endif

Added: sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro
==============================================================================
--- (empty file)
+++ sandbox/icl/libs/xplore/br1/sqlbrowser/sqlbrowser4.pro 2012-03-19 12:55:28 EDT (Mon, 19 Mar 2012)
@@ -0,0 +1,48 @@
+TEMPLATE = app
+TARGET = sqlbrowser
+
+QT += sql
+
+INCLUDEPATH += /NIBuild/3rdparty/boost-1.48.0
+
+HEADERS = browser.h connectionwidget.h qsqlconnectiondialog.h \
+ exttableview.h \
+ dagitem.h \
+ dagmodel.h \
+ dagmodel.h \
+ StringVisitor.h \
+ Dag.h \
+ CreatorVisitor.h
+SOURCES = main.cpp browser.cpp connectionwidget.cpp qsqlconnectiondialog.cpp \
+ exttableview.cpp \
+ dagitem.cpp \
+ dagmodel.cpp
+
+FORMS = browserwidget.ui qsqlconnectiondialog.ui
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+# install
+target.path = $$[QT_INSTALL_DEMOS]/sqlbrowser
+sources.files = $$SOURCES $$HEADERS $$FORMS *.pro
+sources.path = $$[QT_INSTALL_DEMOS]/sqlbrowser
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/demos/symbianpkgrules.pri)
+
+wince*: {
+ DEPLOYMENT_PLUGIN += qsqlite
+}
+
+
+
+
+
+
+
+
+
+
+


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