Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73304 - in sandbox/coerce/boost/coerce: . detail
From: vexocide_at_[hidden]
Date: 2011-07-22 16:02:21


Author: vexocide
Date: 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
New Revision: 73304
URL: http://svn.boost.org/trac/boost/changeset/73304

Log:
Added support for tag instances
Added:
   sandbox/coerce/boost/coerce/precision.hpp
      - copied, changed from r73024, /sandbox/coerce/boost/coerce/detail/precision.hpp
Removed:
   sandbox/coerce/boost/coerce/detail/precision.hpp
   sandbox/coerce/boost/coerce/detail/tag.hpp
Text files modified:
   sandbox/coerce/boost/coerce/coerce.hpp | 6 +
   sandbox/coerce/boost/coerce/detail/karma.hpp | 64 ++------------------
   sandbox/coerce/boost/coerce/detail/qi.hpp | 21 -----
   sandbox/coerce/boost/coerce/precision.hpp | 10 +-
   sandbox/coerce/boost/coerce/sequence.hpp | 6
   sandbox/coerce/boost/coerce/tag.hpp | 126 +++++++++++++++++++++++++--------------
   6 files changed, 103 insertions(+), 130 deletions(-)

Modified: sandbox/coerce/boost/coerce/coerce.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/coerce.hpp (original)
+++ sandbox/coerce/boost/coerce/coerce.hpp 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
@@ -51,7 +51,8 @@
 
         bool result = traits::as<
                 Target, Source, Tag
- >::BOOST_NESTED_TEMPLATE call<Target, Source, Tag>(target, source);
+ >::BOOST_NESTED_TEMPLATE call<Target, Source, Tag>(
+ target, source, tag);
 
         if (!result) {
             throw_exception(coerce::bad_cast());
@@ -78,7 +79,8 @@
 
         bool result = traits::as<
                 Target, Source, Tag
- >::BOOST_NESTED_TEMPLATE call<Target, Source, Tag>(target, source);
+ >::BOOST_NESTED_TEMPLATE call<Target, Source, Tag>(
+ target, source, tag);
 
         if (!result) {
             return default_value;

Modified: sandbox/coerce/boost/coerce/detail/karma.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/detail/karma.hpp (original)
+++ sandbox/coerce/boost/coerce/detail/karma.hpp 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
@@ -11,80 +11,30 @@
 #pragma once
 #endif
 
-#include <boost/coerce/detail/precision.hpp>
 #include <boost/coerce/reserve.hpp>
 #include <boost/coerce/sequence.hpp>
 #include <boost/coerce/tag.hpp>
 
-#include <boost/config.hpp>
-#include <boost/limits.hpp>
-#include <boost/spirit/home/karma/auto.hpp>
 #include <boost/spirit/home/karma/char.hpp>
+#include <boost/spirit/home/karma/generate.hpp>
 #include <boost/spirit/home/karma/numeric.hpp>
 #include <boost/spirit/home/karma/operator/optional.hpp>
-#include <boost/spirit/include/version.hpp>
-#include <boost/type_traits/remove_const.hpp>
 
 namespace boost { namespace coerce { namespace detail {
 
- template <typename Source, typename Tag>
- struct create_generator {
- typedef typename Tag::BOOST_NESTED_TEMPLATE generator<Source>::type type;
-
- static inline type const
- call() {
- return Tag::BOOST_NESTED_TEMPLATE generator<Source>::call();
- }
- };
-
- template <typename Source>
- struct create_generator<Source, tag::none>
- : spirit::traits::create_generator<Source> { };
-
- template <typename Source>
- struct real_policies
- : spirit::karma::real_policies<Source> {
- static inline unsigned
- precision(Source const &) {
- return detail::precision<Source>::value;
- }
- };
-
- template <typename Source>
- struct create_generator_floating_point {
- typedef spirit::karma::real_generator<
- Source,
- real_policies<typename remove_const<Source>::type>
- > type;
-
- static inline type const
- call() {
- return type();
- }
- };
-
- template <>
- struct create_generator<float, tag::none>
- : create_generator_floating_point<float> { };
-
- template <>
- struct create_generator<double, tag::none>
- : create_generator_floating_point<double> { };
-
- template <>
- struct create_generator<long double, tag::none>
- : create_generator_floating_point<long double> { };
-
     struct karma {
         template <typename Target, typename Source, typename Tag>
         static inline bool
- call(Target & target, Source const & source) {
+ call(Target & target, Source const & source, Tag const & tag) {
             detail::call_reserve(
                 target, traits::reserve_size<Source>::call(source));
 
+ typename traits::sequence<Target>::type iterator =
+ traits::sequence<Target>::back_inserter(target);
+
             bool result = spirit::karma::generate(
- traits::sequence<Target>::back_inserter(target),
- create_generator<Source, Tag>::call(),
+ iterator,
+ typename Tag::template generator<Target, Source>(tag),
                 source);
 
             return result;

Deleted: sandbox/coerce/boost/coerce/detail/precision.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/detail/precision.hpp 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
+++ (empty file)
@@ -1,45 +0,0 @@
-// Copyright Jeroen Habraken 2011.
-//
-// 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_COERCE_DETAIL_PRECISION_HPP
-#define BOOST_COERCE_DETAIL_PRECISION_HPP
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include <boost/config.hpp>
-#include <boost/limits.hpp>
-
-namespace boost { namespace coerce { namespace detail {
-
- template <typename T>
- struct precision {
- typedef std::numeric_limits<T> limits;
-
- BOOST_STATIC_CONSTANT(bool, is_specialized =
- limits::is_specialized && !limits::is_exact);
-
- BOOST_STATIC_CONSTANT(bool, is_specialized_binary =
- is_specialized && limits::radix == 2 && limits::digits > 0);
-
- BOOST_STATIC_CONSTANT(unsigned, precision_binary =
- 2UL + limits::digits * 30103UL / 100000UL);
-
- BOOST_STATIC_CONSTANT(bool, is_specialized_decimal =
- is_specialized && limits::radix == 10 && limits::digits10 > 0);
-
- BOOST_STATIC_CONSTANT(unsigned, precision_decimal =
- limits::digits10 + 1U);
-
- BOOST_STATIC_CONSTANT(unsigned, value =
- is_specialized_binary ? precision_binary
- : is_specialized_decimal ? precision_decimal : 6);
- };
-
-} } } // namespace boost::coerce::detail
-
-#endif // BOOST_COERCE_DETAIL_PRECISION_HPP

Modified: sandbox/coerce/boost/coerce/detail/qi.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/detail/qi.hpp (original)
+++ sandbox/coerce/boost/coerce/detail/qi.hpp 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
@@ -15,32 +15,17 @@
 #include <boost/coerce/string.hpp>
 #include <boost/coerce/tag.hpp>
 
-#include <boost/config.hpp>
-#include <boost/spirit/home/qi/auto.hpp>
 #include <boost/spirit/home/qi/char.hpp>
 #include <boost/spirit/home/qi/numeric.hpp>
 #include <boost/spirit/home/qi/operator/optional.hpp>
+#include <boost/spirit/home/qi/parse.hpp>
 
 namespace boost { namespace coerce { namespace detail {
 
- template <typename Target, typename Tag>
- struct create_parser {
- typedef typename Tag::BOOST_NESTED_TEMPLATE parser<Target>::type type;
-
- static inline type const
- call() {
- return Tag::BOOST_NESTED_TEMPLATE parser<Target>::call();
- }
- };
-
- template <typename Target>
- struct create_parser<Target, tag::none>
- : spirit::traits::create_parser<Target> { };
-
     struct qi {
         template <typename Target, typename Source, typename Tag>
         static inline bool
- call(Target & target, Source const & source) {
+ call(Target & target, Source const & source, Tag const & tag) {
             typedef traits::string<Source> string_traits;
 
             typename string_traits::size_type
@@ -52,7 +37,7 @@
 
             bool result = spirit::qi::parse(
                 iterator, string_traits::end(source),
- create_parser<Target, Tag>::call(),
+ typename Tag::template parser<Target, Source>(tag),
                 target);
 
             if (static_cast<typename string_traits::size_type>(iterator - begin) != length) {

Deleted: sandbox/coerce/boost/coerce/detail/tag.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/detail/tag.hpp 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
+++ (empty file)
@@ -1,46 +0,0 @@
-// Copyright Jeroen Habraken 2011.
-//
-// 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_COERCE_DETAIL_TAG_HPP
-#define BOOST_COERCE_DETAIL_TAG_HPP
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include <boost/mpl/if.hpp>
-#include <boost/spirit/home/karma/numeric.hpp>
-#include <boost/spirit/home/qi/numeric.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/type_traits/is_integral.hpp>
-#include <boost/type_traits/is_signed.hpp>
-#include <boost/static_assert.hpp>
-
-namespace boost { namespace coerce { namespace detail {
-
- template <typename T, unsigned Radix>
- struct integer_parser
- : mpl::if_<
- is_signed<T>,
- spirit::qi::int_parser<T, Radix>,
- spirit::qi::uint_parser<T, Radix>
- > {
- BOOST_STATIC_ASSERT(is_integral<T>::value);
- };
-
- template <typename T, unsigned Radix>
- struct integer_generator
- : mpl::if_<
- is_signed<T>,
- spirit::karma::int_generator<T, Radix>,
- spirit::karma::uint_generator<T, Radix>
- > {
- BOOST_STATIC_ASSERT(is_integral<T>::value);
- };
-
-} } } // namespace boost::coerce::detail
-
-#endif // BOOST_COERCE_DETAIL_TAG_HPP

Copied: sandbox/coerce/boost/coerce/precision.hpp (from r73024, /sandbox/coerce/boost/coerce/detail/precision.hpp)
==============================================================================
--- /sandbox/coerce/boost/coerce/detail/precision.hpp (original)
+++ sandbox/coerce/boost/coerce/precision.hpp 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
@@ -4,8 +4,8 @@
 // (See accompanying file ../../../LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#ifndef BOOST_COERCE_DETAIL_PRECISION_HPP
-#define BOOST_COERCE_DETAIL_PRECISION_HPP
+#ifndef BOOST_COERCE_PRECISION_HPP
+#define BOOST_COERCE_PRECISION_HPP
 
 #ifdef _MSC_VER
 #pragma once
@@ -14,7 +14,7 @@
 #include <boost/config.hpp>
 #include <boost/limits.hpp>
 
-namespace boost { namespace coerce { namespace detail {
+namespace boost { namespace coerce { namespace traits {
 
     template <typename T>
     struct precision {
@@ -40,6 +40,6 @@
                 : is_specialized_decimal ? precision_decimal : 6);
     };
 
-} } } // namespace boost::coerce::detail
+} } } // namespace boost::coerce::traits
 
-#endif // BOOST_COERCE_DETAIL_PRECISION_HPP
+#endif // BOOST_COERCE_PRECISION_HPP

Modified: sandbox/coerce/boost/coerce/sequence.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/sequence.hpp (original)
+++ sandbox/coerce/boost/coerce/sequence.hpp 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
@@ -27,10 +27,10 @@
 
     template <typename T>
     struct sequence_impl_std {
- typedef T type;
+ typedef std::back_insert_iterator<T> type;
 
- static inline std::back_insert_iterator<type>
- back_inserter(type & value) {
+ static inline type
+ back_inserter(T & value) {
             return std::back_inserter(value);
         }
     };

Modified: sandbox/coerce/boost/coerce/tag.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/tag.hpp (original)
+++ sandbox/coerce/boost/coerce/tag.hpp 2011-07-22 16:02:19 EDT (Fri, 22 Jul 2011)
@@ -11,43 +11,96 @@
 #pragma once
 #endif
 
-#include <boost/coerce/detail/tag.hpp>
+#include <boost/coerce/precision.hpp>
 
-#include <boost/proto/deep_copy.hpp>
-#include <boost/spirit/home/qi/directive/no_case.hpp>
-#include <boost/spirit/home/qi/operator/sequence.hpp>
-#include <boost/spirit/home/qi/operator/optional.hpp>
-#include <boost/spirit/home/qi/string/lit.hpp>
+#include <boost/spirit/home/karma/auto.hpp>
+#include <boost/spirit/home/karma/numeric.hpp>
+#include <boost/spirit/home/qi/auto.hpp>
+#include <boost/spirit/home/qi/numeric/int.hpp>
+#include <boost/spirit/home/qi/numeric/uint.hpp>
+#include <boost/type_traits/is_signed.hpp>
+#include <boost/type_traits/remove_const.hpp>
 
 namespace boost { namespace coerce { namespace tag {
 
- struct none { };
+ struct none {
+ template <typename Target, typename Source>
+ struct parser
+ : spirit::traits::create_parser<Target>::type {
+ parser(tag::none const &) { }
+ };
 
- template <unsigned Radix>
- struct base {
- template <typename Target>
- struct parser {
- typedef typename detail::integer_parser<
- Target, Radix
- >::type type;
-
- static inline type const
- call() {
- return type();
- }
+ template <typename Target, typename Source>
+ struct generator
+ : spirit::traits::create_generator<Source>::type {
+ generator(tag::none const &) { }
         };
 
         template <typename Source>
- struct generator {
- typedef typename detail::integer_generator<
- Source, Radix
- >::type type;
-
- static inline type const
- call() {
- return type();
+ struct real_policies
+ : spirit::karma::real_policies<
+ typename remove_const<Source>::type
+ > {
+ static inline unsigned
+ precision(Source const &) {
+ return traits::precision<Source>::value;
             }
         };
+
+ template <typename Target, typename Source>
+ struct generator_floating_point
+ : spirit::karma::real_generator<Source, real_policies<Source> > { };
+
+ template <typename Target>
+ struct generator<Target, float>
+ : generator_floating_point<Target, float> {
+ generator(tag::none const &) { }
+ };
+
+ template <typename Target>
+ struct generator<Target, double>
+ : generator_floating_point<Target, double> {
+ generator(tag::none const &) { }
+ };
+
+ template <typename Target>
+ struct generator<Target, long double>
+ : generator_floating_point<Target, long double> {
+ generator(tag::none const &) { }
+ };
+ };
+
+ template <unsigned Radix>
+ struct base {
+ template <typename Target, typename Source, bool U = is_signed<Target>::value>
+ struct parser;
+
+ template <typename Target, typename Source>
+ struct parser<Target, Source, true>
+ : spirit::qi::int_parser<Target, Radix> {
+ parser(tag::base<Radix> const &) { }
+ };
+
+ template <typename Target, typename Source>
+ struct parser<Target, Source, false>
+ : spirit::qi::uint_parser<Target, Radix> {
+ parser(tag::base<Radix> const &) { }
+ };
+
+ template <typename Target, typename Source, bool U = is_signed<Target>::value>
+ struct generator;
+
+ template <typename Target, typename Source>
+ struct generator<Target, Source, true>
+ : spirit::karma::int_generator<Source, Radix> {
+ generator(tag::base<Radix> const &) { }
+ };
+
+ template <typename Target, typename Source>
+ struct generator<Target, Source, false>
+ : spirit::karma::uint_generator<Source, Radix> {
+ generator(tag::base<Radix> const &) { }
+ };
     };
 
     struct bin
@@ -57,24 +110,7 @@
         : base<8> { };
 
     struct hex
- : base<16> {
- template <typename Target>
- struct parser {
- typedef typename detail::integer_parser<
- Target, 16
- >::type parser_type;
-
- typedef typename proto::result_of::deep_copy<
- BOOST_TYPEOF_TPL((-spirit::standard::no_case_type()["0x"] >> parser_type()))
- >::type type;
-
- static inline type const
- call() {
- return proto::deep_copy(
- -spirit::standard::no_case_type()["0x"] >> parser_type());
- }
- };
- };
+ : base<16> { };
 
 } } } // namespace boost::coerce::tag
 


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