With the pair of producer Port
and consumer Port
registered, we can make them Connectable
and/or OnlyConnectable.
All we need to do is specialize the implementation for the appropriate
PortTraits:
namespace boost { namespace dataflow { namespace extension { // To implement Connectable, we specialize the binary_operation_impl // functor template. We specify three things: // producer PortTraits (vtk::vtk_algorithm_output_producer) // consumer PortTraits (vtk::vtk_algorithm_consumer) // operation (operations::connect) template<> struct binary_operation_impl<vtk::vtk_algorithm_output_producer, vtk::vtk_algorithm_consumer, operations::connect> { typedef void result_type; template<typename Producer, typename Consumer> void operator()(Producer &producer, Consumer &consumer) { // To interface with port_adaptor objects, we use get_object get_object(consumer).AddInputConnection(&get_object(producer)); } }; // To implement OnlyConnectable, we do the same thing except now the operation // is operations::connect_only template<> struct binary_operation_impl<vtk::vtk_algorithm_output_producer, vtk::vtk_algorithm_consumer, operations::connect_only> { typedef void result_type; template<typename Producer, typename Consumer> void operator()(Producer &producer, Consumer &consumer) { get_object(consumer).SetInputConnection(&get_object(producer)); } }; } } } // namespace boost::dataflow::vtk
Connections are done through the boost::dataflow::binary_operation
function with either operation::connect
or operation::connect_only operation, and a specified
framework tag. In the next step, we'll set up forwarding functions and
operators that will make connections easier.
What we can do with what we have so far
using namespace boost::dataflow; // connect *cone to *coneMapper binary_operation<operations::connect, vtk::tag> (*cone->GetOutputPort(), vtk::vtk_algorithm_consumer_adapter(*coneMapper)); // make *cone the only thing connected to *coneMapper binary_operation<operations::connect_only, vtk::tag> (*cone->GetOutputPort(), vtk::vtk_algorithm_consumer_adapter(*coneMapper));