Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50081 - in sandbox/dataflow-rewrite: boost/dataflow/blueprint libs/dataflow/test/blueprint
From: stipe_at_[hidden]
Date: 2008-12-02 19:51:35


Author: srajko
Date: 2008-12-02 19:51:34 EST (Tue, 02 Dec 2008)
New Revision: 50081
URL: http://svn.boost.org/trac/boost/changeset/50081

Log:
blueprint factory allows additional arguments
Text files modified:
   sandbox/dataflow-rewrite/boost/dataflow/blueprint/factory.hpp | 31 +++++++++++++++++++++++++++----
   sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/test_factory.cpp | 21 ++++++++++++++++++++-
   2 files changed, 47 insertions(+), 5 deletions(-)

Modified: sandbox/dataflow-rewrite/boost/dataflow/blueprint/factory.hpp
==============================================================================
--- sandbox/dataflow-rewrite/boost/dataflow/blueprint/factory.hpp (original)
+++ sandbox/dataflow-rewrite/boost/dataflow/blueprint/factory.hpp 2008-12-02 19:51:34 EST (Tue, 02 Dec 2008)
@@ -15,7 +15,10 @@
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
 #include <boost/functional/factory.hpp>
+#include <boost/function_types/function_type.hpp>
 #include <boost/iterator/iterator_adaptor.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/joint_view.hpp>
 
 #include <map>
 #include <memory>
@@ -47,14 +50,31 @@
     friend class boost::iterator_core_access;
 };
 
-template<typename BlueprintFramework>
+template<typename BlueprintFramework, typename AdditionalArgs=mpl::vector<> >
 class factory
 {
+public:
     typedef typename BlueprintFramework::framework_type framework_type;
     typedef framework_entity<BlueprintFramework> entity_type;
- typedef boost::function<entity_type * (framework_context<BlueprintFramework> &)> function_type;
+ typedef framework_entity<BlueprintFramework> framework_entity_type;
+ typedef framework_context<BlueprintFramework> framework_context_type;
+ typedef
+ typename function_types::function_type
+ <
+ typename mpl::joint_view
+ <
+ mpl::vector
+ <
+ framework_entity_type *,
+ framework_context_type &
+ >,
+ AdditionalArgs
+ >::type
+ >::type signature_type;
+
+ typedef boost::function<signature_type> function_type;
     typedef std::map<std::string, function_type> map_type;
-public:
+
     typedef key_iterator<map_type> iterator;
     
     std::auto_ptr<entity_type> make(const std::string &key)
@@ -79,7 +99,10 @@
     {
         m_components[s] = boost::bind(boost::factory<port_adapter<BlueprintFramework, T> *>(), _1, t0);
     }
-
+ void add_entity(const std::string &s, const function_type &f)
+ {
+ m_components[s] = f;
+ }
 protected:
     map_type m_components;
 };

Modified: sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/test_factory.cpp
==============================================================================
--- sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/test_factory.cpp (original)
+++ sandbox/dataflow-rewrite/libs/dataflow/test/blueprint/test_factory.cpp 2008-12-02 19:51:34 EST (Tue, 02 Dec 2008)
@@ -18,7 +18,7 @@
 
 namespace df = boost::dataflow;
 
-BOOST_AUTO_TEST_CASE( test )
+BOOST_AUTO_TEST_CASE( test_default )
 {
     df::blueprint::factory<my_blueprint_framework> factory;
     factory.add_port<my_port_producer>("my_port_producer");
@@ -28,4 +28,23 @@
     
     BOOST_CHECK_EQUAL(&entity->framework_context(), &fo);
     BOOST_CHECK(entity->type_info() == typeid(my_port_producer));
+}
+
+typedef df::blueprint::factory<my_blueprint_framework, boost::mpl::vector<int> > factory_int_type;
+
+struct constructor_int
+{
+ factory_int_type::framework_entity_type *operator()(factory_int_type::framework_context_type &c, int x) const
+ {
+ return new df::blueprint::port_adapter<my_blueprint_framework, my_port_producer>(c);
+ }
+};
+
+BOOST_AUTO_TEST_CASE( test_signature )
+{
+ df::blueprint::factory<my_blueprint_framework, boost::mpl::vector<int> > factory;
+ factory.add_entity("my_port_producer_int", constructor_int());
+
+ df::blueprint::framework_context<my_blueprint_framework> fo;
+ df::blueprint::framework_entity<my_blueprint_framework> *entity = factory["my_port_producer_int"](fo, 1);
 }
\ No newline at end of file


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