Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52996 - in sandbox/mirror: boost/mirror libs/mirror/example/factories
From: chochlik_at_[hidden]
Date: 2009-05-14 13:50:27


Author: matus.chochlik
Date: 2009-05-14 13:50:25 EDT (Thu, 14 May 2009)
New Revision: 52996
URL: http://svn.boost.org/trac/boost/changeset/52996

Log:
[mirror 0.4.x]
- added default values for the advanced_functor_caller
- added a advanced-member-function-caller

Text files modified:
   sandbox/mirror/boost/mirror/adv_func_call.hpp | 118 +++++++++++++++++++++++++++++++++++----
   sandbox/mirror/boost/mirror/functor_call.hpp | 13 +++-
   sandbox/mirror/libs/mirror/example/factories/inserter.cpp | 25 ++++++--
   sandbox/mirror/libs/mirror/example/factories/person.hpp | 69 +++++++++++++----------
   4 files changed, 171 insertions(+), 54 deletions(-)

Modified: sandbox/mirror/boost/mirror/adv_func_call.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/adv_func_call.hpp (original)
+++ sandbox/mirror/boost/mirror/adv_func_call.hpp 2009-05-14 13:50:25 EDT (Thu, 14 May 2009)
@@ -92,9 +92,16 @@
         typedef Manufacturer< T > manufacturer; \
         manufacturer m; \
         \
- template <typename Param> \
- inline param_source_switch(Param param) \
- : m(param, MetaFunctions(), FunctionIndex(), ParamIndex()) \
+ template <typename FactoryParam> \
+ inline param_source_switch(FactoryParam factory_param) \
+ : m(factory_param, MetaFunctions(), FunctionIndex(), ParamIndex()) \
+ { } \
+ \
+ template <typename FactoryParam> \
+ inline param_source_switch( \
+ FactoryParam factory_param, \
+ const T* opt_def \
+ ): m(factory_param, MetaFunctions(), FunctionIndex(), ParamIndex(), opt_def) \
         { } \
         \
         template < BOOST_PP_ENUM_PARAMS(ARITY, typename T) > \
@@ -139,8 +146,12 @@
                 type::reflected_type \
>::type T; \
         \
- template <typename Param> \
- inline param_source_switch(Param) \
+ template <typename FactoryParam> \
+ inline param_source_switch(FactoryParam) \
+ { } \
+ \
+ template <typename FactoryParam> \
+ inline param_source_switch(FactoryParam, const void*) \
         { } \
         \
         template < BOOST_PP_ENUM_PARAMS(ARITY, typename T) > \
@@ -177,7 +188,7 @@
 
 #define BOOST_MIRROR_ADV_FUNC_CALLER_DECLARE_PARAM_SOURCE( \
         Z, PARAM_INDEX, ARITY \
-) param_source_switch< \
+) typedef param_source_switch< \
         Manufacturer, \
         MetaFunctions, \
         FunctionIndex, \
@@ -191,11 +202,26 @@
>::type, \
                 mpl::int_< 1 > \
>::type \
-> BOOST_PP_CAT(_, PARAM_INDEX);
+> BOOST_PP_CAT(src_, PARAM_INDEX); \
+BOOST_PP_CAT(src_, PARAM_INDEX) BOOST_PP_CAT(_, PARAM_INDEX);
 
 #define BOOST_MIRROR_ADV_FUNC_CALLER_INITIALIZE_PARAM_SOURCE( \
         Z, PARAM_INDEX, _ \
-) , BOOST_PP_CAT(_, PARAM_INDEX)(param)
+) , BOOST_PP_CAT(_, PARAM_INDEX)(factory_param)
+
+#define BOOST_MIRROR_ADV_FUNC_CALLER_INITIALIZE_PARAM_SOURCE_W_DEF( \
+ Z, PARAM_INDEX, _ \
+) , BOOST_PP_CAT(_, PARAM_INDEX)( \
+ factory_param, \
+ & BOOST_PP_CAT(def_value_, PARAM_INDEX) \
+)
+
+#define BOOST_MIRROR_ADV_FUNC_CALLER_DECL_DEFAULT_PARAM(Z, INDEX, X) \
+ , typename ::boost::call_traits< \
+ typename BOOST_PP_CAT(src_, INDEX) ::T \
+ >::param_type \
+ BOOST_PP_CAT(def_value_, INDEX)
+
 
 #define BOOST_MIRROR_ADV_FUNC_CALLER_CALL_PARAM_SOURCE( \
         Z, PARAM_INDEX, CALL_PARAMS \
@@ -227,8 +253,8 @@
                 ARITY \
         ) \
         \
- template <class Param> \
- inline advanced_functor_caller(Param param) \
+ template <class FactoryParam> \
+ inline advanced_functor_caller(FactoryParam factory_param) \
          : _dummy() \
         BOOST_PP_REPEAT( \
                 PARAM_COUNT, \
@@ -236,6 +262,21 @@
                 _ \
         ){ } \
         \
+ template <class FactoryParam> \
+ inline advanced_functor_caller( \
+ FactoryParam factory_param \
+ BOOST_PP_REPEAT( \
+ PARAM_COUNT, \
+ BOOST_MIRROR_ADV_FUNC_CALLER_DECL_DEFAULT_PARAM, \
+ _ \
+ ) \
+ ): _dummy() \
+ BOOST_PP_REPEAT( \
+ PARAM_COUNT, \
+ BOOST_MIRROR_ADV_FUNC_CALLER_INITIALIZE_PARAM_SOURCE_W_DEF, \
+ _ \
+ ){ } \
+ \
         typedef typename MetaFunctions::template function<FunctionIndex> \
                 _meta_function; \
         \
@@ -288,6 +329,8 @@
         _
 )
 
+#undef BOOST_MIRROR_ADV_FUNC_CALLER_DECL_DEFAULT_PARAM
+#undef BOOST_MIRROR_ADV_FUNC_CALLER_INITIALIZE_PARAM_SOURCE_W_DEF
 #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
@@ -335,10 +378,59 @@
          : base_class(0)
         { }
 
- template <class Param>
- inline advanced_functor_caller(Param param)
- : base_class(param)
+ template <class FactoryParam>
+ inline advanced_functor_caller(FactoryParam factory_param)
+ : base_class(factory_param)
         { }
+
+#ifndef BOOST_NO_VARIADIC_TEMPLATES
+ template <class FactoryParam, class ...Defaults>
+ advanced_functor_caller(FactoryParam factory_param, Defaults ...defs)
+ : base_class(factory_param, defs...)
+ { }
+#endif
+
+};
+
+
+template <
+ template <class> class Manufacturer,
+ class Class,
+ int FuncIndex,
+ class ParamMapping_c
+> struct advanced_mem_func_caller : public advanced_functor_caller<
+ Manufacturer,
+ meta_member_functions<Class>,
+ mpl::int_<FuncIndex>,
+ typename ParamMapping_c::type
+>
+{
+private:
+ typedef advanced_functor_caller<
+ Manufacturer,
+ meta_member_functions<Class>,
+ mpl::int_<FuncIndex>,
+ typename ParamMapping_c::type
+ > base_class;
+public:
+ inline advanced_mem_func_caller(void)
+ : base_class(0)
+ { }
+
+ template <class FactoryParam>
+ inline advanced_mem_func_caller(FactoryParam factory_param)
+ : base_class(factory_param)
+ { }
+
+#ifndef BOOST_NO_VARIADIC_TEMPLATES
+ template <class FactoryParam, class ...Defaults>
+ inline advanced_mem_func_caller(
+ FactoryParam factory_param,
+ Defaults ...defs
+ ): base_class(factory_param, defs...)
+ { }
+#endif
+
 };
 
 

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-14 13:50:25 EDT (Thu, 14 May 2009)
@@ -205,6 +205,9 @@
         }
 };
 
+/** A template with more convenient interface, for calling member functions
+ * of a class
+ */
 template <
         template <class> class Manufacturer,
         class Class,
@@ -222,19 +225,21 @@
                 mpl::int_<FuncIndex>
> base_class;
 public:
- member_function_caller()
+ inline member_function_caller(void)
          : base_class(0)
         { }
 
         template <class FactoryParam>
- member_function_caller(FactoryParam factory_param)
+ inline member_function_caller(FactoryParam factory_param)
          : base_class(factory_param)
         { }
 
 #ifndef BOOST_NO_VARIADIC_TEMPLATES
         template <class FactoryParam, class ...Defaults>
- member_function_caller(FactoryParam factory_param, Defaults ...defs)
- : base_class(factory_param, defs...)
+ inline member_function_caller(
+ FactoryParam factory_param,
+ Defaults ...defs
+ ): base_class(factory_param, defs...)
         { }
 #endif
 

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-14 13:50:25 EDT (Thu, 14 May 2009)
@@ -107,22 +107,33 @@
                                 p.street,
                                 p.number,
                                 p.city,
- p.postal_code
+ p.postal_code,
+ p.country
                         );
 #endif
                         func(p);
                         //
                         // TODO: test
                         //
- typedef BOOST_MIRRORED_CLASS(person)::member_functions meta_fns;
- advanced_functor_caller<
+ advanced_mem_func_caller<
                                 input_ui,
- meta_fns,
- mpl::int_<0>,
- mpl::vector4<mpl::int_<0>, mpl::int_<0>, mpl::int_<1>, mpl::int_<2> >
+ person,
+ 0,
+ mpl::vector_c<int, 0, 0, 1, 2, 3>
+#ifdef BOOST_NO_VARIADIC_TEMPLATES
> adv_func;
+#else
+ > adv_func(
+ 0,
+ p.street,
+ p.number,
+ p.city,
+ p.postal_code,
+ p.country
+ );
+#endif
                         //
- adv_func(p, BOOST_CTS_LIT("Zilina"), BOOST_CTS_LIT("010 07"));
+ adv_func(p, BOOST_CTS_LIT("Zilina"), BOOST_CTS_LIT("010 07"), BOOST_CTS_LIT("Slovakia"));
                         //
                         // TODO:
                         //

Modified: sandbox/mirror/libs/mirror/example/factories/person.hpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/factories/person.hpp (original)
+++ sandbox/mirror/libs/mirror/example/factories/person.hpp 2009-05-14 13:50:25 EDT (Thu, 14 May 2009)
@@ -17,46 +17,53 @@
 
 namespace test {
 
+typedef ::boost::cts::bstring string;
+
 struct person
 {
- ::boost::cts::bstring first_name;
- ::boost::cts::bstring family_name;
- ::boost::cts::bstring street;
- ::boost::cts::bstring number;
- ::boost::cts::bstring city;
- ::boost::cts::bstring postal_code;
+ string first_name;
+ string family_name;
+ string street;
+ string number;
+ string city;
+ string postal_code;
+ string country;
 
         person(
- const ::boost::cts::bstring& _first_name,
- const ::boost::cts::bstring& _family_name,
- const ::boost::cts::bstring& _street,
- const ::boost::cts::bstring& _number,
- const ::boost::cts::bstring& _city,
- const ::boost::cts::bstring& _postal_code
+ const string& _first_name,
+ const string& _family_name,
+ const string& _street,
+ const string& _number,
+ const string& _city,
+ const string& _postal_code,
+ const string& _country
         ): first_name(_first_name)
          , family_name(_family_name)
          , street(_street)
          , number(_number)
          , city(_city)
          , postal_code(_postal_code)
+ , country(_country)
         { }
 
         void change_address(
- const ::boost::cts::bstring& _street,
- const ::boost::cts::bstring& _number,
- const ::boost::cts::bstring& _city,
- const ::boost::cts::bstring& _postal_code
+ const string& _street,
+ const string& _number,
+ const string& _city,
+ const string& _postal_code,
+ const string& _country
         )
         {
                 street.assign(_street);
                 number.assign(_number);
                 city.assign(_city);
                 postal_code.assign(_postal_code);
+ country.assign(_country);
         }
 
- inline ::boost::cts::bstring name_and_surname(void) const
+ inline string name_and_surname(void) const
         {
- ::boost::cts::bstring result(first_name);
+ string result(first_name);
                 result.append(BOOST_CTS_LIT(" "));
                 result.append(family_name);
                 return result;
@@ -74,29 +81,31 @@
 // tegister the class, it's attribs, constructors
 BOOST_MIRROR_QREG_CLASS_NO_BASE(
         ::test, person,
- (first_name)(family_name)(street)(number)(city)(postal_code)
+ (first_name)(family_name)(street)(number)(city)(postal_code)(country)
 )
 BOOST_MIRROR_QREG_CONSTRUCTORS(
         ::test::person, (
- ((const ::boost::cts::bstring&)(first_name))
- ((const ::boost::cts::bstring&)(family_name))
- ((const ::boost::cts::bstring&)(street))
- ((const ::boost::cts::bstring&)(number))
- ((const ::boost::cts::bstring&)(city))
- ((const ::boost::cts::bstring&)(postal_code))
+ ((const ::test::string&)(first_name))
+ ((const ::test::string&)(family_name))
+ ((const ::test::string&)(street))
+ ((const ::test::string&)(number))
+ ((const ::test::string&)(city))
+ ((const ::test::string&)(postal_code))
+ ((const ::test::string&)(country))
         )
 )
 
 BOOST_MIRROR_REG_MEM_FUNCTIONS_BEGIN(::test::person)
 BOOST_MIRROR_REG_MEM_FUNCTION(
         0, void, change_address,
- ((const ::boost::cts::bstring&)(street))
- ((const ::boost::cts::bstring&)(number))
- ((const ::boost::cts::bstring&)(city))
- ((const ::boost::cts::bstring&)(postal_code))
+ ((const ::test::string&)(street))
+ ((const ::test::string&)(number))
+ ((const ::test::string&)(city))
+ ((const ::test::string&)(postal_code))
+ ((const ::test::string&)(country))
 )
 BOOST_MIRROR_REG_CONST_MEM_FUNCTION(
- 1, ::boost::cts::bstring, name_and_surname, ((void))
+ 1, ::test::string, name_and_surname, ((void))
 )
 BOOST_MIRROR_REG_MEM_FUNCTIONS_END
 


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