Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50289 - in sandbox/mirror: boost/mirror libs/mirror/example/factories
From: chochlik_at_[hidden]
Date: 2008-12-16 04:55:56


Author: matus.chochlik
Date: 2008-12-16 04:55:56 EST (Tue, 16 Dec 2008)
New Revision: 50289
URL: http://svn.boost.org/trac/boost/changeset/50289

Log:
[mirror 0.3.x]
 - minor updates to the meta_constructor
 - fix of the tetrahedron factory example

Added:
   sandbox/mirror/libs/mirror/example/factories/input_ui.hpp (contents, props changed)
Text files modified:
   sandbox/mirror/boost/mirror/meta_constructors.hpp | 1
   sandbox/mirror/libs/mirror/example/factories/tetrahedron.cpp | 105 +--------------------------------------
   2 files changed, 6 insertions(+), 100 deletions(-)

Modified: sandbox/mirror/boost/mirror/meta_constructors.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/meta_constructors.hpp (original)
+++ sandbox/mirror/boost/mirror/meta_constructors.hpp 2008-12-16 04:55:56 EST (Tue, 16 Dec 2008)
@@ -29,6 +29,7 @@
 #include <boost/preprocessor/stringize.hpp>
 #include <boost/preprocessor/wstringize.hpp>
 
+#include <boost/char_type_switch/string.hpp>
 
 namespace boost {
 namespace mirror {

Added: sandbox/mirror/libs/mirror/example/factories/input_ui.hpp
==============================================================================
--- (empty file)
+++ sandbox/mirror/libs/mirror/example/factories/input_ui.hpp 2008-12-16 04:55:56 EST (Tue, 16 Dec 2008)
@@ -0,0 +1,128 @@
+/**
+ * \file examples/factories/input_ui.hpp
+ *
+ * Simple console based user interface plug-in for mirror::factory
+ * used in the examples in this directory
+ *
+ * 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_EXAMPLES_FACTORIES_INPUT_UI_HPP
+#define BOOST_MIRROR_EXAMPLES_FACTORIES_INPUT_UI_HPP
+
+#include <boost/char_type_switch/iostream.hpp>
+
+#include <boost/mirror/factory.hpp>
+#include <boost/mirror/meta_type.hpp>
+
+namespace test {
+
+/** The general implementation of the input user interface template.
+ * Upon construction prints-out a banner and uses a factory
+ * configured to use the same input user interface to construct
+ * the Product.
+ */
+template <class Product>
+struct input_ui
+{
+ struct banner
+ {
+ template <class Context, class ConstrIndex, class ParamIndex>
+ banner(int tabs, Context* pc, ConstrIndex ci, ParamIndex pi)
+ {
+ ::std::cout <<
+ ::boost::cts::bstring(tabs, BOOST_CTS_LIT('\t')) <<
+ BOOST_CTS_LIT("Construct ") <<
+ BOOST_MIRRORED_TYPE(Product)::full_name() <<
+ BOOST_CTS_LIT(" ") <<
+ boost::mirror::meta_constructors<
+ Context
+ >::base_param_name(ci, pi) <<
+ ::std::endl;
+ }
+ } b;
+
+ typename ::boost::mirror::make_factory< input_ui, Product >::type f;
+
+ template <class Context, class ConstrIndex, class ParamIndex>
+ input_ui(int tabs, Context* pc, ConstrIndex ci, ParamIndex pi)
+ : b(tabs, pc, ci, pi)
+ , f(tabs)
+ { }
+
+ inline Product operator()(void)
+ {
+ return f();
+ }
+};
+
+/** Specialization of the input interface, used to produce
+ * doubles by prompting the user to enter a value on the
+ * console.
+ */
+template <>
+struct input_ui<double>
+{
+ double x;
+
+ template <class Context, class ConstrIndex, class ParamIndex>
+ input_ui(int tabs, Context* pc, ConstrIndex ci, ParamIndex pi)
+ {
+ ::std::cout <<
+ ::boost::cts::bstring(tabs, BOOST_CTS_LIT('\t')) <<
+ BOOST_CTS_LIT("Enter ") <<
+ BOOST_MIRRORED_TYPE(double)::full_name() <<
+ BOOST_CTS_LIT(" ") <<
+ boost::mirror::meta_constructors<
+ Context
+ >::base_param_name(ci, pi) <<
+ BOOST_CTS_LIT(" = ") <<
+ ::std::flush;
+ ::std::cin >> x;
+ }
+
+ inline double operator()(void)
+ {
+ return x;
+ }
+};
+
+/** A manager of this input user interface, which picks the
+ * constructor that will be used by the means of the result
+ * of the index member function (i.e. the zero-th registered
+ * constructor will be always used with this manager).
+ */
+template <>
+struct input_ui<void>
+{
+ int tabs;
+
+ input_ui(int _tabs, int factory_index)
+ : tabs(_tabs)
+ { }
+
+ input_ui(const ::boost::cts::bchar* names[], int factory_index)
+ : tabs(0)
+ {
+ ::std::cout <<
+ BOOST_CTS_LIT("Create ") <<
+ names[factory_index] << ::std::endl;
+ }
+
+ inline int param(void) const
+ {
+ return tabs+1;
+ }
+
+ inline int index(void)
+ {
+ return 0;
+ }
+};
+
+} // namespace test
+
+#endif
+

Modified: sandbox/mirror/libs/mirror/example/factories/tetrahedron.cpp
==============================================================================
--- sandbox/mirror/libs/mirror/example/factories/tetrahedron.cpp (original)
+++ sandbox/mirror/libs/mirror/example/factories/tetrahedron.cpp 2008-12-16 04:55:56 EST (Tue, 16 Dec 2008)
@@ -17,6 +17,8 @@
 #include <boost/mirror/factory.hpp>
 #include <boost/mirror/meta_type.hpp>
 
+#include "./input_ui.hpp"
+
 namespace test {
         
 struct vector
@@ -106,103 +108,6 @@
 };
 
 
-/** The general implementation of the input user interface template.
- * Upon construction prints-out a banner and uses a factory
- * configured to use the same input user interface to construct
- * the Product.
- */
-template <class Product>
-struct input_ui
-{
- struct banner
- {
- template <class Context, class ConstrIndex, class ParamIndex>
- banner(Context* pc, ConstrIndex ci, ParamIndex pi)
- {
- ::std::cout <<
- "Construct " <<
- BOOST_MIRRORED_TYPE(Product)::full_name() <<
- " " <<
- boost::mirror::meta_constructors<
- Context
- >::base_param_name(ci, pi) <<
- ::std::endl;
- }
- } b;
-
- typename ::boost::mirror::make_factory< input_ui, Product >::type f;
-
- template <class Context, class ConstrIndex, class ParamIndex>
- input_ui(int _x, Context* pc, ConstrIndex ci, ParamIndex pi)
- : b(pc, ci, pi)
- , f(_x)
- { }
-
- inline Product operator()(void)
- {
- return f();
- }
-};
-
-/** Specialization of the input interface, used to produce
- * doubles by prompting the user to enter a value on the
- * console.
- */
-template <>
-struct input_ui<double>
-{
- double x;
-
- template <class Context, class ConstrIndex, class ParamIndex>
- input_ui(int _x, Context* pc, ConstrIndex ci, ParamIndex pi)
- {
- ::std::cout <<
- "Enter " <<
- BOOST_MIRRORED_TYPE(double)::full_name() <<
- " " <<
- boost::mirror::meta_constructors<
- Context
- >::base_param_name(ci, pi) <<
- " = " <<
- ::std::flush;
- ::std::cin >> x;
- }
-
- inline double operator()(void)
- {
- return x;
- }
-};
-
-/** A manager of this input user interface, which picks the
- * constructor that will be used by the means of the result
- * of the index member function (i.e. the zero-th registered
- * constructor will be always used with this manager).
- */
-template <>
-struct input_ui<void>
-{
-
- input_ui(int _x, int factory_index)
- { }
-
- input_ui(const char* names[], int factory_index)
- {
- ::std::cout << "Create " << names[factory_index] << ::std::endl;
- }
-
- inline int param(void) const
- {
- // no params
- return 0;
- }
-
- inline int index(void)
- {
- return 0;
- }
-};
-
 } // namespace test
 
 
@@ -250,14 +155,14 @@
         using namespace ::boost::mirror;
         //
         // create a factory plugged with the input ui
- const char* param_names[] = {"a tetrahedron"};
+ const cts::bchar* param_names[] = {BOOST_CTS_LIT("a tetrahedron")};
         factory< ::test::input_ui, ::test::tetrahedron > f(param_names, 0);
         // use the factory to construct a tetrahedron and calculate
         // it's volume and base area
         ::test::tetrahedron t(f());
         // ... and print them out
- cout << "the volume is " << t.volume() << endl;
- cout << "the area of the base is " << t.base.area() << endl;
+ cout << BOOST_CTS_LIT("the volume is ") << t.volume() << endl;
+ cout << BOOST_CTS_LIT("the area of the base is ") << t.base.area() << endl;
         //
         return 0;
 }


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