Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56459 - in trunk/boost/spirit: home/karma home/karma/action home/karma/numeric home/support include
From: hartmut.kaiser_at_[hidden]
Date: 2009-09-28 16:52:08


Author: hkaiser
Date: 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
New Revision: 56459
URL: http://svn.boost.org/trac/boost/changeset/56459

Log:
Spirit: added bool_ generators
Added:
   trunk/boost/spirit/home/karma/numeric/bool.hpp (contents, props changed)
   trunk/boost/spirit/home/karma/numeric/bool_policies.hpp (contents, props changed)
   trunk/boost/spirit/include/karma_bool.hpp (contents, props changed)
Text files modified:
   trunk/boost/spirit/home/karma/action/action.hpp | 5 -
   trunk/boost/spirit/home/karma/numeric.hpp | 1
   trunk/boost/spirit/home/karma/numeric/int.hpp | 110 ++++++++++++++++++++-----------------
   trunk/boost/spirit/home/karma/numeric/real.hpp | 116 ++++++++++++++++++++++-----------------
   trunk/boost/spirit/home/karma/numeric/real_policies.hpp | 2
   trunk/boost/spirit/home/karma/numeric/uint.hpp | 116 +++++++++++++++++++++------------------
   trunk/boost/spirit/home/support/attributes.hpp | 6 --
   trunk/boost/spirit/home/support/common_terminals.hpp | 51 +++++++++++++++++
   8 files changed, 238 insertions(+), 169 deletions(-)

Modified: trunk/boost/spirit/home/karma/action/action.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/action/action.hpp (original)
+++ trunk/boost/spirit/home/karma/action/action.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -54,13 +54,12 @@
             typedef traits::make_attribute<attr_type, Attribute> make_attribute;
 
             // create a attribute if none is supplied
- // this creates a _copy_ of the parameter because the semantic
- // action likely will change parts of this
+ // this creates a _copy_ of the attribute because the semantic
+ // action will likely change parts of this
             typename make_attribute::value_type attr = make_attribute::call(attr_);
 
             // call the function, passing the attribute, the context and a bool
             // flag that the client can set to false to fail generating.
- // The client can return false to fail parsing.
             return traits::action_dispatch<Subject>()(f, attr, ctx) &&
                    subject.generate(sink, ctx, d, attr);
         }

Modified: trunk/boost/spirit/home/karma/numeric.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -10,6 +10,7 @@
 #pragma once
 #endif
 
+#include <boost/spirit/home/karma/numeric/bool.hpp>
 #include <boost/spirit/home/karma/numeric/int.hpp>
 #include <boost/spirit/home/karma/numeric/uint.hpp>
 #include <boost/spirit/home/karma/numeric/real.hpp>

Added: trunk/boost/spirit/home/karma/numeric/bool.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/karma/numeric/bool.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -0,0 +1,350 @@
+// 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_SEP_28_2009_1113AM)
+#define BOOST_SPIRIT_KARMA_BOOL_SEP_28_2009_1113AM
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <limits>
+
+#include <boost/spirit/home/support/common_terminals.hpp>
+#include <boost/spirit/home/support/string_traits.hpp>
+#include <boost/spirit/home/support/info.hpp>
+#include <boost/spirit/home/support/char_class.hpp>
+#include <boost/spirit/home/karma/meta_compiler.hpp>
+#include <boost/spirit/home/karma/delimit_out.hpp>
+#include <boost/spirit/home/karma/auxiliary/lazy.hpp>
+#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>
+
+///////////////////////////////////////////////////////////////////////////////
+namespace boost { namespace spirit
+{
+ namespace tag
+ {
+ template <typename T, typename Policies>
+ struct bool_tag
+ {
+ bool_tag() {}
+ bool_tag(Policies const& policies)
+ : policies_(policies) {}
+
+ Policies policies_;
+ };
+ }
+
+ namespace karma
+ {
+ ///////////////////////////////////////////////////////////////////////
+ // forward declaration only
+ template <typename T>
+ struct bool_policies;
+
+ ///////////////////////////////////////////////////////////////////////
+ // This one is the class that the user can instantiate directly in
+ // order to create a customized int generator
+ template <typename T = bool, typename Policies = bool_policies<T> >
+ struct bool_generator
+ : spirit::terminal<tag::bool_tag<T, Policies> >
+ {};
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Enablers
+ ///////////////////////////////////////////////////////////////////////////
+ template <>
+ struct use_terminal<karma::domain, tag::bool_> // enables bool_
+ : mpl::true_ {};
+
+ template <>
+ struct use_terminal<karma::domain, bool> // enables lit(true)
+ : mpl::true_ {};
+
+ template <typename A0>
+ struct use_terminal<karma::domain // enables bool_(...)
+ , terminal_ex<tag::bool_, fusion::vector1<A0> >
+ > : mpl::true_ {};
+
+ template <> // enables *lazy* bool_(...)
+ struct use_lazy_terminal<karma::domain, tag::bool_, 1>
+ : mpl::true_ {};
+
+ ///////////////////////////////////////////////////////////////////////////
+ // enables any custom bool_generator
+ template <typename T, typename Policies>
+ struct use_terminal<karma::domain, tag::bool_tag<T, Policies> >
+ : mpl::true_ {};
+
+ // enables any custom bool_generator(...)
+ template <typename T, typename Policies, typename A0>
+ struct use_terminal<karma::domain
+ , terminal_ex<tag::bool_tag<T, Policies>, fusion::vector1<A0> >
+ > : mpl::true_ {};
+
+ // enables *lazy* custom bool_generator
+ template <typename T, typename Policies>
+ struct use_lazy_terminal<karma::domain, tag::bool_tag<T, Policies>, 1>
+ : mpl::true_ {};
+
+}}
+
+///////////////////////////////////////////////////////////////////////////////
+namespace boost { namespace spirit { namespace karma
+{
+ using spirit::bool_;
+ using spirit::bool__type;
+
+ using spirit::lit; // lit(true) is equivalent to true
+
+ ///////////////////////////////////////////////////////////////////////////
+ // This specialization is used for bool generators not having a direct
+ // initializer: bool_. These generators must be used in conjunction with
+ // an Attribute.
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename T, typename CharEncoding, typename Tag, typename Policies>
+ struct any_bool_generator
+ : primitive_generator<any_bool_generator<T, CharEncoding, Tag, Policies> >
+ {
+ public:
+ any_bool_generator(Policies const& p = Policies())
+ : p_(p) {}
+
+ typedef typename Policies::properties properties;
+
+ template <typename Context, typename Unused>
+ struct attribute
+ {
+ typedef T type;
+ };
+
+ // bool_ has a Attribute attached
+ template <typename OutputIterator, typename Context, typename Delimiter
+ , typename Attribute>
+ bool
+ generate(OutputIterator& sink, Context&, Delimiter const& d
+ , Attribute const& attr) const
+ {
+ 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)) &&
+ delimit_out(sink, d); // always do post-delimiting
+ }
+
+ // this bool_ has no Attribute attached, it needs to have been
+ // initialized from a direct literal
+ template <typename OutputIterator, typename Context, typename Delimiter>
+ static bool
+ generate(OutputIterator&, Context&, Delimiter const&, unused_type)
+ {
+ BOOST_SPIRIT_ASSERT_MSG(false, bool_not_usable_without_attribute, ());
+ return false;
+ }
+
+ template <typename Context>
+ static info what(Context const& ctx)
+ {
+ return info("bool");
+ }
+
+ Policies p_;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // This specialization is used for bool generators having a direct
+ // initializer: bool_(true), bool_(0) etc.
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename T, typename CharEncoding, typename Tag
+ , typename Policies, bool no_attribute>
+ struct literal_bool_generator
+ : primitive_generator<literal_bool_generator<T, CharEncoding, Tag
+ , Policies, no_attribute> >
+ {
+ public:
+ typedef typename Policies::properties properties;
+
+ template <typename Context, typename Unused>
+ struct attribute
+ : mpl::if_c<no_attribute, unused_type, T>
+ {};
+
+ literal_bool_generator(typename add_const<T>::type n
+ , Policies const& p = Policies())
+ : n_(n), p_(p) {}
+
+ // A bool_() which additionally has an associated attribute emits
+ // its immediate literal only if it matches the attribute, otherwise
+ // it fails.
+ template <typename OutputIterator, typename Context, typename Delimiter
+ , typename Attribute>
+ bool generate(OutputIterator& sink, Context&, Delimiter const& d
+ , Attribute const& attr) const
+ {
+ if (!traits::has_optional_value(attr) ||
+ n_ != traits::optional_value(attr))
+ {
+ return false;
+ }
+ return p_.template generate<CharEncoding, Tag>(sink, n_) &&
+ delimit_out(sink, d);
+ }
+
+ // A bool_() without any associated attribute just emits its
+ // immediate literal
+ template <typename OutputIterator, typename Context, typename Delimiter>
+ bool generate(OutputIterator& sink, Context&, Delimiter const& d
+ , unused_type) const
+ {
+ return p_.template generate<CharEncoding, Tag>(sink, n_) &&
+ delimit_out(sink, d);
+ }
+
+ template <typename Context>
+ static info what(Context const& ctx)
+ {
+ return info("bool");
+ }
+
+ T n_;
+ Policies p_;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ // extract policies if this is a bool_tag
+ template <typename Policies>
+ struct get_bool_policies
+ {
+ template <typename Tag>
+ static Policies call(Tag) { return Policies(); }
+
+ template <typename T>
+ static Policies const& call(tag::bool_tag<T, Policies> const& p)
+ { return p.policies_; }
+ };
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Generator generators: make_xxx function (objects)
+ ///////////////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ template <typename Modifiers, typename T = bool
+ , typename Policies = bool_policies<T> >
+ struct make_bool
+ {
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef any_bool_generator<
+ T
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ , Policies
+ > result_type;
+
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ using karma::detail::get_bool_policies;
+ return result_type(get_bool_policies<Policies>::call(term));
+ }
+ };
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Modifiers>
+ struct make_primitive<tag::bool_, Modifiers>
+ : detail::make_bool<Modifiers> {};
+
+ template <typename T, typename Policies, typename Modifiers>
+ struct make_primitive<tag::bool_tag<T, Policies>, Modifiers>
+ : detail::make_bool<Modifiers, T, Policies> {};
+
+ ///////////////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ template <typename Modifiers, typename T = bool
+ , typename Policies = bool_policies<T> >
+ struct make_bool_direct
+ {
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef literal_bool_generator<
+ T
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ , Policies, false
+ > result_type;
+
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ using karma::detail::get_bool_policies;
+ return result_type(fusion::at_c<0>(term.args)
+ , get_bool_policies<Policies>::call(term.term));
+ }
+ };
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Modifiers, typename A0>
+ struct make_primitive<
+ terminal_ex<tag::bool_, fusion::vector1<A0> >, Modifiers>
+ : detail::make_bool_direct<Modifiers> {};
+
+ template <typename T, typename Policies, typename A0, typename Modifiers>
+ struct make_primitive<
+ terminal_ex<tag::bool_tag<T, Policies>, fusion::vector1<A0> >
+ , Modifiers>
+ : detail::make_bool_direct<Modifiers, T, Policies> {};
+
+ ///////////////////////////////////////////////////////////////////////////
+ namespace detail
+ {
+ template <typename Modifiers>
+ struct basic_bool_literal
+ {
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef literal_bool_generator<
+ bool
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ , bool_policies<>, true
+ > result_type;
+
+ template <typename T_>
+ result_type operator()(T_ i, unused_type) const
+ {
+ return result_type(i);
+ }
+ };
+ }
+
+ template <typename Modifiers>
+ struct make_primitive<bool, Modifiers>
+ : detail::basic_bool_literal<Modifiers> {};
+
+}}}
+
+#endif

Added: trunk/boost/spirit/home/karma/numeric/bool_policies.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/karma/numeric/bool_policies.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -0,0 +1,80 @@
+// 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_POLICIES_SEP_28_2009_1203PM)
+#define BOOST_SPIRIT_KARMA_BOOL_POLICIES_SEP_28_2009_1203PM
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/spirit/home/support/char_class.hpp>
+#include <boost/spirit/home/karma/generate.hpp>
+#include <boost/spirit/home/karma/char.hpp>
+
+namespace boost { namespace spirit { namespace karma
+{
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // bool_policies, if you need special handling of your boolean output
+ // just overload this policy class and use it as a template
+ // parameter to the karma::bool_generator boolean generator
+ //
+ // struct special_bool_policy : karma::bool_policies<>
+ // {
+ // template <typename CharEncoding, typename Tag
+ // , typename OutputIterator>
+ // static bool generate (OutputIterator& sink, bool b)
+ // {
+ // // we want to spell the names of true and false backwards
+ // return string_inserter<CharEncoding, Tag>::call(
+ // sink, b ? "eurt" : "aslaf");
+ // }
+ // };
+ //
+ // typedef karma::bool_generator<special_bool_policy> backwards_bool;
+ //
+ // karma::generate(sink, backwards_bool(), true); // will output: eurt
+ //
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename T = bool>
+ struct bool_policies
+ {
+ ///////////////////////////////////////////////////////////////////////
+ // Expose the data type the generator is targeted at
+ ///////////////////////////////////////////////////////////////////////
+ typedef T value_type;
+
+ ///////////////////////////////////////////////////////////////////////
+ // By default the policy doesn't require any special iterator
+ // functionality. The boolean generator exposes its properties
+ // from here, so this needs to be updated in case other properties
+ // need to be implemented.
+ ///////////////////////////////////////////////////////////////////////
+ typedef mpl::int_<generator_properties::no_properties> properties;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Print the textual representations of the given 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 (OutputIterator& sink, T b)
+ {
+ return string_inserter<CharEncoding, Tag>::call(
+ sink, b ? "true" : "false");
+ }
+ };
+
+}}}
+
+#endif

Modified: trunk/boost/spirit/home/karma/numeric/int.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/int.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/int.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -311,99 +311,105 @@
     ///////////////////////////////////////////////////////////////////////////
     // Generator generators: make_xxx function (objects)
     ///////////////////////////////////////////////////////////////////////////
- template <typename T, typename Modifiers, unsigned Radix = 10
- , bool force_sign = false>
- struct make_int
+ namespace detail
     {
- static bool const lower =
- has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
- static bool const upper =
- has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
-
- typedef any_int_generator<
- T
- , typename spirit::detail::get_encoding<
- Modifiers, unused_type, lower || upper>::type
- , typename detail::get_casetag<Modifiers, lower || upper>::type
- , Radix
- , force_sign
- > result_type;
-
- result_type operator()(unused_type, unused_type) const
+ template <typename T, typename Modifiers, unsigned Radix = 10
+ , bool force_sign = false>
+ struct make_int
         {
- return result_type();
- }
- };
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef any_int_generator<
+ T
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ , Radix
+ , force_sign
+ > result_type;
+
+ result_type operator()(unused_type, unused_type) const
+ {
+ return result_type();
+ }
+ };
+ }
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename Modifiers>
     struct make_primitive<tag::short_, Modifiers>
- : make_int<short, Modifiers> {};
+ : detail::make_int<short, Modifiers> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::int_, Modifiers>
- : make_int<int, Modifiers> {};
+ : detail::make_int<int, Modifiers> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::long_, Modifiers>
- : make_int<long, Modifiers> {};
+ : detail::make_int<long, Modifiers> {};
 
 #ifdef BOOST_HAS_LONG_LONG
     template <typename Modifiers>
     struct make_primitive<tag::long_long, Modifiers>
- : make_int<boost::long_long_type, Modifiers> {};
+ : detail::make_int<boost::long_long_type, Modifiers> {};
 #endif
 
     template <typename T, unsigned Radix, bool force_sign, typename Modifiers>
     struct make_primitive<tag::int_tag<T, Radix, force_sign>, Modifiers>
- : make_int<T, Modifiers, Radix, force_sign> {};
+ : detail::make_int<T, Modifiers, Radix, force_sign> {};
 
     ///////////////////////////////////////////////////////////////////////////
- template <typename T, typename Modifiers, unsigned Radix = 10
- , bool force_sign = false>
- struct make_int_direct
+ namespace detail
     {
- static bool const lower =
- has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
- static bool const upper =
- has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
-
- typedef literal_int_generator<
- T
- , typename spirit::detail::get_encoding<
- Modifiers, unused_type, lower || upper>::type
- , typename detail::get_casetag<Modifiers, lower || upper>::type
- , Radix, force_sign, false
- > result_type;
-
- template <typename Terminal>
- result_type operator()(Terminal const& term, unused_type) const
+ template <typename T, typename Modifiers, unsigned Radix = 10
+ , bool force_sign = false>
+ struct make_int_direct
         {
- return result_type(fusion::at_c<0>(term.args));
- }
- };
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef literal_int_generator<
+ T
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ , Radix, force_sign, false
+ > result_type;
+
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ return result_type(fusion::at_c<0>(term.args));
+ }
+ };
+ }
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::short_, fusion::vector1<A0> >, Modifiers>
- : make_int_direct<short, Modifiers> {};
+ : detail::make_int_direct<short, Modifiers> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::int_, fusion::vector1<A0> >, Modifiers>
- : make_int_direct<int, Modifiers> {};
+ : detail::make_int_direct<int, Modifiers> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::long_, fusion::vector1<A0> >, Modifiers>
- : make_int_direct<long, Modifiers> {};
+ : detail::make_int_direct<long, Modifiers> {};
 
 #ifdef BOOST_HAS_LONG_LONG
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::long_long, fusion::vector1<A0> >, Modifiers>
- : make_int_direct<boost::long_long_type, Modifiers> {};
+ : detail::make_int_direct<boost::long_long_type, Modifiers> {};
 #endif
 
     template <typename T, unsigned Radix, bool force_sign, typename A0
@@ -411,7 +417,7 @@
     struct make_primitive<
         terminal_ex<tag::int_tag<T, Radix, force_sign>, fusion::vector1<A0> >
           , Modifiers>
- : make_int_direct<T, Modifiers, Radix, force_sign> {};
+ : detail::make_int_direct<T, Modifiers, Radix, force_sign> {};
 
     ///////////////////////////////////////////////////////////////////////////
     namespace detail

Modified: trunk/boost/spirit/home/karma/numeric/real.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/real.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/real.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -47,6 +47,11 @@
     namespace karma
     {
         ///////////////////////////////////////////////////////////////////////
+ // forward declaration only
+ template <typename T>
+ struct real_policies;
+
+ ///////////////////////////////////////////////////////////////////////
         // This one is the class that the user can instantiate directly in
         // order to create a customized real generator
         template <typename T = double, typename Policies = real_policies<T> >
@@ -268,7 +273,7 @@
     {
         // extract policies if this is a real_tag
         template <typename Policies>
- struct get_policies
+ struct get_real_policies
         {
             template <typename Tag>
             static Policies call(Tag) { return Policies(); }
@@ -282,94 +287,101 @@
     ///////////////////////////////////////////////////////////////////////////
     // Generator generators: make_xxx function (objects)
     ///////////////////////////////////////////////////////////////////////////
- template <
- typename T, typename Modifiers, typename Policies = real_policies<T> >
- struct make_real
+ namespace detail
     {
- static bool const lower =
- has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
- static bool const upper =
- has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
-
- typedef any_real_generator<
- T, Policies
- , typename spirit::detail::get_encoding<
- Modifiers, unused_type, lower || upper>::type
- , typename detail::get_casetag<Modifiers, lower || upper>::type
- > result_type;
-
- template <typename Terminal>
- result_type operator()(Terminal const& term, unused_type) const
+ template <typename T, typename Modifiers
+ , typename Policies = real_policies<T> >
+ struct make_real
         {
- using karma::detail::get_policies;
- return result_type(get_policies<Policies>::call(term));
- }
- };
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef any_real_generator<
+ T, Policies
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ > result_type;
+
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ using karma::detail::get_real_policies;
+ return result_type(get_real_policies<Policies>::call(term));
+ }
+ };
+ }
 
     template <typename Modifiers>
     struct make_primitive<tag::float_, Modifiers>
- : make_real<float, Modifiers> {};
+ : detail::make_real<float, Modifiers> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::double_, Modifiers>
- : make_real<double, Modifiers> {};
+ : detail::make_real<double, Modifiers> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::long_double, Modifiers>
- : make_real<long double, Modifiers> {};
+ : detail::make_real<long double, Modifiers> {};
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename T, typename Policy, typename Modifiers>
     struct make_primitive<tag::real_tag<T, Policy>, Modifiers>
- : make_real<T, Modifiers, Policy> {};
+ : detail::make_real<T, Modifiers, Policy> {};
 
     ///////////////////////////////////////////////////////////////////////////
- template <
- typename T, typename Modifiers, typename Policies = real_policies<T> >
- struct make_real_direct
+ namespace detail
     {
- static bool const lower =
- has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
- static bool const upper =
- has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
-
- typedef literal_real_generator<
- T, Policies
- , typename spirit::detail::get_encoding<
- Modifiers, unused_type, lower || upper>::type
- , typename detail::get_casetag<Modifiers, lower || upper>::type
- , false
- > result_type;
-
- template <typename Terminal>
- result_type operator()(Terminal const& term, unused_type) const
+ template <typename T, typename Modifiers
+ , typename Policies = real_policies<T> >
+ struct make_real_direct
         {
- return result_type(T(fusion::at_c<0>(term.args))
- , karma::detail::get_policies<Policies>::call(term.term));
- }
- };
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef literal_real_generator<
+ T, Policies
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ , false
+ > result_type;
+
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ using karma::detail::get_real_policies;
+ return result_type(T(fusion::at_c<0>(term.args))
+ , get_real_policies<Policies>::call(term.term));
+ }
+ };
+ }
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::float_, fusion::vector1<A0> >, Modifiers>
- : make_real_direct<float, Modifiers> {};
+ : detail::make_real_direct<float, Modifiers> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::double_, fusion::vector1<A0> >, Modifiers>
- : make_real_direct<double, Modifiers> {};
+ : detail::make_real_direct<double, Modifiers> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::long_double, fusion::vector1<A0> >, Modifiers>
- : make_real_direct<long double, Modifiers> {};
+ : detail::make_real_direct<long double, Modifiers> {};
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename T, typename Policy, typename A0, typename Modifiers>
     struct make_primitive<
         terminal_ex<tag::real_tag<T, Policy>, fusion::vector1<A0> >
           , Modifiers>
- : make_real_direct<T, Modifiers, Policy> {};
+ : detail::make_real_direct<T, Modifiers, Policy> {};
 
     ///////////////////////////////////////////////////////////////////////////
     namespace detail

Modified: trunk/boost/spirit/home/karma/numeric/real_policies.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/real_policies.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/real_policies.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -47,7 +47,7 @@
     struct real_policies
     {
         ///////////////////////////////////////////////////////////////////////
- // Expose the data type the generator is targeted to
+ // Expose the data type the generator is targeted at
         ///////////////////////////////////////////////////////////////////////
         typedef T value_type;
 

Modified: trunk/boost/spirit/home/karma/numeric/uint.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/uint.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/uint.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -333,129 +333,135 @@
     ///////////////////////////////////////////////////////////////////////////
     // Generator generators: make_xxx function (objects)
     ///////////////////////////////////////////////////////////////////////////
- template <typename T, typename Modifiers, unsigned Radix = 10>
- struct make_uint
+ namespace detail
     {
- static bool const lower =
- has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
- static bool const upper =
- has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
-
- typedef any_uint_generator<
- T
- , typename spirit::detail::get_encoding<
- Modifiers, unused_type, lower || upper>::type
- , typename detail::get_casetag<Modifiers, lower || upper>::type
- , Radix
- > result_type;
-
- result_type operator()(unused_type, unused_type) const
+ template <typename T, typename Modifiers, unsigned Radix = 10>
+ struct make_uint
         {
- return result_type();
- }
- };
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef any_uint_generator<
+ T
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ , Radix
+ > result_type;
+
+ result_type operator()(unused_type, unused_type) const
+ {
+ return result_type();
+ }
+ };
+ }
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename Modifiers>
     struct make_primitive<tag::ushort_, Modifiers>
- : make_uint<unsigned short, Modifiers> {};
+ : detail::make_uint<unsigned short, Modifiers> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::uint_, Modifiers>
- : make_uint<unsigned int, Modifiers> {};
+ : detail::make_uint<unsigned int, Modifiers> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::ulong_, Modifiers>
- : make_uint<unsigned long, Modifiers> {};
+ : detail::make_uint<unsigned long, Modifiers> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::bin, Modifiers>
- : make_uint<unsigned, Modifiers, 2> {};
+ : detail::make_uint<unsigned, Modifiers, 2> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::oct, Modifiers>
- : make_uint<unsigned, Modifiers, 8> {};
+ : detail::make_uint<unsigned, Modifiers, 8> {};
 
     template <typename Modifiers>
     struct make_primitive<tag::hex, Modifiers>
- : make_uint<unsigned, Modifiers, 16> {};
+ : detail::make_uint<unsigned, Modifiers, 16> {};
 
 #ifdef BOOST_HAS_LONG_LONG
     template <typename Modifiers>
     struct make_primitive<tag::ulong_long, Modifiers>
- : make_uint<boost::ulong_long_type, Modifiers> {};
+ : detail::make_uint<boost::ulong_long_type, Modifiers> {};
 #endif
 
     template <typename T, unsigned Radix, typename Modifiers>
     struct make_primitive<tag::uint_tag<T, Radix>, Modifiers>
- : make_uint<T, Modifiers, Radix> {};
+ : detail::make_uint<T, Modifiers, Radix> {};
 
     ///////////////////////////////////////////////////////////////////////////
- template <typename T, typename Modifiers, unsigned Radix = 10>
- struct make_uint_direct
+ namespace detail
     {
- static bool const lower =
- has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
- static bool const upper =
- has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
-
- typedef literal_uint_generator<
- T
- , typename spirit::detail::get_encoding<
- Modifiers, unused_type, lower || upper>::type
- , typename detail::get_casetag<Modifiers, lower || upper>::type
- , Radix, false
- > result_type;
-
- template <typename Terminal>
- result_type operator()(Terminal const& term, unused_type) const
+ template <typename T, typename Modifiers, unsigned Radix = 10>
+ struct make_uint_direct
         {
- return result_type(fusion::at_c<0>(term.args));
- }
- };
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef literal_uint_generator<
+ T
+ , typename spirit::detail::get_encoding<
+ Modifiers, unused_type, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ , Radix, false
+ > result_type;
+
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ return result_type(fusion::at_c<0>(term.args));
+ }
+ };
+ }
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::ushort_, fusion::vector1<A0> >, Modifiers>
- : make_uint_direct<unsigned short, Modifiers> {};
+ : detail::make_uint_direct<unsigned short, Modifiers> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::uint_, fusion::vector1<A0> >, Modifiers>
- : make_uint_direct<unsigned int, Modifiers> {};
+ : detail::make_uint_direct<unsigned int, Modifiers> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::ulong_, fusion::vector1<A0> >, Modifiers>
- : make_uint_direct<unsigned long, Modifiers> {};
+ : detail::make_uint_direct<unsigned long, Modifiers> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::bin, fusion::vector1<A0> >, Modifiers>
- : make_uint_direct<unsigned, Modifiers, 2> {};
+ : detail::make_uint_direct<unsigned, Modifiers, 2> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::oct, fusion::vector1<A0> >, Modifiers>
- : make_uint_direct<unsigned, Modifiers, 8> {};
+ : detail::make_uint_direct<unsigned, Modifiers, 8> {};
 
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::hex, fusion::vector1<A0> >, Modifiers>
- : make_uint_direct<unsigned, Modifiers, 16> {};
+ : detail::make_uint_direct<unsigned, Modifiers, 16> {};
 
 #ifdef BOOST_HAS_LONG_LONG
     template <typename Modifiers, typename A0>
     struct make_primitive<
         terminal_ex<tag::ulong_long, fusion::vector1<A0> >, Modifiers>
- : make_uint_direct<boost::ulong_long_type, Modifiers> {};
+ : detail::make_uint_direct<boost::ulong_long_type, Modifiers> {};
 #endif
 
     template <typename T, unsigned Radix, typename A0, typename Modifiers>
     struct make_primitive<
         terminal_ex<tag::uint_tag<T, Radix>, fusion::vector1<A0> >
           , Modifiers>
- : make_uint_direct<T, Modifiers, Radix> {};
+ : detail::make_uint_direct<T, Modifiers, Radix> {};
 
     namespace detail
     {

Modified: trunk/boost/spirit/home/support/attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes.hpp (original)
+++ trunk/boost/spirit/home/support/attributes.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -405,12 +405,6 @@
         {
             return value; // just pass the one provided
         }
-
- template <typename T>
- static T const& call(T const& value)
- {
- return value; // just pass the one provided
- }
     };
 
     template <typename Attribute, typename ActualAttribute>

Modified: trunk/boost/spirit/home/support/common_terminals.hpp
==============================================================================
--- trunk/boost/spirit/home/support/common_terminals.hpp (original)
+++ trunk/boost/spirit/home/support/common_terminals.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -41,6 +41,7 @@
         ( bin )
         ( oct )
         ( hex )
+ ( bool_ )
         ( ushort_ )
         ( ulong_ )
         ( uint_ )
@@ -78,6 +79,56 @@
         ( token )
         ( attr )
     )
+
+ ///////////////////////////////////////////////////////////////////////////
+ // support for attr_cast
+ namespace tag
+ {
+ template <typename Attribute, typename Expr>
+ struct attr_cast_tag
+ {
+ attr_cast_tag() {}
+ attr_cast_tag(Expr const& expr) : expr_(expr) {}
+
+ Expr expr_;
+ };
+ }
+
+ namespace detail
+ {
+ // extract expression if this is a attr_cast_tag
+ template <typename Expr>
+ struct get_expr
+ {
+ template <typename Tag>
+ static Expr call(Tag) { return Expr(); }
+
+ template <typename Attribute>
+ static Expr const&
+ call(tag::attr_cast_tag<Attribute, Expr> const& t)
+ { return t.expr_; }
+ };
+ }
+
+ // thats the terminal used to identify a attr_cast<>() component
+ template <typename Attribute, typename Expr>
+ struct attr_cast_type
+ : spirit::terminal<tag::attr_cast_tag<Attribute, Expr> >
+ {
+ attr_cast_type() {}
+ attr_cast_type(Expr const& expr)
+ : spirit::terminal<tag::attr_cast_tag<Attribute, Expr> >(expr) {}
+ };
+
+ // This one is the function that the user can call directly in order
+ // to create a customized attr_cast component
+ template <typename Attribute, typename Expr>
+ attr_cast_type<Attribute, Expr>
+ attr_cast(Expr const& expr)
+ {
+ return attr_cast_type<Attribute, Expr>(expr);
+ }
+
 }}
 
 ///////////////////////////////////////////////////////////////////////////////

Added: trunk/boost/spirit/include/karma_bool.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/include/karma_bool.hpp 2009-09-28 16:52:07 EDT (Mon, 28 Sep 2009)
@@ -0,0 +1,18 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 Joel de Guzman
+ Copyright (c) 2001-2009 Hartmut Kaiser
+ http://spirit.sourceforge.net/
+
+ 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_SPIRIT_INCLUDE_KARMA_BOOL
+#define BOOST_SPIRIT_INCLUDE_KARMA_BOOL
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/spirit/home/karma/numeric/bool.hpp>
+
+#endif


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