Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52913 - in sandbox/mirror: boost/char_type_switch boost/mirror libs/mirror/example/factories
From: chochlik_at_[hidden]
Date: 2009-05-11 13:40:12


Author: matus.chochlik
Date: 2009-05-11 13:40:10 EDT (Mon, 11 May 2009)
New Revision: 52913
URL: http://svn.boost.org/trac/boost/changeset/52913

Log:
[mirror 0.4.x]
- added stringstream to char_type_switch facility
- added support for default values for functor_callers

Added:
   sandbox/mirror/boost/char_type_switch/sstream.hpp (contents, props changed)
Text files modified:
   sandbox/mirror/boost/mirror/functor_call.hpp | 102 ++++++++++++++++++++++++++++++--------
   sandbox/mirror/libs/mirror/example/factories/input_ui.hpp | 106 +++++++++++++++++++++++++++------------
   sandbox/mirror/libs/mirror/example/factories/inserter.cpp | 15 +++++
   3 files changed, 168 insertions(+), 55 deletions(-)

Added: sandbox/mirror/boost/char_type_switch/sstream.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/boost/char_type_switch/sstream.hpp 2009-05-11 13:40:10 EDT (Mon, 11 May 2009)
@@ -0,0 +1,25 @@
+/**
+ * \file boost/char_type_switch/sstream.hpp
+ * Narrow/Wide character type switching for sstreams
+ *
+ * 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_CHAR_TYPE_SWITCH_SSTREAM
+#define BOOST_CHAR_TYPE_SWITCH_SSTREAM
+
+#include <boost/char_type_switch/string.hpp>
+// Needed for ::std cout, cin, cerr, wcin, wcout, wcerr
+#include <sstream>
+
+namespace boost {
+namespace cts {
+
+typedef ::std::basic_stringstream<bchar, bchar_traits> bstringstream;
+
+} // namespace cts
+} // 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-11 13:40:10 EDT (Mon, 11 May 2009)
@@ -10,9 +10,12 @@
 #ifndef BOOST_MIRROR_FUNCTOR_CALL_HPP
 #define BOOST_MIRROR_FUNCTOR_CALL_HPP
 
+#include <boost/call_traits.hpp>
+#include <boost/preprocessor/repetition/repeat_from_to.hpp>
 #include <boost/mirror/factory.hpp>
 #include <boost/mirror/meta_mem_functions.hpp>
 
+
 namespace boost {
 namespace mirror {
 namespace detail {
@@ -26,13 +29,16 @@
 
 
 #define BOOST_MIRROR_BASE_FUNCTION_CALLER_DECLARE_FACTORY(Z, INDEX, X)\
-Manufacturer< \
-typename constructor_utils::template adjust_product< \
+typedef typename constructor_utils::template adjust_product< \
         typename meta_function::params:: \
         template param< mpl::int_< INDEX > >:: \
         type::reflected_type \
->::type \
-> BOOST_PP_CAT(_, INDEX);
+>::type BOOST_PP_CAT(T, INDEX); \
+Manufacturer< BOOST_PP_CAT(T, INDEX) > BOOST_PP_CAT(_, INDEX);
+
+#define BOOST_MIRROR_BASE_FUNCTION_CALLER_DECL_DEFAULT_PARAM(Z, INDEX, X) \
+ , typename ::boost::call_traits< BOOST_PP_CAT(T, INDEX) >::param_type \
+ BOOST_PP_CAT(opt_default_, INDEX)
 
 #define BOOST_MIRROR_BASE_FUNCTION_CALLER_INITIALIZE_FACTORY(Z, INDEX, PARAM) \
         , BOOST_PP_CAT(_, INDEX) ( \
@@ -42,11 +48,36 @@
                 mpl::int_< INDEX >() \
         )
 
+#define BOOST_MIRROR_BASE_FUNCTION_CALLER_INITIALIZE_FACTORY_W_DEF(Z, INDEX, PARAM) \
+ , BOOST_PP_CAT(_, INDEX) ( \
+ PARAM, \
+ _meta_functions, \
+ FuncIndex(), \
+ mpl::int_< INDEX >(), \
+ & BOOST_PP_CAT(opt_default_, INDEX) \
+ )
+
+#define BOOST_MIRROR_BASE_FUNCTION_CALLER_DECLARE_CONSTR_W_DEF(PARAM_COUNT) \
+ template <class FactoryParam> \
+ inline base_functor_caller( \
+ FactoryParam factory_param \
+ BOOST_PP_REPEAT( \
+ PARAM_COUNT, \
+ BOOST_MIRROR_BASE_FUNCTION_CALLER_DECL_DEFAULT_PARAM, \
+ _ \
+ ) \
+ ): _meta_functions() \
+ BOOST_PP_REPEAT( \
+ PARAM_COUNT, \
+ BOOST_MIRROR_BASE_FUNCTION_CALLER_INITIALIZE_FACTORY_W_DEF, \
+ factory_param \
+ ) { }
+
 #define BOOST_MIRROR_BASE_FUNCTION_CALLER_CALL_FACTORY(Z, INDEX, X) \
         BOOST_PP_CAT(_, INDEX)()
 
 
-#define BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER(PARAM_COUNT) \
+#define BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER_BEGIN(PARAM_COUNT)\
 template < \
         template <class> class Manufacturer, \
         class MetaFunctions, \
@@ -69,19 +100,20 @@
                 0 \
         ) \
  \
- typedef typename meta_function::result_type::reflected_type result;\
+ typedef typename meta_function::result_type::reflected_type result_type;\
  \
- template <class Param> \
- inline base_functor_caller(Param param) \
+ template <class FactoryParam> \
+ inline base_functor_caller(FactoryParam factory_param) \
          : _meta_functions() \
         BOOST_PP_REPEAT( \
                 PARAM_COUNT, \
                 BOOST_MIRROR_BASE_FUNCTION_CALLER_INITIALIZE_FACTORY, \
- param \
+ factory_param \
         ) { } \
- \
+
+#define BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER_END(PARAM_COUNT)\
         template <class Functor> \
- inline result call(Functor func) \
+ inline result_type call(Functor func) \
         { \
                 return func( \
                         BOOST_PP_ENUM( \
@@ -93,17 +125,29 @@
         } \
 };
 
+#define BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER(PARAM_COUNT) \
+BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER_BEGIN(PARAM_COUNT) \
+BOOST_MIRROR_BASE_FUNCTION_CALLER_DECLARE_CONSTR_W_DEF(PARAM_COUNT) \
+BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER_END(PARAM_COUNT)
+
 #define BOOST_MIRROR_DO_IMPLEMENT_BASE_FUNCTION_CALLER(Z, PARAM_COUNT, X) \
         BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER(PARAM_COUNT)
 
-BOOST_PP_REPEAT(
- BOOST_MIRROR_MAX_FUNC_PARAMS(),
+BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER_BEGIN(0)
+BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER_END(0)
+BOOST_PP_REPEAT_FROM_TO(
+ 1, BOOST_MIRROR_MAX_FUNC_PARAMS(),
         BOOST_MIRROR_DO_IMPLEMENT_BASE_FUNCTION_CALLER,
         0
 )
 
+#undef BOOST_MIRROR_BASE_FUNCTION_CALLER_DECLARE_CONSTR_W_DEF
+#undef BOOST_MIRROR_BASE_FUNCTION_CALLER_DECL_DEFAULT_PARAM
+#undef BOOST_MIRROR_BASE_FUNCTION_CALLER_INITIALIZE_FACTORY_W_DEF
 #undef BOOST_MIRROR_DO_IMPLEMENT_BASE_FUNCTION_CALLER
 #undef BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER
+#undef BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER_BEGIN
+#undef BOOST_MIRROR_IMPLEMENT_BASE_FUNCTION_CALLER_END
 #undef BOOST_MIRROR_BASE_FUNCTION_CALLER_CALL_FACTORY
 #undef BOOST_MIRROR_BASE_FUNCTION_CALLER_INITIALIZE_FACTORY
 #undef BOOST_MIRROR_BASE_FUNCTION_CALLER_DECLARE_FACTORY
@@ -132,22 +176,29 @@
                 template function<FunctionIndex>::params::size
> base_class;
 
- typedef typename base_class::result result;
+ typedef typename base_class::result_type result_type;
         typedef typename base_class::meta_function meta_function;
 
 public:
- template <class Param>
- functor_caller(Param param)
- : base_class(param)
+ template <class FactoryParam>
+ functor_caller(FactoryParam factory_param)
+ : base_class(factory_param)
+ { }
+
+#ifndef BOOST_NO_VARIADIC_TEMPLATES
+ template <class FactoryParam, class ...Defaults>
+ functor_caller(FactoryParam factory_param, Defaults ...defs)
+ : base_class(factory_param, defs...)
         { }
+#endif
 
- inline result operator()(void)
+ inline result_type operator()(void)
         {
                 return base_class::call(meta_function::wrap());
         }
 
         template <class Class>
- inline result operator()(Class& instance)
+ inline result_type operator()(Class& instance)
         {
                 return base_class::call(meta_function::wrap(instance));
         }
@@ -174,10 +225,17 @@
          : base_class(0)
         { }
 
- template <class Param>
- member_function_caller(Param param)
- : base_class(param)
+ template <class FactoryParam>
+ 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...)
         { }
+#endif
 
 };
 

Modified: sandbox/mirror/libs/mirror/example/factories/input_ui.hpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/factories/input_ui.hpp (original)
+++ sandbox/mirror/libs/mirror/example/factories/input_ui.hpp 2009-05-11 13:40:10 EDT (Mon, 11 May 2009)
@@ -13,6 +13,7 @@
 #define BOOST_MIRROR_EXAMPLES_FACTORIES_INPUT_UI_HPP
 
 #include <boost/char_type_switch/iostream.hpp>
+#include <boost/char_type_switch/sstream.hpp>
 
 #include <boost/mirror/factory.hpp>
 #include <boost/mirror/meta_type.hpp>
@@ -47,8 +48,13 @@
         typename ::boost::mirror::make_factory< input_ui, Product >::type f;
 
         template <class MetaFunctions, class FuncIndex, class ParamIndex>
- input_ui(int tabs, MetaFunctions mf, FuncIndex fi, ParamIndex pi)
- : b(tabs, mf, fi, pi)
+ input_ui(
+ int tabs,
+ MetaFunctions mf,
+ FuncIndex fi,
+ ParamIndex pi,
+ const Product* opt_default = (const Product*)0
+ ): b(tabs, mf, fi, pi)
          , f(tabs)
         { }
 
@@ -85,37 +91,68 @@
                 int tabs,
                 MetaFunctions mf,
                 FuncIndex fi,
- ParamIndex pi
+ ParamIndex pi,
+ const Product* opt_default
         )
         {
- typedef typename MetaFunctions::
- template function<FuncIndex> meta_function;
- //
- ::boost::cts::bcout() <<
- ::boost::cts::bstring(tabs, BOOST_CTS_LIT('\t')) <<
- BOOST_CTS_LIT("Enter ") <<
- BOOST_MIRRORED_TYPE(Product)::full_name() <<
- BOOST_CTS_LIT(" ") <<
- meta_function::params::
- template param<ParamIndex>::base_name() <<
- BOOST_CTS_LIT(" for ") <<
- meta_function::result_type::full_name() << (
- meta_function::is_constructor::value ?
- ::boost::cts::bstring() :
- ::boost::cts::bstring(BOOST_CTS_LIT(" "))
- ) << (
- meta_function::is_constructor::value ?
- ::boost::cts::bstring() :
- meta_function::base_name()
- ) << BOOST_CTS_LIT("(");
- //
- meta_function::params::
- for_each(constr_param_name_printer());
- //
+ typedef typename MetaFunctions::
+ template function<FuncIndex> meta_function;
+ //
+ ::boost::cts::bcout() <<
+ ::boost::cts::bstring(tabs, BOOST_CTS_LIT('\t')) <<
+ BOOST_CTS_LIT("Enter ") <<
+ BOOST_MIRRORED_TYPE(Product)::full_name() <<
+ BOOST_CTS_LIT(" ") <<
+ meta_function::params::
+ template param<ParamIndex>::base_name() <<
+ BOOST_CTS_LIT(" for ") <<
+ meta_function::result_type::full_name() << (
+ meta_function::is_constructor::value ?
+ ::boost::cts::bstring() :
+ ::boost::cts::bstring(BOOST_CTS_LIT(" "))
+ ) << (
+ meta_function::is_constructor::value ?
+ ::boost::cts::bstring() :
+ meta_function::base_name()
+ ) << BOOST_CTS_LIT("(");
+ //
+ meta_function::params::
+ for_each(constr_param_name_printer());
+ //
+ ::boost::cts::bcout() <<
+ BOOST_CTS_LIT(") ");
+ if(opt_default)
+ {
                         ::boost::cts::bcout() <<
- BOOST_CTS_LIT(") = ") <<
- ::std::flush;
- ::boost::cts::bcin() >> x;
+ BOOST_CTS_LIT("[") <<
+ *opt_default <<
+ BOOST_CTS_LIT("]");
+
+ }
+ ::boost::cts::bcout() <<
+ BOOST_CTS_LIT(" = ") <<
+ ::std::flush;
+ //
+ while(1)
+ {
+ ::boost::cts::bstring input;
+ ::std::getline(::boost::cts::bcin(), input);
+ if(input.empty())
+ {
+ if(opt_default)
+ {
+ x = *opt_default;
+ break;
+ }
+ }
+ else
+ {
+ ::boost::cts::bstringstream tmp(input);
+ tmp >> x;
+ break;
+
+ }
+ }
         }
 
         inline Product operator()(void)
@@ -129,8 +166,13 @@
 struct input_ui< TYPE > : console_input_ui< TYPE > \
 { \
         template <class MetaFunctions, class FuncIndex, class ParamIndex> \
- input_ui(int tabs, MetaFunctions mf, FuncIndex fi, ParamIndex pi) \
- : console_input_ui< TYPE >(tabs, mf, fi, pi) \
+ input_ui( \
+ int tabs, \
+ MetaFunctions mf, \
+ FuncIndex fi, \
+ ParamIndex pi, \
+ const TYPE* opt_default = (const TYPE*)0 \
+ ): console_input_ui< TYPE >(tabs, mf, fi, pi, opt_default) \
         { } \
 };
 

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-11 13:40:10 EDT (Mon, 11 May 2009)
@@ -94,11 +94,23 @@
                                 BOOST_CTS_LIT("Change persons address ? (y/n) ") <<
                                 ::std::flush;
                         cts::bcin() >> change_address;
+ cts::bcin().ignore();
                 } while(change_address != yes && change_address != no);
                 if(change_address == yes)
                 {
+ person& p(persons.back());
+#ifdef BOOST_NO_VARIADIC_TEMPLATES
                         member_function_caller<input_ui, person, 0> func;
- func(persons.back());
+#else
+ member_function_caller<input_ui, person, 0> func(
+ 0,
+ p.street,
+ p.number,
+ p.city,
+ p.postal_code
+ );
+#endif
+ func(p);
                 }
                 // check whether to insert more persons
                 do
@@ -107,6 +119,7 @@
                                 BOOST_CTS_LIT("Insert more ? (y/n) ") <<
                                 ::std::flush;
                         cts::bcin() >> insert_more;
+ cts::bcin().ignore();
                 } while(insert_more != yes && insert_more != no);
         }
         //


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