Boost logo

Boost-Commit :

From: stipe_at_[hidden]
Date: 2007-12-23 13:19:59


Author: srajko
Date: 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
New Revision: 42262
URL: http://svn.boost.org/trac/boost/changeset/42262

Log:
added runtime keyed_port support, fixed signals support to include extraction
Text files modified:
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation.hpp | 8 +++-
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation_t.hpp | 51 ++++++++++++++++++++------
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/keyed_port_t.hpp | 59 +++++++++++++++++++++++++++++-
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/port.hpp | 14 +++++++
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/port_t.hpp | 10 +++-
   sandbox/SOC/2007/signals/boost/dataflow/blueprint/vector_port_t.hpp | 8 ++-
   sandbox/SOC/2007/signals/boost/dataflow/signals/component/filter_base.hpp | 2 +
   sandbox/SOC/2007/signals/boost/dataflow/signals/component/storage.hpp | 38 ++++++++++++++++++-
   sandbox/SOC/2007/signals/boost/dataflow/signals/support.hpp | 76 ++++++++++++++++++++++++++++++++-------
   9 files changed, 225 insertions(+), 41 deletions(-)

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -24,16 +24,20 @@
 {
     if (outgoing.is_complemented_port())
     {
+ port &resolved_incoming = incoming.resolve_key(outgoing);
+
         return outgoing.as<complemented_port>().template is_operable_port_to_complement<Operation>()
             && (outgoing.as<complemented_port>().complement_type_info()
- == incoming.port_type_info());
+ == resolved_incoming.port_type_info());
     }
 
     if (incoming.is_complemented_port())
     {
+ port &resolved_outgoing = outgoing.resolve_key(outgoing);
+
         return incoming.as<complemented_port>().template is_operable_complement_to_port<Operation>()
             && (incoming.as<complemented_port>().complement_type_info()
- == outgoing.port_type_info());
+ == resolved_outgoing.port_type_info());
     }
 
     return false;

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation_t.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation_t.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/binary_operation_t.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -8,18 +8,22 @@
 
 #include <boost/dataflow/blueprint/binary_operation.hpp>
 #include <boost/dataflow/support/binary_operation.hpp>
+#include <boost/dataflow/support/keyed_port.hpp>
+
+
+#include <iostream>
 
 namespace boost { namespace dataflow { namespace blueprint {
 
 namespace detail
 {
- template <typename Operation, typename Mechanism, typename ProducerPort, typename ConsumerPort>
+ template <typename ProducerPort, typename ConsumerPort, typename Operation, typename Tag>
     typename disable_if<
             dataflow::are_binary_operable<
- Operation,
- Mechanism,
                 ProducerPort,
- ConsumerPort
+ ConsumerPort,
+ Operation,
+ Tag
>
>::type
     call_binary_operation(port &producer, port &consumer)
@@ -27,30 +31,51 @@
         throw std::exception();
     }
     
- template <typename Operation, typename Mechanism, typename ProducerPort, typename ConsumerPort>
+ template <typename ProducerPort, typename ConsumerPort, typename Operation, typename Tag>
     typename enable_if<
             dataflow::are_binary_operable<
- Operation,
- Mechanism,
                 ProducerPort,
- ConsumerPort
+ ConsumerPort,
+ Operation,
+ Tag
>
>::type
     call_binary_operation(port &producer, port &consumer)
     {
- dataflow::binary_operation<Operation, Mechanism>(
- any_cast<ProducerPort &>(producer.get()),
- any_cast<ConsumerPort &>(consumer.get()));
+ typedef typename mpl::if_<
+ is_keyed_port<ProducerPort>,
+ typename remove_reference<
+ typename result_of::get_keyed_port<
+ ProducerPort,
+ typename traits_of<ConsumerPort, Tag>::type,
+ Tag>::type>::type,
+ ProducerPort>::type * resolved_producer_type;
+
+ typedef typename mpl::if_<
+ is_keyed_port<ConsumerPort>,
+ typename remove_reference<
+ typename result_of::get_keyed_port<
+ ConsumerPort,
+ typename traits_of<ProducerPort, Tag>::type,
+ Tag>::type>::type,
+ ConsumerPort>::type * resolved_consumer_type;
+
+ any any_producer = producer.resolve_key(consumer).get(),
+ any_consumer = consumer.resolve_key(producer).get();
+
+ dataflow::binary_operation<Operation, Tag>(
+ *any_cast<resolved_producer_type>(any_producer),
+ *any_cast<resolved_consumer_type>(any_consumer));
     }
 }
 
-template <typename Operation, typename Mechanism, typename ProducerPort, typename ConsumerPort, typename Enable=void>
+template <typename ProducerPort, typename ConsumerPort, typename Operation, typename Tag, typename Enable=void>
 class binary_operation_t : public binary_operation<Operation>
 {
 public:
     void invoke(port &producer, port &consumer)
     {
- detail::call_binary_operation<Operation, Mechanism, ProducerPort, ConsumerPort>(
+ detail::call_binary_operation<ProducerPort, ConsumerPort, Operation, Tag>(
             producer, consumer);
     }
     virtual std::auto_ptr<binary_operation<Operation> > copy() const

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/keyed_port_t.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/keyed_port_t.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/keyed_port_t.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -9,9 +9,36 @@
 #include <boost/dataflow/blueprint/vector_port_t.hpp>
 #include <boost/dataflow/support/keyed_port.hpp>
 
+#include <boost/array.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/identity.hpp>
 
 namespace boost { namespace dataflow { namespace blueprint {
 
+namespace detail {
+
+ template<typename T>
+ struct wrap_identity
+ {
+ typedef mpl::identity<T> type;
+ };
+
+ template<typename Array>
+ struct fill_type_info
+ {
+ fill_type_info(Array &array) : m_array(array), it() {}
+
+ template<typename T>
+ void operator()(T)
+ {
+ m_array[it++]=&typeid(typename T::type);
+ }
+
+ Array &m_array;
+ int it;
+ };
+}
+
 template<typename PortOrRef, typename Tag>
 class port_t<
     PortOrRef,
@@ -23,16 +50,42 @@
>::type >
     : public detail::vector_port_impl<keyed_port, PortOrRef, Tag>
 {
+ typedef array<
+ const std::type_info *,
+ mpl::size<typename port_t::port_traits_type::port_keys>::type::value
+ > array_type;
+
 public:
     port_t(typename call_traits<PortOrRef>::param_type p)
         : detail::vector_port_impl<keyed_port, PortOrRef, Tag>(p)
- {}
+ {
+ mpl::for_each<
+ typename port_t::port_traits_type::port_keys,
+ detail::wrap_identity<mpl::_>
+ > (detail::fill_type_info<array_type>(m_type_info));
+ }
     
     virtual port *clone() const
     {
         return new port_t(*this);
- };
-
+ }
+
+ bool has_key(const std::type_info &info)
+ {
+ for(typename array_type::iterator it=m_type_info.begin(); it!= m_type_info.end(); it++)
+ if (**it == info)
+ return true;
+ return false;
+ }
+ port &get_keyed_port(const std::type_info &info)
+ {
+ for(typename array_type::iterator it=m_type_info.begin(); it!= m_type_info.end(); it++)
+ if (**it == info)
+ return port_t::m_ports[it - m_type_info.begin()];
+ throw std::exception();
+ }
+private:
+ array_type m_type_info;
 };
 
 } } } // namespace boost::dataflow::blueprint

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/port.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/port.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/port.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -37,6 +37,7 @@
 
 class complemented_port;
 class vector_port;
+class keyed_port;
 
 /// Base class for all blueprint port types. Run-time analogue of the Port concept.
 class port
@@ -60,8 +61,10 @@
 
     virtual boost::any get()=0;
     virtual const std::type_info &port_type_info()=0;
+ virtual const std::type_info &port_traits_type_info()=0;
     virtual ~port() {};
     virtual port *clone() const =0;
+ port &resolve_key(port &key);
 private:
     port_traits traits_;
 };
@@ -151,8 +154,19 @@
 
     virtual bool is_keyed_port() const
     { return true; }
+ virtual bool has_key(const std::type_info &info)=0;
+ virtual port &get_keyed_port(const std::type_info &info)=0;
 };
 
+inline port &port::resolve_key(port &key)
+{
+ port *resolved = this;
+ while (resolved->is_keyed_port() &&
+ resolved->as<keyed_port>().has_key(key.port_traits_type_info()))
+ resolved = &resolved->as<keyed_port>().get_keyed_port(key.port_traits_type_info());
+ return *resolved;
+}
+
 } } } // namespace boost::dataflow::blueprint
 
 namespace boost

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/port_t.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/port_t.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/port_t.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -40,8 +40,12 @@
     {
         return typeid(port_type);
     };
+ virtual const std::type_info &port_traits_type_info()
+ {
+ return typeid(port_traits_type);
+ };
 protected:
- PortOrRef p;
+ typename remove_const<PortOrRef>::type p;
 };
 
 template<typename PortOrRef, typename Tag=default_tag, typename Enable=void>
@@ -77,15 +81,15 @@
     struct operation_type
     {
         typedef blueprint::binary_operation_t<
- Operation,
             port_type,
             typename port_traits_type::complement_port_type,
+ Operation,
             Tag
> p_to_c;
         typedef blueprint::binary_operation_t<
- Operation,
             typename port_traits_type::complement_port_type,
             port_type,
+ Operation,
             Tag
> c_to_p;
     };

Modified: sandbox/SOC/2007/signals/boost/dataflow/blueprint/vector_port_t.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/blueprint/vector_port_t.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/blueprint/vector_port_t.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -22,6 +22,7 @@
     class vector_port_impl
         : public port_t_base<Base, PortOrRef, Tag>
     {
+ protected:
         typedef typename vector_port_impl::port_type port_type;
         typedef typename vector_port_impl::port_traits_type port_traits_type;
 
@@ -38,16 +39,17 @@
         }
         port & get_port(int port_num)
         {
- return ports[port_num];
+ return m_ports[port_num];
         }
 
+ protected:
+ ptr_vector<port> m_ports;
     private:
         void port_t_()
         {
             for(size_t i=0; i<num_ports(); i++)
- ports.push_back(blueprint::get_port<Tag>(vector_port_impl::p, i));
+ m_ports.push_back(blueprint::get_port<Tag>(vector_port_impl::p, i));
         }
- ptr_vector<port> ports;
     };
 }
 

Modified: sandbox/SOC/2007/signals/boost/dataflow/signals/component/filter_base.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/signals/component/filter_base.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/signals/component/filter_base.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -46,6 +46,8 @@
 template<typename Filter, typename Signal, typename OutSignatures>
 class filter_base : public dataflow::component<filter_component_traits<Filter, Signal, OutSignatures> >
 {
+public:
+ typedef OutSignatures out_signatures_type;
 };
 
 } }

Modified: sandbox/SOC/2007/signals/boost/dataflow/signals/component/storage.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/signals/component/storage.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/signals/component/storage.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -70,10 +70,44 @@
     };
 
 
+//template<typename Storage>
+//struct storage_component_traits
+// : public Storage::base_type::dataflow_traits
+//{};
+
 template<typename Storage>
 struct storage_component_traits
- : public Storage::base_type::dataflow_traits
-{};
+ : public dataflow::fusion_component_traits<
+ fusion::vector<
+ typename Storage::signal_type &,
+ dataflow::port_adapter<
+ Storage,
+ dataflow::signals::call_consumer<typename Storage::out_signatures_type>,
+ dataflow::signals::tag>,
+ dataflow::port_adapter<
+ Storage,
+ dataflow::signals::extract_producer<typename Storage::signature_type>,
+ dataflow::signals::tag>
+ >,
+ mpl::map<
+ mpl::pair<dataflow::default_port_selector
+ <dataflow::directions::outgoing, dataflow::signals::connect_mechanism>,
+ mpl::int_<0> >,
+ mpl::pair<dataflow::default_port_selector
+ <dataflow::directions::incoming, dataflow::signals::connect_mechanism>,
+ mpl::int_<1> >
+ >,
+ dataflow::signals::tag>
+{
+ template<typename Component>
+ static typename storage_component_traits::fusion_ports get_ports(Component &component)
+ {
+ return typename storage_component_traits::fusion_ports(
+ component.default_signal(),
+ component,
+ component);
+ };
+};
 
 /** \brief Stores and transmits arguments received from a signal.
     \param Signature Signature of the signal sent.

Modified: sandbox/SOC/2007/signals/boost/dataflow/signals/support.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/signals/support.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/signals/support.hpp 2007-12-23 13:19:58 EST (Sun, 23 Dec 2007)
@@ -11,6 +11,7 @@
 #include <boost/dataflow/signals/connection/detail/bind_object.hpp>
 
 #include <boost/mpl/vector.hpp>
+#include <boost/mpl/joint_view.hpp>
 #include <boost/signal.hpp>
 
 namespace boost { namespace dataflow {
@@ -35,6 +36,13 @@
     typedef T signature_type;
 };
 
+template<typename T>
+struct extract_producer
+ : public complemented_port_traits<ports::producer, boost::function<T>, tag>
+{
+ typedef T signature_type;
+};
+
 namespace detail
 {
     template<typename T>
@@ -44,6 +52,12 @@
     };
     
     template<typename T>
+ struct wrap_extract_producer
+ {
+ typedef extract_producer<T> type;
+ };
+
+ template<typename T>
     struct wrap_function
     {
         typedef boost::function<T> type;
@@ -54,24 +68,29 @@
 struct call_consumer
     : public keyed_port_traits<
         ports::consumer,
- typename mpl::transform<
- SignatureSequence,
- detail::wrap_producer<mpl::_1>
- >::type,
- typename mpl::transform<
- SignatureSequence,
- detail::wrap_function<mpl::_1>
- >::type,
+ mpl::joint_view<
+ typename mpl::transform<
+ SignatureSequence,
+ detail::wrap_producer<mpl::_1>
+ >::type,
+ typename mpl::transform<
+ SignatureSequence,
+ detail::wrap_extract_producer<mpl::_1>
+ >::type
+ >,
+ mpl::joint_view<
+ typename mpl::transform<
+ SignatureSequence,
+ detail::wrap_function<mpl::_1>
+ >::type,
+ typename mpl::transform<
+ SignatureSequence,
+ detail::wrap_function<mpl::_1>
+ >::type
+ >,
         tag>
 {};
 
-template<typename T>
-struct extract_producer
- : public complemented_port_traits<ports::producer, boost::function<T>, tag>
-{
- typedef T signature_type;
-};
-
 } // namespace signals
 
 template<typename Signature, typename Combiner, typename Group, typename GroupCompare>
@@ -114,6 +133,33 @@
             producer.connect(consumer);
         }
     };
+
+ template<typename SignatureSequence, typename Signature>
+ struct get_keyed_port_impl<signals::call_consumer<SignatureSequence>, signals::extract_producer<Signature> >
+ {
+ typedef const boost::function<Signature> result_type;
+
+ template<typename ConsumerPort>
+ result_type operator()(ConsumerPort &consumer)
+ {
+ typedef typename get_object_type<ConsumerPort>::type object_type;
+
+ return boost::signals::detail::bind_object<Signature, object_type>()
+ (static_cast<typename boost::signals::detail::slot_type<Signature, object_type>::type>(&object_type::operator()), get_object(consumer));
+ };
+ };
+
+ template<typename T>
+ struct binary_operation_impl<signals::extract_producer<T>, signals::consumer<T>, operations::extract>
+ {
+ typedef void result_type;
+
+ template<typename Producer, typename Consumer>
+ void operator()(Producer &producer, Consumer &consumer)
+ {
+ get_object(producer).call(consumer);
+ }
+ };
 }
 
 } } // namespace boost::dataflow


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