Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52965 - in sandbox/mirror: boost/mirror libs/mirror/example/factories
From: chochlik_at_[hidden]
Date: 2009-05-13 10:07:13


Author: matus.chochlik
Date: 2009-05-13 10:07:12 EDT (Wed, 13 May 2009)
New Revision: 52965
URL: http://svn.boost.org/trac/boost/changeset/52965

Log:
[mirror 0.4.x]
- added advanced functor caller which allow to construct
  only a subset of the functor parameters by a factory
  and to supply the others when calling the functor

Added:
   sandbox/mirror/boost/mirror/adv_func_call.hpp (contents, props changed)
Text files modified:
   sandbox/mirror/boost/mirror/functor_call.hpp | 3 ++-
   sandbox/mirror/libs/mirror/example/factories/inserter.cpp | 17 ++++++++++++++++-
   2 files changed, 18 insertions(+), 2 deletions(-)

Added: sandbox/mirror/boost/mirror/adv_func_call.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/mirror/adv_func_call.hpp 2009-05-13 10:07:12 EDT (Wed, 13 May 2009)
@@ -0,0 +1,349 @@
+/**
+ * \file boost/mirror/adv_func_call.hpp
+ *
+ * Advanced meta-function-based functor callers
+ *
+ * Copyright 2008 Matus Chochlik. 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)
+ */
+
+#ifndef BOOST_MIRROR_ADV_FUNC_CALL_HPP
+#define BOOST_MIRROR_ADV_FUNC_CALL_HPP
+
+#include <boost/mirror/functor_call.hpp>
+
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+#include <boost/preprocessor/arithmetic/inc.hpp>
+#include <boost/preprocessor/arithmetic/dec.hpp>
+
+#include <boost/mpl/max_element.hpp>
+
+namespace boost {
+namespace mirror {
+namespace detail {
+
+#define BOOST_MIRROR_DETAIL_IMPLEMENT_SELECT_NTH_N(R, N, PARAM_COUNT) \
+template < BOOST_PP_ENUM_PARAMS(PARAM_COUNT, typename T) > \
+inline const BOOST_PP_CAT(T, BOOST_PP_DEC(N)) & select_nth( \
+ mpl::int_< N > n, \
+ BOOST_PP_ENUM_BINARY_PARAMS( \
+ PARAM_COUNT, \
+ const T, \
+ & p \
+ ) \
+){return BOOST_PP_CAT(p, BOOST_PP_DEC(N));}
+
+
+#define BOOST_MIRROR_DETAIL_IMPLEMENT_SELECT_NTH(R, PARAM_COUNT, _) \
+BOOST_PP_REPEAT_FROM_TO( \
+ 1, \
+ BOOST_PP_INC(PARAM_COUNT), \
+ BOOST_MIRROR_DETAIL_IMPLEMENT_SELECT_NTH_N, \
+ PARAM_COUNT\
+)
+
+BOOST_PP_REPEAT(
+ BOOST_MIRROR_MAX_FUNC_PARAMS(),
+ BOOST_MIRROR_DETAIL_IMPLEMENT_SELECT_NTH,
+ _
+)
+
+#undef BOOST_MIRROR_DETAIL_IMPLEMENT_SELECT_NTH
+#undef BOOST_MIRROR_DETAIL_IMPLEMENT_SELECT_NTH_N
+
+template <
+ template <class> class Manufacturer,
+ class MetaFunctions,
+ class FunctionIndex,
+ class ParamIndex,
+ class ParamMapping,
+ class Arity,
+ class ConstructedParam
+> struct param_source_switch;
+
+
+#define BOOST_MIRROR_IMPLEMENT_PARAM_SOURCE_SWITCH_BASE( \
+ Z, ARITY, DATA \
+) \
+template < \
+ template <class> class Manufacturer, \
+ class MetaFunctions, \
+ class FunctionIndex, \
+ class ParamIndex, \
+ class ParamMapping \
+> struct param_source_switch< \
+ Manufacturer, \
+ MetaFunctions, \
+ FunctionIndex, \
+ ParamIndex, \
+ ParamMapping, \
+ mpl::int_< ARITY >, \
+ mpl::true_ \
+> \
+{ \
+ typedef typename constructor_utils::template adjust_product< \
+ typename MetaFunctions:: \
+ template function<FunctionIndex>::params:: \
+ template param<ParamIndex>:: \
+ type::reflected_type \
+ >::type T; \
+ typedef Manufacturer< T > manufacturer; \
+ manufacturer m; \
+ \
+ template <typename Param> \
+ inline param_source_switch(Param param) \
+ : m(param, MetaFunctions(), FunctionIndex(), ParamIndex()) \
+ { } \
+ \
+ template < BOOST_PP_ENUM_PARAMS(ARITY, typename T) > \
+ inline T operator()(BOOST_PP_ENUM_PARAMS(ARITY, T)) \
+ { \
+ return m(); \
+ } \
+};
+
+BOOST_PP_REPEAT_FROM_TO(
+ 1, BOOST_MIRROR_MAX_FUNC_PARAMS(),
+ BOOST_MIRROR_IMPLEMENT_PARAM_SOURCE_SWITCH_BASE,
+ _
+)
+
+#undef BOOST_MIRROR_IMPLEMENT_PARAM_SOURCE_SWITCH_BASE
+
+
+#define BOOST_MIRROR_IMPLEMENT_PARAM_SOURCE_SWITCH_BASE( \
+ Z, ARITY, DATA \
+) \
+template < \
+ template <class> class Manufacturer, \
+ class MetaFunctions, \
+ class FunctionIndex, \
+ class ParamIndex, \
+ class ParamMapping \
+> struct param_source_switch< \
+ Manufacturer, \
+ MetaFunctions, \
+ FunctionIndex, \
+ ParamIndex, \
+ ParamMapping, \
+ mpl::int_< ARITY >, \
+ mpl::false_ \
+> \
+{ \
+ typedef typename constructor_utils::template adjust_product< \
+ typename MetaFunctions:: \
+ template function<FunctionIndex>::params:: \
+ template param<ParamIndex>:: \
+ type::reflected_type \
+ >::type T; \
+ \
+ template <typename Param> \
+ inline param_source_switch(Param) \
+ { } \
+ \
+ template < BOOST_PP_ENUM_PARAMS(ARITY, typename T) > \
+ inline T operator()( \
+ BOOST_PP_ENUM_BINARY_PARAMS(ARITY, const T, & p) \
+ ) \
+ { \
+ return select_nth( \
+ mpl::int_< \
+ mpl::at<ParamMapping, ParamIndex>::type::value \
+ >(), \
+ BOOST_PP_ENUM_PARAMS(ARITY, p) \
+ ); \
+ } \
+};
+
+BOOST_PP_REPEAT_FROM_TO(
+ 1, BOOST_MIRROR_MAX_FUNC_PARAMS(),
+ BOOST_MIRROR_IMPLEMENT_PARAM_SOURCE_SWITCH_BASE,
+ _
+)
+
+#undef BOOST_MIRROR_IMPLEMENT_PARAM_SOURCE_SWITCH_BASE
+
+
+template <
+ template <class> class Manufacturer,
+ class MetaFunctions,
+ class FunctionIndex,
+ class ParamMapping,
+ class ParamCount,
+ class Arity
+> struct advanced_functor_caller;
+
+#define BOOST_MIRROR_ADV_FUNC_CALLER_DECLARE_PARAM_SOURCE( \
+ Z, PARAM_INDEX, ARITY \
+) param_source_switch< \
+ Manufacturer, \
+ MetaFunctions, \
+ FunctionIndex, \
+ mpl::int_< PARAM_INDEX >, \
+ ParamMapping, \
+ mpl::int_< ARITY >, \
+ typename mpl::less< \
+ typename mpl::at< \
+ ParamMapping, \
+ mpl::int_< PARAM_INDEX > \
+ >::type, \
+ mpl::int_< 1 > \
+ >::type \
+> BOOST_PP_CAT(_, PARAM_INDEX);
+
+#define BOOST_MIRROR_ADV_FUNC_CALLER_INITIALIZE_PARAM_SOURCE( \
+ Z, PARAM_INDEX, _ \
+) , BOOST_PP_CAT(_, PARAM_INDEX)(param)
+
+#define BOOST_MIRROR_ADV_FUNC_CALLER_CALL_PARAM_SOURCE( \
+ Z, PARAM_INDEX, CALL_PARAMS \
+) BOOST_PP_CAT(_, PARAM_INDEX) CALL_PARAMS
+
+
+#define BOOST_MIRROR_DETAIL_IMPLEMENT_ADVANCED_FUNCTOR_CALLER_1( \
+ Z, ARITY, PARAM_COUNT \
+) \
+template < \
+ template <class> class Manufacturer, \
+ class MetaFunctions, \
+ class FunctionIndex, \
+ class ParamMapping \
+> struct advanced_functor_caller< \
+ Manufacturer, \
+ MetaFunctions, \
+ FunctionIndex, \
+ ParamMapping, \
+ mpl::int_<PARAM_COUNT>, \
+ mpl::int_< ARITY > \
+> \
+{ \
+protected: \
+ struct { } _dummy; \
+ BOOST_PP_REPEAT( \
+ PARAM_COUNT, \
+ BOOST_MIRROR_ADV_FUNC_CALLER_DECLARE_PARAM_SOURCE, \
+ ARITY \
+ ) \
+ \
+ template <class Param> \
+ inline advanced_functor_caller(Param param) \
+ : _dummy() \
+ BOOST_PP_REPEAT( \
+ PARAM_COUNT, \
+ BOOST_MIRROR_ADV_FUNC_CALLER_INITIALIZE_PARAM_SOURCE, \
+ _ \
+ ){ } \
+ \
+ typedef typename MetaFunctions::template function<FunctionIndex> \
+ _meta_function; \
+ \
+ typedef typename _meta_function::result_type::reflected_type \
+ result_type;\
+ \
+ template <class Functor, BOOST_PP_ENUM_PARAMS(ARITY, typename T) > \
+ inline result_type call( \
+ Functor func, \
+ BOOST_PP_ENUM_BINARY_PARAMS( \
+ ARITY, \
+ const T, \
+ & p \
+ ) \
+ ) \
+ { \
+ return func( \
+ BOOST_PP_ENUM( \
+ PARAM_COUNT, \
+ BOOST_MIRROR_ADV_FUNC_CALLER_CALL_PARAM_SOURCE,\
+ (BOOST_PP_ENUM_PARAMS(ARITY, p))\
+ ) \
+ ); \
+ } \
+public: \
+ template <class Class, BOOST_PP_ENUM_PARAMS(ARITY, typename T) > \
+ inline result_type operator()( \
+ Class& instance, \
+ BOOST_PP_ENUM_BINARY_PARAMS(ARITY, const T, & p) \
+ ) \
+ { \
+ return call( \
+ _meta_function::wrap(instance), \
+ BOOST_PP_ENUM_PARAMS(ARITY, p) \
+ ); \
+ } \
+};
+
+#define BOOST_MIRROR_DETAIL_IMPLEMENT_ADVANCED_FUNCTOR_CALLER_2( \
+ Z, PARAM_COUNT, _ \
+) BOOST_PP_REPEAT_FROM_TO( \
+ 1, PARAM_COUNT, \
+ BOOST_MIRROR_DETAIL_IMPLEMENT_ADVANCED_FUNCTOR_CALLER_1, \
+ PARAM_COUNT \
+)
+
+BOOST_PP_REPEAT(
+ BOOST_MIRROR_MAX_FUNC_PARAMS(),
+ BOOST_MIRROR_DETAIL_IMPLEMENT_ADVANCED_FUNCTOR_CALLER_2,
+ _
+)
+
+#undef BOOST_MIRROR_ADV_FUNC_CALLER_INITIALIZE_PARAM_SOURCE
+#undef BOOST_MIRROR_ADV_FUNC_CALLER_DECLARE_PARAM_SOURCE
+#undef BOOST_MIRROR_DETAIL_IMPLEMENT_ADVANCED_FUNCTOR_CALLER_2
+#undef BOOST_MIRROR_DETAIL_IMPLEMENT_ADVANCED_FUNCTOR_CALLER_1
+
+} // namespace detail
+
+template <
+ template <class> class Manufacturer,
+ class MetaFunctions,
+ class FunctionIndex,
+ class ParamMapping
+> struct advanced_functor_caller : public detail::advanced_functor_caller<
+ Manufacturer,
+ MetaFunctions,
+ FunctionIndex,
+ ParamMapping,
+ typename MetaFunctions::
+ template function<FunctionIndex>::
+ params::size,
+ mpl::int_<
+ mpl::deref<
+ typename mpl::max_element<ParamMapping>::type
+ >::type::value
+ >
+>
+{
+private:
+ typedef detail::advanced_functor_caller<
+ Manufacturer,
+ MetaFunctions,
+ FunctionIndex,
+ ParamMapping,
+ typename MetaFunctions::
+ template function<FunctionIndex>::
+ params::size,
+ mpl::int_<
+ mpl::deref<
+ typename mpl::max_element<ParamMapping>::type
+ >::type::value
+ >
+ > base_class;
+public:
+ inline advanced_functor_caller(void)
+ : base_class(0)
+ { }
+
+ template <class Param>
+ inline advanced_functor_caller(Param param)
+ : base_class(param)
+ { }
+};
+
+
+} // namespace mirror
+} // namespace boost
+
+#endif //include guard
+

Modified: sandbox/mirror/boost/mirror/functor_call.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/functor_call.hpp (original)
+++ sandbox/mirror/boost/mirror/functor_call.hpp 2009-05-13 10:07:12 EDT (Wed, 13 May 2009)
@@ -100,7 +100,8 @@
                 0 \
         ) \
  \
- typedef typename meta_function::result_type::reflected_type result_type;\
+ typedef typename meta_function::result_type::reflected_type \
+ result_type;\
  \
         template <class FactoryParam> \
         inline base_functor_caller(FactoryParam factory_param) \

Modified: sandbox/mirror/libs/mirror/example/factories/inserter.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/factories/inserter.cpp (original)
+++ sandbox/mirror/libs/mirror/example/factories/inserter.cpp 2009-05-13 10:07:12 EDT (Wed, 13 May 2009)
@@ -14,7 +14,7 @@
 
 #include <boost/char_type_switch/iostream.hpp>
 
-#include <boost/mirror/functor_call.hpp>
+#include <boost/mirror/adv_func_call.hpp>
 #include <boost/mirror/meta_mem_functions.hpp>
 #include <boost/mirror/meta_class.hpp>
 #include <boost/mirror/algorithm/for_each.hpp>
@@ -111,6 +111,21 @@
                         );
 #endif
                         func(p);
+ //
+ // TODO: test
+ //
+ typedef BOOST_MIRRORED_CLASS(person)::member_functions meta_fns;
+ advanced_functor_caller<
+ input_ui,
+ meta_fns,
+ mpl::int_<0>,
+ mpl::vector4<mpl::int_<0>, mpl::int_<0>, mpl::int_<1>, mpl::int_<2> >
+ > adv_func;
+ //
+ adv_func(p, BOOST_CTS_LIT("Zilina"), BOOST_CTS_LIT("010 07"));
+ //
+ // TODO:
+ //
                 }
                 // check whether to insert more persons
                 do


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