Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50044 - in sandbox/dataflow-rewrite: boost/dataflow/blueprint libs/dataflow/build/xcodeide/dataflow.xcodeproj libs/dataflow/test/blueprint libs/dataflow/test/generic
From: stipe_at_[hidden]
Date: 2008-11-30 19:35:45


Author: srajko
Date: 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
New Revision: 50044
URL: http://svn.boost.org/trac/boost/changeset/50044

Log:
completed blueprint static_vector_adapter
Added:
   sandbox/dataflow-rewrite/boost/dataflow/blueprint/static_vector_adapter.hpp (contents, props changed)
   sandbox/dataflow-rewrite/boost/dataflow/blueprint/vector.hpp (contents, props changed)
Text files modified:
   sandbox/dataflow-rewrite/boost/dataflow/blueprint/castable_polymorphic_object.hpp | 8 ++++++--
   sandbox/dataflow-rewrite/boost/dataflow/blueprint/framework_entity_adapter.hpp | 9 +++++++++
   sandbox/dataflow-rewrite/boost/dataflow/blueprint/port_adapter.hpp | 3 +--
   sandbox/dataflow-rewrite/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj | 4 ++++
   sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/my_blueprint_static_vector.hpp | 3 +++
   sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/test_static_vector.cpp | 7 +++++++
   sandbox/dataflow-rewrite/libs/dataflow/test/generic/my_static_vector.hpp | 6 +++---
   sandbox/dataflow-rewrite/libs/dataflow/test/generic/test_entities.cpp | 4 ++--
   8 files changed, 35 insertions(+), 9 deletions(-)

Modified: sandbox/dataflow-rewrite/boost/dataflow/blueprint/castable_polymorphic_object.hpp
==============================================================================
--- sandbox/dataflow-rewrite/boost/dataflow/blueprint/castable_polymorphic_object.hpp (original)
+++ sandbox/dataflow-rewrite/boost/dataflow/blueprint/castable_polymorphic_object.hpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -14,7 +14,7 @@
 #include <boost/utility/enable_if.hpp>
 #include <boost/type_traits/is_const.hpp>
 #include <boost/type_traits/remove_const.hpp>
-
+#include <boost/assert.hpp>
 
 namespace boost { namespace dataflow { namespace blueprint {
 
@@ -29,11 +29,15 @@
     
     template<typename T>
     typename disable_if<is_const<T>, T &>::type get_as()
- { return *reinterpret_cast<T *>(get_ptr()); }
+ {
+ BOOST_ASSERT(typeid(T)==m_type_info);
+ return *reinterpret_cast<T *>(get_ptr());
+ }
     
     template<typename T>
     typename enable_if<is_const<T>, const T &>::type get_as() const
     {
+ BOOST_ASSERT(typeid(T)==m_type_info);
         return *reinterpret_cast<typename remove_const<T>::type *>(
             const_cast<castable_polymorphic_object *>(this)->get_ptr());
     }

Modified: sandbox/dataflow-rewrite/boost/dataflow/blueprint/framework_entity_adapter.hpp
==============================================================================
--- sandbox/dataflow-rewrite/boost/dataflow/blueprint/framework_entity_adapter.hpp (original)
+++ sandbox/dataflow-rewrite/boost/dataflow/blueprint/framework_entity_adapter.hpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -37,6 +37,15 @@
         : Base(fo, typeid(m_entity))
         , m_entity(t)
     {}
+
+ entity_type &entity()
+ {
+ return m_entity;
+ }
+ const entity_type &entity() const
+ {
+ return m_entity;
+ }
 private:
     virtual void *get_ptr()
     {

Modified: sandbox/dataflow-rewrite/boost/dataflow/blueprint/port_adapter.hpp
==============================================================================
--- sandbox/dataflow-rewrite/boost/dataflow/blueprint/port_adapter.hpp (original)
+++ sandbox/dataflow-rewrite/boost/dataflow/blueprint/port_adapter.hpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -22,8 +22,7 @@
     typedef framework_entity_adapter<BlueprintFramework, PortOrRef, Base> base_type;
 public:
     port_adapter(framework_context<BlueprintFramework> &fo)
- : base_type(fo)
-
+ : base_type(fo)
     {}
     template<typename T>
     port_adapter(framework_context<BlueprintFramework> &fo, const T &t)

Added: sandbox/dataflow-rewrite/boost/dataflow/blueprint/static_vector_adapter.hpp
==============================================================================
--- (empty file)
+++ sandbox/dataflow-rewrite/boost/dataflow/blueprint/static_vector_adapter.hpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -0,0 +1,131 @@
+/*=================================---------------------------------------------
+ Copyright 2007,2008 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)
+-----------------------------------------------===============================*/
+
+#ifndef BOOST__DATAFLOW__BLUEPRINT__STATIC_VECTOR_ADAPTER_HPP
+#define BOOST__DATAFLOW__BLUEPRINT__STATIC_VECTOR_ADAPTER_HPP
+
+
+#include <boost/dataflow/blueprint/framework_entity_adapter.hpp>
+#include <boost/dataflow/blueprint/port_adapter.hpp>
+#include <boost/dataflow/blueprint/vector.hpp>
+
+#include <boost/fusion/include/for_each.hpp>
+#include <boost/ptr_container/ptr_vector.hpp>
+
+
+namespace boost { namespace dataflow { namespace blueprint {
+
+template<typename BlueprintFramework>
+class static_port_iterator
+ : public port_iterator_base<BlueprintFramework>
+{
+public:
+ static_port_iterator(ptr_vector<port<BlueprintFramework> > &ports, unsigned index = 0)
+ : m_ports(ports)
+ , m_index(index)
+ {}
+private:
+ virtual void increment()
+ {
+ m_index++;
+ }
+ virtual bool equal(port_iterator_base<BlueprintFramework> const& other) const
+ {
+ const static_port_iterator *other_iterator = dynamic_cast<const static_port_iterator *> (other.get_ptr());
+ return
+ (
+ other_iterator
+ && (&m_ports == &other_iterator->m_ports)
+ && (m_index == other_iterator->m_index)
+ );
+ }
+ virtual port<BlueprintFramework>& dereference() const
+ {
+ return m_ports[m_index];
+ }
+ virtual port_iterator_base<BlueprintFramework> * clone() const
+ {
+ return new static_port_iterator(*this);
+ }
+ virtual const port_iterator_base<BlueprintFramework> * get_ptr() const
+ {
+ return this;
+ }
+
+ ptr_vector<port<BlueprintFramework> > &m_ports;
+ unsigned m_index;
+};
+
+
+namespace detail
+{
+ template<typename BlueprintFramework>
+ struct add_ports
+ {
+ add_ports(ptr_vector<port<BlueprintFramework> > &ports, framework_context<BlueprintFramework> &fo)
+ : m_ports(ports)
+ , m_fo(fo)
+ {}
+ template<typename Entity>
+ void operator()(Entity &entity) const
+ {
+ m_ports.push_back(new port_adapter<BlueprintFramework, Entity &>(m_fo, entity));
+ }
+ ptr_vector<port<BlueprintFramework> > &m_ports;
+ framework_context<BlueprintFramework> &m_fo;
+ };
+}
+
+
+template<typename BlueprintFramework, typename VectorOrRef, typename Base=framework_entity<BlueprintFramework> >
+class static_vector_adapter : public framework_entity_adapter<BlueprintFramework, VectorOrRef, Base>
+{
+ typedef framework_entity_adapter<BlueprintFramework, VectorOrRef, Base> base_type;
+public:
+ static_vector_adapter(framework_context<BlueprintFramework> &fo)
+ : base_type(fo)
+ {
+ initialize_ports();
+ }
+ template<typename T>
+ static_vector_adapter(framework_context<BlueprintFramework> &fo, const T &t)
+ : base_type(fo, t)
+ {
+ initialize_ports();
+ }
+ template<typename T>
+ static_vector_adapter(framework_context<BlueprintFramework> &fo, T &t)
+ : base_type(fo, t)
+ {
+ initialize_ports();
+ }
+
+ virtual port_iterator<BlueprintFramework> begin()
+ {
+ return new static_port_iterator<BlueprintFramework>(m_ports);
+ }
+ virtual port_iterator<BlueprintFramework> end()
+ {
+ return new static_port_iterator<BlueprintFramework>(m_ports, m_ports.size());
+ }
+private:
+ void initialize_ports()
+ {
+ fusion::for_each
+ (
+ entities_framework<typename BlueprintFramework::framework_type>(base_type::entity()),
+ detail::add_ports<BlueprintFramework>(m_ports, base_type::framework_context())
+ );
+ }
+
+ ptr_vector<port<BlueprintFramework> > m_ports;
+};
+
+} } } // namespace boost::dataflow::blueprint
+
+#endif // BOOST__DATAFLOW__BLUEPRINT__STATIC_VECTOR_ADAPTER_HPP

Added: sandbox/dataflow-rewrite/boost/dataflow/blueprint/vector.hpp
==============================================================================
--- (empty file)
+++ sandbox/dataflow-rewrite/boost/dataflow/blueprint/vector.hpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -0,0 +1,93 @@
+/*=================================---------------------------------------------
+ Copyright 2007,2008 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)
+-----------------------------------------------===============================*/
+
+#ifndef BOOST__DATAFLOW__BLUEPRINT__VECTOR_HPP
+#define BOOST__DATAFLOW__BLUEPRINT__VECTOR_HPP
+
+
+#include <boost/dataflow/blueprint/port.hpp>
+#include <boost/iterator/iterator_facade.hpp>
+
+namespace boost { namespace dataflow { namespace blueprint {
+
+template<typename BlueprintFramework>
+class port_iterator_base
+ : public boost::iterator_facade<
+ port_iterator_base<BlueprintFramework>
+ , port<BlueprintFramework>
+ , boost::forward_traversal_tag>
+{
+public:
+ virtual ~port_iterator_base(){}
+ friend class boost::iterator_core_access;
+
+ virtual void increment()=0;
+ virtual bool equal(port_iterator_base const& other) const =0;
+ virtual port<BlueprintFramework>& dereference() const =0;
+ virtual port_iterator_base * clone() const =0;
+ virtual const port_iterator_base * get_ptr() const =0;
+};
+
+template<typename BlueprintFramework>
+class port_iterator
+ : public port_iterator_base<BlueprintFramework>
+{
+public:
+ port_iterator(port_iterator_base<BlueprintFramework> *ptr)
+ : m_ptr(ptr)
+ {}
+ virtual void increment()
+ {
+ if(m_ptr.use_count()!=1)
+ m_ptr.reset(m_ptr->clone());
+ m_ptr->increment();
+ }
+ virtual bool equal(port_iterator_base<BlueprintFramework> const& other) const
+ {
+ return m_ptr->equal(other);
+ }
+ virtual port<BlueprintFramework>& dereference() const
+ {
+ return m_ptr->dereference();
+ }
+ virtual port_iterator_base<BlueprintFramework> * clone() const
+ {
+ return m_ptr->clone();
+ };
+ bool operator==(port_iterator_base<BlueprintFramework> const& other) const
+ {
+ return this->equal(other);
+ }
+ virtual const port_iterator_base<BlueprintFramework> * get_ptr() const
+ {
+ return m_ptr->get_ptr();
+ }
+private:
+ shared_ptr<port_iterator_base<BlueprintFramework> > m_ptr;
+};
+
+
+template<typename BlueprintFramework>
+class vector : public framework_entity<BlueprintFramework>
+{
+ typedef framework_entity<BlueprintFramework> base_type;
+public:
+ vector(framework_context<BlueprintFramework> &fo, const std::type_info &ti)
+ : base_type(fo, ti)
+ {}
+ struct dataflow_traits : public base_type::dataflow_traits
+ {
+ typedef port<BlueprintFramework> entity;
+ };
+ virtual port_iterator<BlueprintFramework> begin()=0;
+ virtual port_iterator<BlueprintFramework> end()=0;
+};
+
+} } } // namespace boost::dataflow::blueprint
+
+#endif // BOOST__DATAFLOW__BLUEPRINT__VECTOR_HPP

Modified: sandbox/dataflow-rewrite/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj
==============================================================================
--- sandbox/dataflow-rewrite/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj (original)
+++ sandbox/dataflow-rewrite/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -197,6 +197,8 @@
                 08BA454B0EDCF1A00053808D /* my_dynamic_vector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = my_dynamic_vector.hpp; sourceTree = "<group>"; };
                 08D18D770EBE25E800B1A160 /* static_vector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = static_vector.hpp; sourceTree = "<group>"; };
                 08D6B0BA0EDE06A8005821A8 /* test_entities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_entities.cpp; sourceTree = "<group>"; };
+ 08D6B0DE0EDE1F55005821A8 /* static_vector_adapter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = static_vector_adapter.hpp; sourceTree = "<group>"; };
+ 08D6B0E50EDE2101005821A8 /* vector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = vector.hpp; sourceTree = "<group>"; };
                 08D965820E83A2F900087C6F /* framework_entity.qbk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = framework_entity.qbk; sourceTree = "<group>"; };
                 08D965C80E83A94E00087C6F /* category.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = category.hpp; sourceTree = "<group>"; };
                 08D965C90E83A94E00087C6F /* port.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = port.hpp; sourceTree = "<group>"; };
@@ -548,6 +550,8 @@
                                 0826E38D0EA542730090AB4E /* operation.hpp */,
                                 0826E3950EA543F60090AB4E /* operation_adapter.hpp */,
                                 0826E4BB0EA57D110090AB4E /* castable_polymorphic_object.hpp */,
+ 08D6B0DE0EDE1F55005821A8 /* static_vector_adapter.hpp */,
+ 08D6B0E50EDE2101005821A8 /* vector.hpp */,
                         );
                         path = blueprint;
                         sourceTree = "<group>";

Modified: sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/my_blueprint_static_vector.hpp
==============================================================================
--- sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/my_blueprint_static_vector.hpp (original)
+++ sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/my_blueprint_static_vector.hpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -10,3 +10,6 @@
 #include "my_blueprint_framework.hpp"
 #include "../generic/my_static_vector.hpp"
 
+#include <boost/dataflow/blueprint/static_vector_adapter.hpp>
+
+typedef df::blueprint::static_vector_adapter<my_blueprint_framework, my_static_vector> my_blueprint_static_vector;
\ No newline at end of file

Modified: sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/test_static_vector.cpp
==============================================================================
--- sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/test_static_vector.cpp (original)
+++ sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/test_static_vector.cpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -18,4 +18,11 @@
 BOOST_AUTO_TEST_CASE( test )
 {
     my_blueprint_framework_context fo;
+ my_blueprint_static_vector vector(fo, my_static_vector(2.5, 1));
+ df::blueprint::port_iterator<my_blueprint_framework> it = vector.begin();
+ BOOST_CHECK_EQUAL(it->get_as<float>(), 2.5);
+ ++it;
+ BOOST_CHECK_EQUAL(it->get_as<int>(), 1);
+ ++it;
+ BOOST_CHECK(it == vector.end());
 }
\ No newline at end of file

Modified: sandbox/dataflow-rewrite/libs/dataflow/test/generic/my_static_vector.hpp
==============================================================================
--- sandbox/dataflow-rewrite/libs/dataflow/test/generic/my_static_vector.hpp (original)
+++ sandbox/dataflow-rewrite/libs/dataflow/test/generic/my_static_vector.hpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -17,13 +17,13 @@
 #include <boost/fusion/include/value_at.hpp>
 #include <boost/fusion/include/at.hpp>
 
-typedef df::static_vector_traits<boost::fusion::vector2<float, int> > my_traits;
+typedef df::static_vector_traits<boost::fusion::vector2<float, int>, my_framework> my_traits;
 
 namespace df=boost::dataflow;
 
-struct tuple
+struct my_static_vector
 {
- tuple(float f, int i)
+ my_static_vector(float f, int i)
         : ports(f,i) {}
     
     typedef my_traits dataflow_traits;

Modified: sandbox/dataflow-rewrite/libs/dataflow/test/generic/test_entities.cpp
==============================================================================
--- sandbox/dataflow-rewrite/libs/dataflow/test/generic/test_entities.cpp (original)
+++ sandbox/dataflow-rewrite/libs/dataflow/test/generic/test_entities.cpp 2008-11-30 19:35:44 EST (Sun, 30 Nov 2008)
@@ -19,9 +19,9 @@
 
 BOOST_AUTO_TEST_CASE( test )
 {
- tuple x(0.5, 2);
+ my_static_vector x(0.5, 2);
     
- typedef df::result_of::entities<tuple>::type result_of_entities;
+ typedef df::result_of::entities<my_static_vector>::type result_of_entities;
     
     BOOST_CHECK((boost::is_same<result_of_entities, ::boost::fusion::vector2<float,int> & >::value));
     


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