Boost logo

Boost-Commit :

From: jmoeller_at_[hidden]
Date: 2007-06-27 22:56:02


Author: jmoeller
Date: 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
New Revision: 7293
URL: http://svn.boost.org/trac/boost/changeset/7293

Log:
Updated fusion code (added fusion_arg_sequence class)
Added build/Jamfile.v2
Minor tweaks for compilation on MSVC and Cygwin gcc
Added auto_ptr overload to result_converter operator()

Added:
   sandbox/langbinding/libs/langbinding/build/Jamfile.v2
Text files modified:
   sandbox/langbinding/boost/langbinding/aux_/config.hpp | 40 ++++++++
   sandbox/langbinding/boost/langbinding/backend/call_xxx_data.hpp | 9 ++
   sandbox/langbinding/boost/langbinding/classes/polymorphic.hpp | 2
   sandbox/langbinding/boost/langbinding/function/aux_/fusion_arg_iterator.hpp | 172 +++++++++++++++++++++++++++++++++++----
   sandbox/langbinding/boost/langbinding/function/aux_/invoke.hpp | 8
   sandbox/langbinding/boost/langbinding/function/aux_/invoker.hpp | 19 ++--
   sandbox/langbinding/boost/langbinding/function/result_converter.hpp | 21 ++++
   sandbox/langbinding/boost/langbinding/module/id.hpp | 2
   sandbox/langbinding/libs/langbinding/src/module/id.cpp | 2
   sandbox/langbinding/libs/langbinding/test/Jamfile | 35 ++++++-
   sandbox/langbinding/libs/langbinding/test/function/make_function.cpp | 4
   11 files changed, 269 insertions(+), 45 deletions(-)

Modified: sandbox/langbinding/boost/langbinding/aux_/config.hpp
==============================================================================
--- sandbox/langbinding/boost/langbinding/aux_/config.hpp (original)
+++ sandbox/langbinding/boost/langbinding/aux_/config.hpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -4,11 +4,19 @@
 #ifndef CONFIG_DWA2004918_HPP
 # define CONFIG_DWA2004918_HPP
 
-#if !defined(BOOST_LANGBINDING_DYNAMIC_LIB)
-# define BOOST_PYTHON_DYNAMIC_LIB
+#include <boost/config.hpp>
+
+//#if !defined(BOOST_LANGBINDING_DYNAMIC_LIB)
+//# define BOOST_PYTHON_DYNAMIC_LIB
+//#endif
+
+// compatibility with the rest of Boost's auto-linking code:
+#if defined(BOOST_ALL_DYN_LINK)
+# undef BOOST_LANGBINDING_STATIC_LIB
+# define BOOST_LANGBINDING_DYNAMIC_LIB
 #endif
 
-#if defined(BOOST_LANGBINDING_DYNAMIC_LIB) && (defined(_WIN32) || defined(__CYGWIN__))
+#if defined(BOOST_LANGBINDING_DYNAMIC_LIB) && defined(BOOST_HAS_DECLSPEC)
 # if defined(BOOST_LANGBINDING_SOURCE)
 # define BOOST_LANGBINDING_DECL __declspec(dllexport)
 # define BOOST_LANGBINDING_BUILD_DLL
@@ -21,4 +29,30 @@
 # define BOOST_LANGBINDING_DECL
 #endif
 
+//
+// Automatically link to the correct build variant where possible.
+//
+#if !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_LANGBINDING_NO_LIB) && !defined(BOOST_WHATEVER_SOURCE)
+//
+// Tell the autolink to link dynamically, this will get undef'ed by auto_link.hpp
+// once it's done with it:
+//
+#if defined(BOOST_LANGBINDING_DYNAMIC_LIB)
+# define BOOST_DYN_LINK
+#endif
+//
+// Set the name of our library, this will get undef'ed by auto_link.hpp
+// once it's done with it:
+//
+#if defined(BOOST_LANGBINDING_LIB_NAME)
+# define BOOST_LIB_NAME BOOST_LANGBINDING_LIB_NAME
+#else
+# define BOOST_LIB_NAME boost_langbinding
+#endif
+//
+// And include the header that does the work:
+//
+#include <boost/config/auto_link.hpp>
+#endif // auto-linking disabled
+
 #endif // CONFIG_DWA2004918_HPP

Modified: sandbox/langbinding/boost/langbinding/backend/call_xxx_data.hpp
==============================================================================
--- sandbox/langbinding/boost/langbinding/backend/call_xxx_data.hpp (original)
+++ sandbox/langbinding/boost/langbinding/backend/call_xxx_data.hpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -11,6 +11,11 @@
 
 namespace boost { namespace langbinding { namespace backend {
 
+#if defined(BOOST_MSVC)
+#pragma warning(push)
+#pragma warning(disable : 4251)
+#endif
+
 // The constant data associated with any given call signature from C++
 // to XXX.
 struct BOOST_LANGBINDING_DECL call_xxx_data
@@ -29,6 +34,10 @@
     std::vector<boost::shared_ptr<void> > cache;
 };
 
+#if defined(BOOST_MSVC)
+#pragma warning(pop)
+#endif
+
 inline call_xxx_data::call_xxx_data(unsigned arity, util::type_info const* types)
   : arity(arity), types(types)
 {}

Modified: sandbox/langbinding/boost/langbinding/classes/polymorphic.hpp
==============================================================================
--- sandbox/langbinding/boost/langbinding/classes/polymorphic.hpp (original)
+++ sandbox/langbinding/boost/langbinding/classes/polymorphic.hpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -22,7 +22,7 @@
     }
     
  private:
- template<class> friend class instance_holder;
+ template<class> friend struct instance_holder;
     backend::class_instance instance;
 };
 

Modified: sandbox/langbinding/boost/langbinding/function/aux_/fusion_arg_iterator.hpp
==============================================================================
--- sandbox/langbinding/boost/langbinding/function/aux_/fusion_arg_iterator.hpp (original)
+++ sandbox/langbinding/boost/langbinding/function/aux_/fusion_arg_iterator.hpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -5,42 +5,87 @@
 #ifndef FUSION_VOID_PTR_ITERATOR_040923_HPP
 #define FUSION_VOID_PTR_ITERATOR_040923_HPP
 
-#include <boost/spirit/fusion/iterator/detail/iterator_base.hpp>
+#include <boost/fusion/support/tag_of_fwd.hpp>
+#include <boost/fusion/support/iterator_base.hpp>
+
+#include <boost/mpl/next_prior.hpp>
+#include <boost/mpl/equal_to.hpp>
+
+#include <boost/langbinding/converter/converter_function.hpp>
 
 namespace boost { namespace langbinding { namespace function { namespace aux {
 
-struct fusion_arg_iterator;
-
+// Define a sequence sized by an MPL Integral Constant
+template <typename Arity>
+struct fusion_arg_sequence {
+ typedef Arity size;
+ fusion_arg_sequence(converter::from_xxx_data* cvtrs) : converters(cvtrs) {}
+
+ converter::from_xxx_data* converters;
+};
+
+struct fusion_arg_sequence_tag;
+
+template <typename Pos>
 struct fusion_arg_iterator
- : fusion::iterator_base<fusion_arg_iterator>
+ : fusion::iterator_base<fusion_arg_iterator<Pos> >
 {
- typedef fusion_arg_iterator tag;
-
+ typedef Pos index;
+ // This could easily be random_access_traversal_tag, but all we need is a
+ // forward sequence:
+ typedef fusion::forward_traversal_tag category;
     fusion_arg_iterator(converter::from_xxx_data* p_) : p(p_) {}
 
+ // Pointer to corresponding data element
     converter::from_xxx_data* p;
 };
 
+struct fusion_arg_iterator_tag;
+
 }}}} // namespace boost::langbinding::function::aux
 
-namespace boost { namespace fusion { namespace meta {
+// Specialize all the necessary fusion metafunctions/metaclasses to define a
+// fusion Sequence
+
+namespace boost { namespace fusion {
+
+namespace traits {
+
+ template<typename Arity>
+ struct tag_of<langbinding::function::aux::fusion_arg_sequence<Arity> >
+ {
+ typedef langbinding::function::aux::fusion_arg_sequence_tag type;
+ };
+
+ template<typename Pos>
+ struct tag_of<langbinding::function::aux::fusion_arg_iterator<Pos> >
+ {
+ typedef langbinding::function::aux::fusion_arg_iterator_tag type;
+ };
+
+} // namespace traits
+
+namespace extension {
+
+ // Define the iterator's operations first
    
     template <typename Tag>
     struct next_impl;
 
     template <>
- struct next_impl<langbinding::function::aux::fusion_arg_iterator>
+ struct next_impl<langbinding::function::aux::fusion_arg_iterator_tag>
     {
         template <typename Iterator>
         struct apply
         {
- typedef langbinding::function::aux::fusion_arg_iterator type;
+ typedef typename Iterator::index index;
+ typedef langbinding::function::aux::fusion_arg_iterator<
+ typename mpl::next<index>::type
+ > type;
 
- static type call(Iterator i)
+ static type call(Iterator const & i)
             {
- return langbinding::function::aux::fusion_arg_iterator(
- i.p + 1
- );
+ return type(i.p);
             };
         };
     };
@@ -49,21 +94,112 @@
     struct deref_impl;
 
     template <>
- struct deref_impl<langbinding::function::aux::fusion_arg_iterator>
+ struct deref_impl<langbinding::function::aux::fusion_arg_iterator_tag>
     {
         template <typename Iterator>
         struct apply
         {
- typedef langbinding::converter::from_xxx_data& type;
+ typedef langbinding::converter::from_xxx_data & type;
 
- static type call(Iterator i)
+ static type call(Iterator const & i)
             {
- return *i.p;
+ return i.p[Iterator::index::value];
             }
         };
     };
 
-}}} // namespace boost::fusion::meta
+ template<typename Tag>
+ struct equal_to_impl;
+
+ template<>
+ struct equal_to_impl<langbinding::function::aux::fusion_arg_iterator_tag>
+ {
+ template<typename It1, typename It2>
+ struct apply
+ : mpl::equal_to<
+ typename It1::index,
+ typename It2::index>
+ {};
+ };
+
+ // Now define the sequence's intrinsics
+
+ template<typename Tag>
+ struct is_sequence_impl;
+
+ template<>
+ struct is_sequence_impl<langbinding::function::aux::fusion_arg_sequence_tag>
+ {
+ template<typename Sequence>
+ struct apply : mpl::true_ {};
+ };
+
+ template<typename Tag>
+ struct is_view_impl;
+
+ template<>
+ struct is_view_impl<langbinding::function::aux::fusion_arg_sequence_tag>
+ {
+ template<typename Sequence>
+ struct apply : mpl::false_ {};
+ };
+
+ template<typename Tag>
+ struct size_impl;
+
+ template<>
+ struct size_impl<langbinding::function::aux::fusion_arg_sequence_tag>
+ {
+ template<typename Sequence>
+ struct apply
+ : Sequence::size
+ {};
+ };
+
+ template<typename Tag>
+ struct begin_impl;
+
+ template<>
+ struct begin_impl<langbinding::function::aux::fusion_arg_sequence_tag>
+ {
+ template<typename Sequence>
+ struct apply
+ {
+ typedef langbinding::function::aux::fusion_arg_iterator<
+ mpl::int_<0>::type
+ > type;
+
+ static type call(Sequence & seq)
+ {
+ return type(seq.converters);
+ }
+ };
+ };
+
+ template<typename Tag>
+ struct end_impl;
+
+ template<>
+ struct end_impl<langbinding::function::aux::fusion_arg_sequence_tag>
+ {
+ template<typename Sequence>
+ struct apply
+ {
+ typedef langbinding::function::aux::fusion_arg_iterator<
+ typename Sequence::size::type
+ > type;
+
+ static type call(Sequence & seq)
+ {
+ return type(seq.converters);
+ }
+ };
+ };
+
+} // namespace extension
+
+}} // namespace boost::fusion
+
 
 #endif // FUSION_VOID_PTR_ITERATOR_040923_HPP
 

Modified: sandbox/langbinding/boost/langbinding/function/aux_/invoke.hpp
==============================================================================
--- sandbox/langbinding/boost/langbinding/function/aux_/invoke.hpp (original)
+++ sandbox/langbinding/boost/langbinding/function/aux_/invoke.hpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -13,14 +13,14 @@
 #include <boost/type_traits/is_same.hpp>
 #include <boost/type_traits/is_member_function_pointer.hpp>
 
-#include <boost/spirit/fusion/sequence/get.hpp>
+#include <boost/fusion/sequence/intrinsic/at.hpp>
 
 #include <boost/langbinding/function/config.hpp>
 #include <boost/langbinding/function/aux_/invoke_tag.hpp>
 
 namespace boost { namespace langbinding { namespace function { namespace aux {
 
-#define BOOST_LANGBINDING_EXTRACT(z, n, tuple) fusion::get<n>(tuple)()
+#define BOOST_LANGBINDING_EXTRACT(z, n, tuple) fusion::at_c<n>(tuple)()
 #define BOOST_LANGBINDING_EXTRACT_SKIP_THIS(z, n, tuple) \
     fusion::get<BOOST_PP_INC(n)>(tuple)()
 
@@ -55,7 +55,7 @@
 template<class F, class Converters>
 void* invoke(invoke_tag_<true, true>, mpl::long_<N>, F const& fn, Converters const& cvs)
 {
- (fusion::get<0>(cvs.args)().*fn)(
+ (fusion::at_c<0>(cvs.args)().*fn)(
         BOOST_PP_ENUM(BOOST_PP_DEC(N), BOOST_LANGBINDING_EXTRACT, cvs.args)
     );
     return cvs.return_();
@@ -65,7 +65,7 @@
 void* invoke(invoke_tag_<false, true>, mpl::long_<N>, F const& fn, Converters const& cvs)
 {
     return cvs.return_(
- (fusion::get<0>(cvs.args)().*fn)(
+ (fusion::at_c<0>(cvs.args)().*fn)(
             BOOST_PP_ENUM(BOOST_PP_DEC(N), BOOST_LANGBINDING_EXTRACT, cvs.args)
         )
     );

Modified: sandbox/langbinding/boost/langbinding/function/aux_/invoker.hpp
==============================================================================
--- sandbox/langbinding/boost/langbinding/function/aux_/invoker.hpp (original)
+++ sandbox/langbinding/boost/langbinding/function/aux_/invoker.hpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -11,14 +11,14 @@
 #include <boost/mpl/begin_end.hpp>
 #include <boost/mpl/iterator_range.hpp>
 #include <boost/mpl/front.hpp>
+#include <boost/mpl/pop_front.hpp>
 
 #include <boost/type_traits/remove_cv.hpp>
 #include <boost/type_traits/remove_reference.hpp>
 #include <boost/type_traits/remove_pointer.hpp>
 
-#include <boost/spirit/fusion/sequence/type_sequence.hpp>
-#include <boost/spirit/fusion/algorithm/transform.hpp>
-#include <boost/spirit/fusion/sequence/generate.hpp>
+#include <boost/fusion/sequence/adapted/mpl.hpp>
+#include <boost/fusion/sequence/conversion/as_list.hpp>
 
 #include <boost/langbinding/function/invoker.hpp>
 #include <boost/langbinding/function/argument_type.hpp>
@@ -105,10 +105,7 @@
 {
     invoker(F fn);
 
- typedef mpl::iterator_range<
- typename mpl::next<typename mpl::begin<Signature>::type>::type
- , typename mpl::end<Signature>::type
- > argument_types;
+ typedef typename mpl::pop_front<Signature>::type argument_types;
 
     typedef typename mpl::front<Signature>::type return_type_;
     typedef result_converter<return_type_> rc_type;
@@ -117,14 +114,16 @@
         backend::plugin const& backend_
       , converter::from_xxx_data* args) const
     {
- aux::fusion_arg_iterator arg_iterator(args);
+ aux::fusion_arg_sequence<
+ typename mpl::size<argument_types>::type
+ > arg_seq(args);
 
- typename fusion::meta::generate<
+ typename fusion::result_of::as_list<
             mpl::transform_view<
                 argument_types
               , arg_extractor<mpl::_>
>
- >::type argument_converters(arg_iterator);
+ >::type argument_converters(arg_seq);
 
         // Find to_xxx converter in registry.
         converter::to_xxx_function rc_fn = get_result_converter(

Modified: sandbox/langbinding/boost/langbinding/function/result_converter.hpp
==============================================================================
--- sandbox/langbinding/boost/langbinding/function/result_converter.hpp (original)
+++ sandbox/langbinding/boost/langbinding/function/result_converter.hpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -280,6 +280,27 @@
         );
     }
 
+ // JHM: I decided to pass auto_ptr<>s by value here. This may
+ // not be the right thing to do. This works, but it moves
+ // ownership of the "pointee" inside of the call. However,
+ // this is what's usually expected, and the installer will
+ // move ownership anyway if invoked.
+ //
+ // Passing by reference doesn't work, because an auto_ptr<>
+ // returned from a function is usually an rvalue, and a non-
+ // const reference can't be bound to an rvalue.
+ template <class U>
+ void* operator()(std::auto_ptr<U> x) const
+ {
+ return callback(
+ &x
+ , make_installer(
+ typename has_installer::type()
+ , x
+ )
+ );
+ }
+
 private:
     converter::to_xxx_function callback;
     backend::plugin const& backend_;

Modified: sandbox/langbinding/boost/langbinding/module/id.hpp
==============================================================================
--- sandbox/langbinding/boost/langbinding/module/id.hpp (original)
+++ sandbox/langbinding/boost/langbinding/module/id.hpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -5,7 +5,7 @@
 #ifndef BOOST_LANGBINDING_MODULE_040921_HPP
 #define BOOST_LANGBINDING_MODULE_040921_HPP
 
-#include <boost/langbinding/module/config.hpp>
+#include <boost/langbinding/aux_/config.hpp>
 
 namespace boost { namespace langbinding { namespace module {
 

Added: sandbox/langbinding/libs/langbinding/build/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/langbinding/libs/langbinding/build/Jamfile.v2 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -0,0 +1,28 @@
+# (C) Copyright John H. Moeller 2007
+# Use, modification and distribution are 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)
+
+project boost/langbinding
+ : source-location ../src
+ : requirements
+ <define>BOOST_LANGBINDING_SOURCE
+ <link>shared:<define>BOOST_LANGBINDING_DYNAMIC_LIB=1
+ <link>static:<define>BOOST_LANGBINDING_STATIC_LIB=1
+ : # default build
+ : usage-requirements
+ <link>shared:<define>BOOST_LANGBINDING_DYNAMIC_LIB=1
+ <link>static:<define>BOOST_LANGBINDING_STATIC_LIB=1
+ ;
+
+SOURCES =
+ backend/plugin
+ backend/call_xxx_data
+ classes/inheritance
+ converter/registry
+ module/id
+ ;
+
+lib boost_langbinding
+ : $(SOURCES).cpp
+ ;

Modified: sandbox/langbinding/libs/langbinding/src/module/id.cpp
==============================================================================
--- sandbox/langbinding/libs/langbinding/src/module/id.cpp (original)
+++ sandbox/langbinding/libs/langbinding/src/module/id.cpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -2,7 +2,7 @@
 // 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/langbinding/module/config.hpp>
+#include <boost/langbinding/module/id.hpp>
 
 namespace boost { namespace langbinding { namespace module { namespace aux {
 

Modified: sandbox/langbinding/libs/langbinding/test/Jamfile
==============================================================================
--- sandbox/langbinding/libs/langbinding/test/Jamfile (original)
+++ sandbox/langbinding/libs/langbinding/test/Jamfile 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -1,6 +1,31 @@
-# declare the location of this subproject relative to the root
-subproject libs/langbinding/test ;
+##==============================================================================
+# Copyright (c) 2003-2006 Joel de Guzman
+#
+# 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)
+#==============================================================================
+# bring in rules for testing
+import testing ;
+
+project
+ : requirements
+ <library>/boost/langbinding//boost_langbinding
+ <define>BOOST_ALL_NO_LIB
+ ;
+
+{
+ test-suite langbinding :
+ #[ run classes/holder.cpp : : : : ]
+ [ run classes/inheritance.cpp : : : : ]
+
+ #[ run converter/converter.cpp : : : : ]
+
+ [ run function/dispatch.cpp : : : : ]
+ [ run function/make_function.cpp : : : : ]
+ [ run function/result_converter.cpp : : : : ]
+ [ run function/rvalue_conversion.cpp : : : : ]
+
+ ;
+}
 
-subinclude libs/langbinding/test/classes ;
-subinclude libs/langbinding/test/converter ;
-subinclude libs/langbinding/test/function ;

Modified: sandbox/langbinding/libs/langbinding/test/function/make_function.cpp
==============================================================================
--- sandbox/langbinding/libs/langbinding/test/function/make_function.cpp (original)
+++ sandbox/langbinding/libs/langbinding/test/function/make_function.cpp 2007-06-27 22:56:00 EDT (Wed, 27 Jun 2007)
@@ -57,8 +57,8 @@
 int main()
 {
     from_xxx_data args[2] = {
- 0, &x, 0
- , 0, &y, 0
+ { 0, &x, 0 }
+ , { 0, &y, 0 }
     };
 
     registered<


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