$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r56464 - in trunk/boost/spirit/home/karma/numeric: . detail
From: hartmut.kaiser_at_[hidden]
Date: 2009-09-28 21:25:38
Author: hkaiser
Date: 2009-09-28 21:25:37 EDT (Mon, 28 Sep 2009)
New Revision: 56464
URL: http://svn.boost.org/trac/boost/changeset/56464
Log:
Spirit: refined bool_policies
Added:
   trunk/boost/spirit/home/karma/numeric/detail/bool_utils.hpp   (contents, props changed)
Text files modified: 
   trunk/boost/spirit/home/karma/numeric/bool.hpp          |    13 +++++----                               
   trunk/boost/spirit/home/karma/numeric/bool_policies.hpp |    54 +++++++++++++++++++++++++++++++++------ 
   2 files changed, 52 insertions(+), 15 deletions(-)
Modified: trunk/boost/spirit/home/karma/numeric/bool.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/bool.hpp	(original)
+++ trunk/boost/spirit/home/karma/numeric/bool.hpp	2009-09-28 21:25:37 EDT (Mon, 28 Sep 2009)
@@ -22,6 +22,7 @@
 #include <boost/spirit/home/karma/detail/get_casetag.hpp>
 #include <boost/spirit/home/karma/domain.hpp>
 #include <boost/spirit/home/karma/numeric/bool_policies.hpp>
+#include <boost/spirit/home/karma/numeric/detail/bool_utils.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 namespace boost { namespace spirit
@@ -129,8 +130,8 @@
             if (!traits::has_optional_value(attr))
                 return false;       // fail if it's an uninitialized optional
 
-            return p_.template generate<CharEncoding, Tag>(
-                        sink, traits::optional_value(attr)) &&
+            return bool_inserter<T, Policies, CharEncoding, Tag>::call(
+                        sink, traits::optional_value(attr), p_) &&
                    delimit_out(sink, d);      // always do post-delimiting
         }
 
@@ -188,8 +189,8 @@
             {
                 return false;
             }
-            return p_.template generate<CharEncoding, Tag>(sink, n_) && 
-                   delimit_out(sink, d);
+            return bool_inserter<T, Policies, CharEncoding, Tag>::
+                      call(sink, n_, p_) && delimit_out(sink, d);
         }
 
         // A bool_() without any associated attribute just emits its 
@@ -198,8 +199,8 @@
         bool generate(OutputIterator& sink, Context&, Delimiter const& d
           , unused_type) const
         {
-            return p_.template generate<CharEncoding, Tag>(sink, n_) && 
-                   delimit_out(sink, d);
+            return bool_inserter<T, Policies, CharEncoding, Tag>::
+                      call(sink, n_) && delimit_out(sink, d);
         }
 
         template <typename Context>
Modified: trunk/boost/spirit/home/karma/numeric/bool_policies.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/bool_policies.hpp	(original)
+++ trunk/boost/spirit/home/karma/numeric/bool_policies.hpp	2009-09-28 21:25:37 EDT (Mon, 28 Sep 2009)
@@ -25,19 +25,18 @@
     //
     //      struct special_bool_policy : karma::bool_policies<>
     //      {
+    //          //  we want to spell the names of false as eurt (true backwards)
     //          template <typename CharEncoding, typename Tag
     //            , typename OutputIterator>
-    //          static bool generate (OutputIterator& sink, bool b)
+    //          static bool generate_flase(OutputIterator& sink, bool)
     //          {
-    //              //  we want to spell the names of true and false backwards
-    //              return string_inserter<CharEncoding, Tag>::call(
-    //                  sink, b ? "eurt" : "aslaf");
+    //              return string_inserter<CharEncoding, Tag>::call(sink, "eurt");
     //          }
     //      };
     //
     //      typedef karma::bool_generator<special_bool_policy> backwards_bool;
     //
-    //      karma::generate(sink, backwards_bool(), true); // will output: eurt
+    //      karma::generate(sink, backwards_bool(), false); // will output: eurt
     //
     ///////////////////////////////////////////////////////////////////////////
     template <typename T = bool>
@@ -57,7 +56,45 @@
         typedef mpl::int_<generator_properties::no_properties> properties;
 
         ///////////////////////////////////////////////////////////////////////
-        //  Print the textual representations of the given boolean value
+        //  This is the main function used to generate the output for a 
+        //  boolean. It is called by the boolean generator in order 
+        //  to perform the conversion. In theory all of the work can be 
+        //  implemented here, but it is the easiest to use existing 
+        //  functionality provided by the type specified by the template 
+        //  parameter `Inserter`. 
+        //
+        //      sink: the output iterator to use for generation
+        //      n:    the floating point number to convert 
+        //      p:    the instance of the policy type used to instantiate this 
+        //            floating point generator.
+        ///////////////////////////////////////////////////////////////////////
+        template <typename Inserter, typename OutputIterator, typename Policies>
+        static bool
+        call (OutputIterator& sink, T n, Policies const& p)
+        {
+            return Inserter::call_n(sink, n, p);
+        }
+
+        ///////////////////////////////////////////////////////////////////////
+        //  Print the textual representations of a true boolean value
+        //
+        //      sink       The output iterator to use for generation
+        //      b          The boolean value to convert. 
+        //
+        //  The CharEncoding and Tag template parameters are either of the type 
+        //  unused_type or describes the character class and conversion to be 
+        //  applied to any output possibly influenced by either the lower[...] 
+        //  or upper[...] directives.
+        //
+        ///////////////////////////////////////////////////////////////////////
+        template <typename CharEncoding, typename Tag, typename OutputIterator>
+        static bool generate_true(OutputIterator& sink, T b)
+        {
+            return string_inserter<CharEncoding, Tag>::call(sink, "true");
+        }
+
+        ///////////////////////////////////////////////////////////////////////
+        //  Print the textual representations of a false boolean value
         //
         //      sink       The output iterator to use for generation
         //      b          The boolean value to convert. 
@@ -69,10 +106,9 @@
         //
         ///////////////////////////////////////////////////////////////////////
         template <typename CharEncoding, typename Tag, typename OutputIterator>
-        static bool generate (OutputIterator& sink, T b)
+        static bool generate_false(OutputIterator& sink, T b)
         {
-            return string_inserter<CharEncoding, Tag>::call(
-                sink, b ? "true" : "false");
+            return string_inserter<CharEncoding, Tag>::call(sink, "false");
         }
     };
 
Added: trunk/boost/spirit/home/karma/numeric/detail/bool_utils.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/karma/numeric/detail/bool_utils.hpp	2009-09-28 21:25:37 EDT (Mon, 28 Sep 2009)
@@ -0,0 +1,60 @@
+//  Copyright (c) 2001-2009 Hartmut Kaiser
+// 
+//  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)
+
+#if !defined(BOOST_SPIRIT_KARMA_BOOL_UTILS_SEP_28_2009_0644PM)
+#define BOOST_SPIRIT_KARMA_BOOL_UTILS_SEP_28_2009_0644PM
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/spirit/home/support/char_class.hpp>
+#include <boost/spirit/home/support/unused.hpp>
+#include <boost/spirit/home/karma/detail/generate_to.hpp>
+#include <boost/spirit/home/karma/detail/string_generate.hpp>
+#include <boost/spirit/home/karma/numeric/detail/numeric_utils.hpp>
+
+namespace boost { namespace spirit { namespace karma 
+{ 
+    ///////////////////////////////////////////////////////////////////////////
+    //
+    //  The bool_inserter template takes care of the boolean to string 
+    //  conversion. The Policies template parameter is used to allow
+    //  customization of the formatting process
+    //
+    ///////////////////////////////////////////////////////////////////////////
+    template <typename T>
+    struct bool_policies;
+
+    template <typename T
+      , typename Policies = bool_policies<T>
+      , typename CharEncoding = unused_type
+      , typename Tag = unused_type>
+    struct bool_inserter
+    {
+        template <typename OutputIterator, typename U>
+        static bool
+        call (OutputIterator& sink, U b, Policies const& p = Policies())
+        {
+            return p.template call<bool_inserter>(sink, T(b), p);
+        }
+
+        ///////////////////////////////////////////////////////////////////////
+        //  This is the workhorse behind the real generator
+        ///////////////////////////////////////////////////////////////////////
+        template <typename OutputIterator, typename U>
+        static bool
+        call_n (OutputIterator& sink, U b, Policies const& p)
+        {
+            if (b) 
+                return p.template generate_true<CharEncoding, Tag>(sink, b);
+            return p.template generate_false<CharEncoding, Tag>(sink, b);
+        }
+    };
+
+}}}
+
+#endif
+