|
Boost-Commit : |
From: stipe_at_[hidden]
Date: 2008-03-14 01:09:09
Author: srajko
Date: 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
New Revision: 43598
URL: http://svn.boost.org/trac/boost/changeset/43598
Log:
binary operations propagate return value, added tracking_call_consumer example
Added:
sandbox/SOC/2007/signals/libs/dataflow/example/signals/tracking_consumer_example.cpp (contents, props changed)
sandbox/SOC/2007/signals/libs/dataflow/test/signals/test_connect_result.cpp (contents, props changed)
Text files modified:
sandbox/SOC/2007/signals/boost/dataflow/signals/support.hpp | 6 +++---
sandbox/SOC/2007/signals/boost/dataflow/support/binary_operation.hpp | 26 ++++++++++++++++++++++++--
sandbox/SOC/2007/signals/boost/dataflow/support/keyed_port.hpp | 38 +++++++++++++++++++++++++++++++-------
sandbox/SOC/2007/signals/boost/dataflow/templates/binary_operation.hpp | 32 ++++++++++++++++++++++++--------
sandbox/SOC/2007/signals/libs/dataflow/build/xcodeide/dataflow.xcodeproj/project.pbxproj | 4 ++++
sandbox/SOC/2007/signals/libs/dataflow/doc/introduction/introduction.qbk | 8 ++++++++
sandbox/SOC/2007/signals/libs/dataflow/example/signals/Jamfile.v2 | 3 ++-
sandbox/SOC/2007/signals/libs/dataflow/test/signals/Jamfile.v2 | 1 +
sandbox/SOC/2007/signals/libs/dataflow/test/signals/test_disconnect.cpp | 13 +++++++++++--
9 files changed, 108 insertions(+), 23 deletions(-)
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 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -127,12 +127,12 @@
template<typename T>
struct binary_operation_impl<signals::producer<T>, signals::consumer<T>, operations::connect>
{
- typedef void result_type;
+ typedef boost::signals::connection result_type;
template<typename Producer, typename Consumer>
- void operator()(Producer &producer, Consumer &consumer)
+ result_type operator()(Producer &producer, Consumer &consumer)
{
- producer.connect(consumer);
+ return producer.connect(consumer);
}
};
Modified: sandbox/SOC/2007/signals/boost/dataflow/support/binary_operation.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/support/binary_operation.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/support/binary_operation.hpp 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -25,11 +25,33 @@
namespace boost { namespace dataflow {
+namespace result_of
+{
+ template<typename OutgoingPort, typename IncomingPort, typename Operation, typename Mechanism, typename Tag>
+ struct default_binary_operation
+ {
+ typedef typename result_of::binary_operation<
+ typename boost::remove_reference<typename result_of::get_default_port<OutgoingPort, args::left, Mechanism, Tag>::type>::type,
+ typename boost::remove_reference<typename result_of::get_default_port<IncomingPort, args::right, Mechanism, Tag>::type>::type,
+ Operation,
+ Tag>::type type;
+/* typedef
+ typename boost::result_of<
+ extension::binary_operation_impl<
+ typename default_traits_of<OutgoingPort, args::left, Mechanism, Tag>::type,
+ typename default_traits_of<IncomingPort, args::right, Mechanism, Tag>::type,
+ Operation>(
+ typename utility::forwardable<typename result_of::get_default_port<OutgoingPort, args::left, Mechanism, Tag>::type>::type,
+ typename utility::forwardable<typename result_of::get_default_port<IncomingPort, args::right, Mechanism, Tag>::type>::type)
+ >::type type;*/
+ };
+}
+
template<typename Operation, typename Mechanism, typename Tag, typename OutgoingPort, typename IncomingPort>
-inline void
+inline typename result_of::default_binary_operation<OutgoingPort, IncomingPort, Operation, Mechanism, Tag>::type
default_binary_operation(OutgoingPort &left, IncomingPort &right)
{
- extension::binary_operation_impl<
+ return extension::binary_operation_impl<
typename default_traits_of<OutgoingPort, args::left, Mechanism, Tag>::type,
typename default_traits_of<IncomingPort, args::right, Mechanism, Tag>::type,
Operation>
Modified: sandbox/SOC/2007/signals/boost/dataflow/support/keyed_port.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/support/keyed_port.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/support/keyed_port.hpp 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -109,12 +109,24 @@
// has_keyed_port<port<ProducerTag>, ConsumerTag, typename ProducerTag::tag>
>::type >
{
- typedef void result_type;
+ template<typename FArgs>
+ struct result;
+
+ template<typename F, typename Producer, typename Consumer>
+ struct result<F(Producer &, Consumer &)>
+ {
+ typedef typename result_of::binary_operation<
+ typename remove_reference<typename result_of::get_keyed_port<Producer, ConsumerTag, typename ProducerTag::tag>::type>::type,
+ Consumer,
+ Operation,
+ typename ConsumerTag::tag
+ >::type type;
+ };
template<typename Producer, typename Consumer>
- void operator()(Producer &producer, Consumer &consumer)
+ typename result<binary_operation_impl(Producer &, Consumer &)>::type operator()(Producer &producer, Consumer &consumer)
{
- binary_operation<Operation, typename ConsumerTag::tag>
+ return binary_operation<Operation, typename ConsumerTag::tag>
(get_keyed_port<ConsumerTag, typename ProducerTag::tag>(producer), consumer);
}
};
@@ -126,12 +138,24 @@
// has_keyed_port<port<ConsumerTag>, ProducerTag, typename ConsumerTag::tag>
>::type >
{
- typedef void result_type;
-
+ template<typename FArgs>
+ struct result;
+
+ template<typename F, typename Producer, typename Consumer>
+ struct result<F(Producer &, Consumer &)>
+ {
+ typedef typename result_of::binary_operation<
+ Producer,
+ typename remove_reference<typename result_of::get_keyed_port<Consumer, ProducerTag, typename ConsumerTag::tag>::type>::type,
+ Operation,
+ typename ProducerTag::tag
+ >::type type;
+ };
+
template<typename Producer, typename Consumer>
- void operator()(Producer &producer, Consumer &consumer)
+ typename result<binary_operation_impl(Producer &, Consumer &)>::type operator()(Producer &producer, Consumer &consumer)
{
- binary_operation<Operation, typename ProducerTag::tag>
+ return binary_operation<Operation, typename ProducerTag::tag>
(producer, get_keyed_port<ProducerTag, typename ConsumerTag::tag>(consumer));
}
};
Modified: sandbox/SOC/2007/signals/boost/dataflow/templates/binary_operation.hpp
==============================================================================
--- sandbox/SOC/2007/signals/boost/dataflow/templates/binary_operation.hpp (original)
+++ sandbox/SOC/2007/signals/boost/dataflow/templates/binary_operation.hpp 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -15,25 +15,41 @@
#endif
template<typename Producer, typename Consumer>
-inline void DATAFLOW_TEMPLATE_BINARY_OPERATION(Producer &producer, Consumer &consumer)
+inline typename boost::dataflow::result_of::default_binary_operation<
+ Producer, Consumer,
+ boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG
+>::type
+ DATAFLOW_TEMPLATE_BINARY_OPERATION(Producer &producer, Consumer &consumer)
{
- boost::dataflow::default_binary_operation< boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG >(producer, consumer);
+ return boost::dataflow::default_binary_operation< boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG >(producer, consumer);
}
template<typename Producer, typename Consumer>
-inline void DATAFLOW_TEMPLATE_BINARY_OPERATION(Producer &producer, const Consumer &consumer)
+inline typename boost::dataflow::result_of::default_binary_operation<
+ Producer, const Consumer,
+ boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG
+>::type
+ DATAFLOW_TEMPLATE_BINARY_OPERATION(Producer &producer, const Consumer &consumer)
{
- boost::dataflow::default_binary_operation< boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG >(producer, consumer);
+ return boost::dataflow::default_binary_operation< boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG >(producer, consumer);
}
template<typename Producer, typename Consumer>
-inline void DATAFLOW_TEMPLATE_BINARY_OPERATION(const Producer &producer, Consumer &consumer)
+inline typename boost::dataflow::result_of::default_binary_operation<
+ const Producer, Consumer,
+ boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG
+>::type
+ DATAFLOW_TEMPLATE_BINARY_OPERATION(const Producer &producer, Consumer &consumer)
{
- boost::dataflow::default_binary_operation< boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG >(producer, consumer);
+ return boost::dataflow::default_binary_operation< boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG >(producer, consumer);
}
template<typename Producer, typename Consumer>
-inline void DATAFLOW_TEMPLATE_BINARY_OPERATION(const Producer &producer, const Consumer &consumer)
+inline typename boost::dataflow::result_of::default_binary_operation<
+ const Producer, const Consumer,
+ boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG
+>::type
+ DATAFLOW_TEMPLATE_BINARY_OPERATION(const Producer &producer, const Consumer &consumer)
{
- boost::dataflow::default_binary_operation< boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG >(producer, consumer);
+ return boost::dataflow::default_binary_operation< boost::dataflow::operations::DATAFLOW_TEMPLATE_BINARY_OPERATION, DATAFLOW_TEMPLATE_MECHANISM, DATAFLOW_TEMPLATE_TAG >(producer, consumer);
}
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-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -91,6 +91,8 @@
0815AEC90D0B814E007ED135 /* test_complemented_port.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_complemented_port.cpp; sourceTree = "<group>"; };
08256FE60CEBDFEC003EC1B4 /* network.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = network.hpp; sourceTree = "<group>"; };
082761BE0C6037A90030E557 /* invocable.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = invocable.hpp; sourceTree = "<group>"; };
+ 083F14A50D8A250700D0F8B7 /* test_connect_result.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_connect_result.cpp; sourceTree = "<group>"; };
+ 083F151E0D8A356500D0F8B7 /* tracking_consumer_example.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tracking_consumer_example.cpp; sourceTree = "<group>"; };
083FD3B90C62A4CB00EF3F6B /* concepts.qbk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = concepts.qbk; sourceTree = "<group>"; };
083FD3C10C62A75B00EF3F6B /* concepts.qbk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = concepts.qbk; sourceTree = "<group>"; };
083FD3C60C62A7F600EF3F6B /* phoenix.qbk */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = phoenix.qbk; sourceTree = "<group>"; };
@@ -760,6 +762,7 @@
08F71D500CA3547C0010099E /* test_storage.cpp */,
08FBDA3A0CD272ED00CC3891 /* test_multiplexer.cpp */,
089B93720D5AA99700F6EEAA /* test_filter_base.cpp */,
+ 083F14A50D8A250700D0F8B7 /* test_connect_result.cpp */,
);
path = signals;
sourceTree = "<group>";
@@ -774,6 +777,7 @@
08F98B470CD01963009D642B /* intro_example.cpp */,
084D2E6E0CE7DFE900E861FA /* gil_example.cpp */,
08A0E54C0D7A7674009B11DD /* quick_start_examples.cpp */,
+ 083F151E0D8A356500D0F8B7 /* tracking_consumer_example.cpp */,
);
path = signals;
sourceTree = "<group>";
Modified: sandbox/SOC/2007/signals/libs/dataflow/doc/introduction/introduction.qbk
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/doc/introduction/introduction.qbk (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/doc/introduction/introduction.qbk 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -403,6 +403,14 @@
The Dataflow library uses the trunk version of Boost - it might not work
perfectly with release versions of boost.
+Version 0.9.1 (under development)
+* Generic Dataflow layer
+ * binary operations now propagate the return value
+
+* [DataflowSignals]
+ * [connect] now returns the `signals::connection` object
+ * added tracking_call_consumer example
+
Version 0.9.0
\[[@http://www.boost-consulting.com/vault/index.php?direction=&order=&directory=Dataflow& available in the Boost vault]\]
Modified: sandbox/SOC/2007/signals/libs/dataflow/example/signals/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/example/signals/Jamfile.v2 (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/signals/Jamfile.v2 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -17,4 +17,5 @@
/boost/thread//boost_thread/<link>static
/boost/system//boost_system/<link>static ;
exe gil_example : gil_example.cpp /boost/thread//boost_thread/<link>static ;
-exe quick_start_examples : quick_start_examples.cpp ;
\ No newline at end of file
+exe quick_start_examples : quick_start_examples.cpp ;
+exe tracking_consumer_example : tracking_consumer_example.cpp ;
\ No newline at end of file
Added: sandbox/SOC/2007/signals/libs/dataflow/example/signals/tracking_consumer_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/example/signals/tracking_consumer_example.cpp 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -0,0 +1,113 @@
+// Copyright 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)
+
+#include <boost/dataflow/signals/component/storage.hpp>
+
+#include <boost/foreach.hpp>
+
+#include <iostream>
+
+namespace boost { namespace dataflow {
+
+namespace signals {
+
+ // we're making a new PortTraits for a operator() consumer that can track
+ struct tracking_call_consumer
+ : public port_traits<ports::consumer, tag>
+ {};
+
+} // namespace signals
+
+namespace extension {
+
+ // here we specialize the connect operation
+ template<typename T>
+ struct binary_operation_impl<signals::producer<T>, signals::tracking_call_consumer, operations::connect>
+ {
+ typedef boost::signals::connection result_type;
+
+ template<typename Producer, typename Consumer>
+ result_type operator()(Producer &producer, Consumer &consumer)
+ {
+ // object_type is so that a port_adapter can be used on the consumer
+ typedef typename get_object_type<Consumer>::type object_type;
+ typedef typename boost::dataflow::utility::slot_type<T, object_type>::type mem_fn_type;
+
+ // grab the correct overload of operator()
+ boost::function<T> mem_fn = boost::dataflow::utility::bind_mem_fn<mem_fn_type, object_type>
+ (static_cast<mem_fn_type>(&object_type::operator()), get_object(consumer));
+
+ // make the connection, register it with the consumer
+ result_type connection = producer.connect(mem_fn);
+ get_object(consumer).register_connection(connection);
+ return connection;
+ }
+ };
+
+} // namespace extension
+
+} } // namespace boost::dataflow
+
+using namespace boost;
+namespace df = boost::dataflow;
+
+// simple consumer that tracks its connections - when it receives a specified
+// number of signals, it will disconnect itself from all producers
+class trackable_consumer
+ : public df::port<df::signals::tracking_call_consumer>
+{
+public:
+ trackable_consumer(unsigned max_count)
+ : m_count(0), m_max_count(max_count)
+ {}
+
+ void operator()()
+ {
+ m_count++;
+ if (m_count >= m_max_count)
+ disconnect_all();
+ }
+
+ void register_connection(const signals::connection &connection)
+ { m_connections.push_back(connection); }
+
+ unsigned count()
+ { return m_count; }
+
+private:
+ void disconnect_all()
+ {
+ BOOST_FOREACH(signals::connection &c, m_connections)
+ c.disconnect();
+ m_connections.clear();
+ }
+
+ typedef std::vector<signals::connection> connections_type;
+ connections_type m_connections;
+ unsigned m_count, m_max_count;
+};
+
+int main(int, char* [])
+{
+ signals::storage<void()> producer;
+ trackable_consumer c1(1), c3(3), c5(5);
+
+ connect(producer, c1);
+ connect(producer, c3);
+ connect(producer, c5);
+
+ // send out 5 signals. c1 should disconnect after 1, c3 after 3, c5 after 5
+ for(int i=0; i<5; i++)
+ producer();
+
+ std::cout << c1.count() << std::endl; // 1
+ std::cout << c3.count() << std::endl; // 3
+ std::cout << c5.count() << std::endl; // 5
+
+ // get_port_c<0> will retreive the signal - there are no more consumers connected
+ std::cout << df::get_port_c<0, df::signals::tag>(producer).num_slots() << std::endl; // 0
+
+ return 0;
+}
Modified: sandbox/SOC/2007/signals/libs/dataflow/test/signals/Jamfile.v2
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/test/signals/Jamfile.v2 (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/test/signals/Jamfile.v2 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -17,6 +17,7 @@
run test_bind_object.cpp ;
run test_connect.cpp ;
+run test_connect_result.cpp ;
run test_filter.cpp ;
run test_storage.cpp ;
Added: sandbox/SOC/2007/signals/libs/dataflow/test/signals/test_connect_result.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/signals/libs/dataflow/test/signals/test_connect_result.cpp 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -0,0 +1,34 @@
+// Copyright Stjepan Rajko 2008. Use, modification and
+// distribution is subject to 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 <boost/dataflow/signals/support.hpp>
+#include <boost/dataflow/signals/component/storage.hpp>
+
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/test/included/test_exec_monitor.hpp>
+
+void func()
+{}
+
+int test_main(int, char* [])
+{
+ namespace df = boost::dataflow;
+ using namespace boost;
+
+ BOOST_CHECK((boost::is_same<
+ df::result_of::binary_operation<boost::signal<void()>, boost::function<void()>, df::operations::connect, df::signals::tag>::type,
+ signals::connection>::type::value));
+
+ BOOST_CHECK((boost::is_same<
+ df::result_of::default_binary_operation<boost::signal<void()>, boost::function<void()>, df::operations::connect, df::signals::connect_mechanism, df::signals::tag>::type,
+ signals::connection>::type::value));
+
+ BOOST_CHECK((boost::is_same<
+ df::result_of::default_binary_operation<signals::storage<void ()>, signals::storage<void ()>, df::operations::connect, df::signals::connect_mechanism, df::signals::tag>::type,
+ signals::connection>::type::value));
+
+ return 0;
+}
Modified: sandbox/SOC/2007/signals/libs/dataflow/test/signals/test_disconnect.cpp
==============================================================================
--- sandbox/SOC/2007/signals/libs/dataflow/test/signals/test_disconnect.cpp (original)
+++ sandbox/SOC/2007/signals/libs/dataflow/test/signals/test_disconnect.cpp 2008-03-14 01:09:08 EDT (Fri, 14 Mar 2008)
@@ -21,11 +21,20 @@
connect(banger, counter);
banger(); // this signal will pass to counter
+ BOOST_CHECK_EQUAL(counter.count(), 1);
+
disconnect_all(banger);
banger(); // this signal will not pass to counter
-
BOOST_CHECK_EQUAL(counter.count(), 1);
- //]
+
+ signals::connection c = connect(banger, counter);
+ banger(); // this signal will pass to counter
+ BOOST_CHECK_EQUAL(counter.count(), 2);
+
+ c.disconnect();
+ banger(); // this signal will not pass to counter
+ BOOST_CHECK_EQUAL(counter.count(), 2);
+//]
}
return 0;
} // int test_main(int, char* [])
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