Boost logo

Boost-Commit :

From: stipe_at_[hidden]
Date: 2008-07-20 19:30:17


Author: srajko
Date: 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
New Revision: 47644
URL: http://svn.boost.org/trac/boost/changeset/47644

Log:
added glv_graph example
Added:
   sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_graph.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj | 2 ++
   sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/Jamfile.v2 | 3 ++-
   sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_bank.cpp | 2 +-
   sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_window.cpp | 32 ++++----------------------------
   sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_window.hpp | 2 --
   sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_example.cpp | 1 +
   sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_logic.cpp | 32 ++++++++++----------------------
   7 files changed, 20 insertions(+), 54 deletions(-)

Modified: sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
@@ -203,6 +203,7 @@
                 08A6B26A0E25A566005539F2 /* blueprint_window.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = blueprint_window.hpp; sourceTree = "<group>"; };
                 08A6B26B0E25A566005539F2 /* glvgui_example.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = glvgui_example.cpp; sourceTree = "<group>"; };
                 08A6B26C0E25A566005539F2 /* Jamfile.v2 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Jamfile.v2; sourceTree = "<group>"; };
+ 08A74E790E33AFA900B1A8CF /* glvgui_graph.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = glvgui_graph.cpp; sourceTree = "<group>"; };
                 08A82B550E11EBF500AAB117 /* dynamic_port.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = dynamic_port.hpp; sourceTree = "<group>"; };
                 08AD8AB50D84DF31008A9764 /* test_has_call_operator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_has_call_operator.cpp; sourceTree = "<group>"; };
                 08AD8AC40D84E3A9008A9764 /* has_call_operator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = has_call_operator.hpp; sourceTree = "<group>"; };
@@ -633,6 +634,7 @@
                 08A6B2640E25A566005539F2 /* glv_gui */ = {
                         isa = PBXGroup;
                         children = (
+ 08A74E790E33AFA900B1A8CF /* glvgui_graph.cpp */,
                                 08C617FB0E27E39500FC4F24 /* glvgui_logic.cpp */,
                                 08A6B2650E25A566005539F2 /* blueprint_bank.cpp */,
                                 08A6B2660E25A566005539F2 /* blueprint_bank.hpp */,

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/Jamfile.v2 (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/Jamfile.v2 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
@@ -20,4 +20,5 @@
     ;
 
 exe glv_example : glvgui_example.cpp $(sources).cpp ;
-exe glv_logic : glvgui_logic.cpp $(sources).cpp ;
\ No newline at end of file
+exe glv_logic : glvgui_logic.cpp $(sources).cpp ;
+exe glv_graph : glvgui_graph.cpp $(sources).cpp ;
\ No newline at end of file

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_bank.cpp
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_bank.cpp (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_bank.cpp 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
@@ -21,7 +21,7 @@
     }
     void spawn()
     {
- m_bank.m_blueprint->add_component(m_bank.m_bank[m_label], m_label);
+ m_bank.m_blueprint->add_component(std::auto_ptr<blueprint::component>(m_bank.m_bank[m_label]()), m_label);
     }
 private:
     std::string m_label;

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_window.cpp
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_window.cpp (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_window.cpp 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
@@ -22,39 +22,15 @@
 void blueprint_window::add_component(std::auto_ptr<blueprint::component> c, const std::string &name)
 {
     std::cout << "Adding component" << name << std::endl;
- blueprint_component *bc = new blueprint_component(name, *c, m_network.add_component(c));
- add_component_helper(*bc);
-}
-
-void blueprint_window::add_component(boost::function<blueprint::component *()> f, const std::string &name)
-{
- std::cout << "Adding component" << name << std::endl;
 
- std::auto_ptr<blueprint::component> c(f());
     blueprint::component &cr = *c;
     blueprint_component *bc = new blueprint_component(name, cr, m_network.add_component(c));
- add_component_helper(*bc);
-
-/* gui::wnd<blueprint_component> bc = gui::create<blueprint_component>
- ( gui::_pos = std::make_pair(m_next_created_x, m_next_created_y)
- , gui::_size = std::make_pair(100, 100)
- , gui::_text = name
- , gui::_parent = this_);*/
-
-// std::auto_ptr<blueprint::component> c(f());
-// blueprint::network::component_type id = m_network.add_component(c);
-// bc->set_component(m_network[id], id);
-
-
-// add_component_helper(*bc);
-}
-
-void blueprint_window::add_component_helper(blueprint_component &bc)
-{
- m_layout << bc;
+ if((m_components.size()%5)==0)
+ m_layout.pos(0, m_components.size()/5 * 220);
+ m_components.push_back(bc);
+ m_layout << *bc;
 }
 
-
 void blueprint_window::register_port_click(blueprint_component_port *port)
 {
     if(m_dragged)

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_window.hpp
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_window.hpp (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/blueprint_window.hpp 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
@@ -32,11 +32,9 @@
 public:
     blueprint_window();
     void add_component(std::auto_ptr<blueprint::component> c, const std::string &name);
- void add_component(boost::function<blueprint::component *()> f, const std::string &name);
     void register_port_click(blueprint_component_port *port);
 private:
     void onDraw();
- void add_component_helper(blueprint_component &bc);
     blueprint::network m_network;
     std::vector<blueprint_component *> m_components;
     blueprint_component_port *m_dragged;

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_example.cpp
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_example.cpp (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_example.cpp 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
@@ -68,6 +68,7 @@
         add_component<output_valuator>("out");
         add_component<input_valuator>("in");
 #ifndef BOOST_MSVC
+ // a doubler (this doesn't compile on MSVC...)
         add_component<signals::function<void (int), int(int)> >
             ("x2", boost::function<int(int)>(boost::bind(std::multiplies<int>(), _1, 2)));
 #endif

Added: sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_graph.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_graph.cpp 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
@@ -0,0 +1,210 @@
+//[ glvgui_graph
+
+// Copyright 2007 Stjepan Rajko.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <glv.h>
+#include <glv_binding_glut.h>
+
+#include "blueprint_bank.hpp"
+#include "blueprint_window.hpp"
+
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/strong_components.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <boost/dataflow/support/fusion_component.hpp>
+#include <boost/dataflow/blueprint/component_bank.hpp>
+#include <boost/dataflow/support/runtime.hpp>
+
+namespace df=boost::dataflow;
+namespace blueprint=boost::dataflow::blueprint;
+
+// provide Dataflow support for a BGL graph type
+namespace boost { namespace dataflow { namespace graph {
+
+struct tag : public default_tag
+{};
+
+typedef boost::adjacency_list<
+ boost::vecS, boost::vecS, boost::directedS> graph_type;
+
+struct vertex;
+struct in_vertex_port;
+struct out_vertex_port;
+
+struct out_vertex_port_traits : public dataflow::complemented_port_traits<ports::producer, in_vertex_port, tag>
+{};
+
+struct out_vertex_port : public dataflow::port<out_vertex_port_traits>
+{
+ out_vertex_port(vertex &c)
+ : m_vertex(c) {}
+ vertex &m_vertex;
+};
+
+struct in_vertex_port_traits : public dataflow::complemented_port_traits<ports::consumer, out_vertex_port, tag>
+{};
+
+struct in_vertex_port : public dataflow::port<in_vertex_port_traits>
+{
+ in_vertex_port(vertex &c)
+ : m_vertex(c) {}
+ vertex &m_vertex;
+};
+
+struct component_traits
+ : public dataflow::fusion_component_traits<
+ fusion::vector<
+ in_vertex_port,
+ out_vertex_port
+ >,
+ mpl::map< >,
+ tag>
+{
+ static fusion_ports get_ports(vertex &v)
+ {
+ return fusion_ports(
+ in_vertex_port(v),
+ out_vertex_port(v));
+ }
+};
+
+struct vertex : public dataflow::component<component_traits>
+{
+ vertex(graph_type &graph)
+ : m_graph(graph)
+ {
+ m_vertex_descriptor = add_vertex(graph);
+ }
+ graph_type &m_graph;
+ graph_type::vertex_descriptor m_vertex_descriptor;
+};
+
+// an empty component that can be invoked... nothing to do with BGL
+struct invocable_component_traits : public dataflow::fusion_component_traits<fusion::vector<>, mpl::map<>, df::graph::tag>
+{
+ template<typename Component>
+ static fusion_ports get_ports(Component &component)
+ {
+ return fusion_ports();
+ }
+};
+
+class invocable_component : public dataflow::component<invocable_component_traits>
+{
+public:
+ invocable_component(graph_type &graph)
+ : m_graph(graph)
+ {}
+protected:
+ graph_type &m_graph;
+};
+
+}
+
+namespace extension {
+
+ // how to connect two vertices
+ template<>
+ struct binary_operation_impl<graph::out_vertex_port_traits, graph::in_vertex_port_traits, operations::connect>
+ {
+ typedef void result_type;
+
+ template<typename Producer, typename Consumer>
+ result_type operator()(Producer &producer, Consumer &consumer)
+ {
+ BOOST_ASSERT(&producer.m_vertex.m_graph == &consumer.m_vertex.m_graph);
+ add_edge(producer.m_vertex.m_vertex_descriptor, consumer.m_vertex.m_vertex_descriptor, producer.m_vertex.m_graph);
+ }
+ };
+
+ // how to invoke a component
+ template<>
+ struct component_operation_impl<graph::invocable_component_traits, operations::invoke>
+ {
+ typedef void result_type;
+
+ template<typename Component>
+ result_type operator()(Component &component)
+ {
+ component.invoke();
+ }
+ };
+
+}
+
+} }
+
+DATAFLOW_RUNTIME_PROPERTY(graph::tag, const char *, "Dataflow.Graph")
+// 30 us supposed to be a UUID :-)
+DATAFLOW_RUNTIME_PROPERTY(graph::tag, int, 30)
+
+// A component that computes the number of strongly connected components in the
+// graph
+class strong_components_computer
+ : public df::graph::invocable_component
+ , public glv::Label
+{
+public:
+ typedef glv::View runtime_base_class_type;
+
+ strong_components_computer(df::graph::graph_type &graph)
+ : df::graph::invocable_component(graph)
+ , glv::Label("")
+ {
+ anchor(glv::Place::CL);
+ size(80);
+ }
+ void invoke()
+ {
+ std::vector<int> component(num_vertices(m_graph)), discover_time(num_vertices(m_graph));
+ std::vector<boost::default_color_type> color(num_vertices(m_graph));
+ std::vector<unsigned> root(num_vertices(m_graph));
+ int num = boost::strong_components(m_graph, &component[0],
+ boost::root_map(&root[0]).
+ color_map(&color[0]).
+ discover_time_map(&discover_time[0]));
+
+ label(boost::lexical_cast<std::string>(num));
+ }
+};
+
+// A component_bank with some components
+class example_bank : public blueprint::tag_component_bank<df::graph::tag>
+{
+public:
+ example_bank()
+ {
+ add_component<df::graph::vertex>("v", boost::ref(m_graph));
+ add_component<strong_components_computer>("sc", boost::ref(m_graph));
+ }
+private:
+ // this is the BGL graph
+ df::graph::graph_type m_graph;
+};
+
+int main()
+{
+ glv::GLV top;
+ glv::Window win(640, 640, "GLV Blueprint GUI", &top);
+ glv::Placer placer(top, glv::Direction::E, glv::Place::TL, 0, 0, 0);
+
+ using namespace boost::dataflow::glv_gui;
+
+ // create the blueprint and component windows
+ blueprint_bank bank;
+ blueprint_window window;
+
+ // initialize the bank
+ bank.set_bank(example_bank());
+ bank.set_blueprint(window);
+
+ placer << bank.view() << window;
+ glv::Application::run();
+}
+
+//]
+

Modified: sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_logic.cpp
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_logic.cpp (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/glv_gui/glvgui_logic.cpp 2008-07-20 19:30:17 EDT (Sun, 20 Jul 2008)
@@ -22,17 +22,16 @@
 
 using df::managed::fusion_component;
 
-// source just provides an output port
-class source : public fusion_component<bool>, public glv::Button
+// the input/output component (link between GUI and dataflow network)
+class io : public fusion_component<bool>, public glv::Button
 {
 public:
     typedef glv::View runtime_base_class_type;
- source(df::managed::network &network)
+ io(df::managed::network &network)
         : fusion_component<bool>(network)
         , glv::Button(glv::Rect(100,100),true)
     {
         anchor(glv::Place::CL);
-// m_producer_port.set(value);
     }
     void invoke()
     {
@@ -51,30 +50,21 @@
     }
 };
 
-// adder has two input ports and an output port.
-// invoking adds the two inputs into the output.
-class not_operation : public fusion_component<bool>, public glv::Button
+// logical NOT component.
+class not_operation : public fusion_component<bool>
 {
 public:
- typedef glv::View runtime_base_class_type;
     not_operation(df::managed::network &network)
         : fusion_component<bool>(network)
- , glv::Button(glv::Rect(100,100),true)
- {
- anchor(glv::Place::CL);
- }
+ {}
     void invoke()
     {
         if(port<0>().connected())
- {
             port<1>().set(!port<0>().get());
- value(port<1>().get(), 0);
- }
     }
 };
 
-// adder has two input ports and an output port.
-// invoking adds the two inputs into the output.
+// logical AND component.
 class and_operation : public fusion_component<boost::mpl::vector<bool,bool>,bool>
 {
 public:
@@ -92,8 +82,7 @@
     }
 };
 
-// adder has two input ports and an output port.
-// invoking adds the two inputs into the output.
+// logical OR component.
 class or_operation : public fusion_component<boost::mpl::vector<bool,bool>,bool>
 {
 public:
@@ -111,8 +100,7 @@
     }
 };
 
-// adder has two input ports and an output port.
-// invoking adds the two inputs into the output.
+// This component requests a network update.
 class update_network : public fusion_component<bool>
 {
 public:
@@ -132,7 +120,7 @@
 public:
     example_bank()
     {
- add_component<source>("src", boost::ref(m_network));
+ add_component<io>("io", boost::ref(m_network));
         add_component<not_operation>("not", boost::ref(m_network));
         add_component<and_operation>("and", boost::ref(m_network));
         add_component<or_operation>("or", boost::ref(m_network));


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