Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71773 - in sandbox/coerce: boost/coerce boost/coerce/detail libs/coerce/example
From: vexocide_at_[hidden]
Date: 2011-05-06 19:37:59


Author: vexocide
Date: 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
New Revision: 71773
URL: http://svn.boost.org/trac/boost/changeset/71773

Log:
Split up the core implementation into domains
Added:
   sandbox/coerce/boost/coerce/detail/
   sandbox/coerce/boost/coerce/detail/push_back.hpp
      - copied, changed from r71711, /sandbox/coerce/boost/coerce/push_back.hpp
   sandbox/coerce/boost/coerce/detail/reserve.hpp (contents, props changed)
   sandbox/coerce/boost/coerce/domain.hpp (contents, props changed)
   sandbox/coerce/boost/coerce/karma.hpp (contents, props changed)
   sandbox/coerce/boost/coerce/qi.hpp (contents, props changed)
Removed:
   sandbox/coerce/boost/coerce/push_back.hpp
Text files modified:
   sandbox/coerce/boost/coerce/coerce.hpp | 115 ++++-----------------------------------
   sandbox/coerce/boost/coerce/detail/push_back.hpp | 6 +-
   sandbox/coerce/boost/coerce/reserve.hpp | 65 ---------------------
   sandbox/coerce/libs/coerce/example/Jamfile.v2 | 1
   4 files changed, 18 insertions(+), 169 deletions(-)

Modified: sandbox/coerce/boost/coerce/coerce.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/coerce.hpp (original)
+++ sandbox/coerce/boost/coerce/coerce.hpp 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
@@ -11,112 +11,23 @@
 #pragma once
 #endif
 
-#include <boost/coerce/push_back.hpp>
-#include <boost/coerce/reserve.hpp>
-
-#include <boost/mpl/bool.hpp>
-#include <boost/range/begin.hpp>
-#include <boost/range/const_iterator.hpp>
-#include <boost/range/end.hpp>
-#include <boost/range/has_range_iterator.hpp>
-#include <boost/range/size.hpp>
-#include <boost/spirit/home/karma/auto.hpp>
-#include <boost/spirit/home/karma/char.hpp>
-#include <boost/spirit/home/karma/numeric.hpp>
-#include <boost/spirit/home/karma/operator/optional.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/include/version.hpp>
-#include <boost/static_assert.hpp>
+#include <boost/coerce/domain.hpp>
+#include <boost/coerce/karma.hpp>
+#include <boost/coerce/qi.hpp>
 
 #include <typeinfo> // for std::bad_cast
 
-namespace boost { namespace coerce { namespace detail {
-
- template <typename Target, typename Source>
- struct as {
- static inline bool
- call(Target & target, Source const & source) {
- return do_call(
- target,
- source,
- has_range_const_iterator<Source>(),
- typename detail::has_push_back<Target>::type());
- }
-
- private:
- static inline bool
- do_call(
- Target & target,
- Source const & source,
- mpl::true_,
- bool
- ) {
- typename range_difference<Source>::type size =
- boost::size(source);
- call_reserve(target, size);
-
- typedef typename range_const_iterator<Source>::type iterator_type;
- iterator_type begin = boost::const_begin(source),
- iterator = begin;
- iterator_type end = boost::const_end(source);
-
- bool result = spirit::qi::parse(
- iterator, end, target);
-
- if (!result || !((begin <= iterator && iterator < end && *iterator == 0) || iterator == end))
- return false;
-
- return true;
- }
-
- static inline bool
- do_call(
- Target & target,
- Source const & source,
- mpl::false_,
- mpl::true_
- ) {
- call_reserve(
- target,
- traits::reserve_size<Source>::call(source));
-
- bool result = spirit::karma::generate(
- std::back_inserter(target),
-#if SPIRIT_VERSION <= 0x2030
- spirit::karma::auto_,
-#endif
- source);
-
- return result;
- }
-
- static inline bool
- do_call(
- Target & target,
- Source const & source,
- mpl::false_,
- mpl::false_
- ) {
- BOOST_STATIC_ASSERT(sizeof(Target) == 0);
-
- return false;
- }
- };
-
-} } } // namespace boost::coerce::detail
-
-namespace boost { namespace coerce { namespace traits {
+namespace boost { namespace coerce {
 
- template <typename Target, typename Source, typename Enable = void>
- struct as
- : coerce::detail::as<Target, Source> { };
+ namespace detail {
 
-} } } // namespace boost::coerce::traits
+ template <typename Target, typename Source, typename Enable = void>
+ struct as
+ : traits::as<
+ typename traits::domain<Target, Source>::type, Target, Source
+ > { };
 
-namespace boost { namespace coerce {
+ } // namespace detail
 
     class bad_cast
         : public std::bad_cast { };
@@ -126,7 +37,7 @@
     as(Source const & source) {
         Target target;
 
- bool result = traits::as<
+ bool result = detail::as<
                 Target, Source
>::call(target, source);
 
@@ -145,7 +56,7 @@
     ) {
         Target target;
 
- bool result = traits::as<
+ bool result = detail::as<
                 Target, Source
>::call(target, source);
 

Copied: sandbox/coerce/boost/coerce/detail/push_back.hpp (from r71711, /sandbox/coerce/boost/coerce/push_back.hpp)
==============================================================================
--- /sandbox/coerce/boost/coerce/push_back.hpp (original)
+++ sandbox/coerce/boost/coerce/detail/push_back.hpp 2011-05-06 19:37:58 EDT (Fri, 06 May 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_PUSH_BACK_HPP
-#define BOOST_COERCE_PUSH_BACK_HPP
+#ifndef BOOST_COERCE_DETAIL_PUSH_BACK_HPP
+#define BOOST_COERCE_DETAIL_PUSH_BACK_HPP
 
 #ifdef _MSC_VER
 #pragma once
@@ -35,4 +35,4 @@
 
 } } } // namespace boost::coerce::detail
 
-#endif // BOOST_COERCE_PUSH_BACK_HPP
+#endif // BOOST_COERCE_DETAIL_PUSH_BACK_HPP

Added: sandbox/coerce/boost/coerce/detail/reserve.hpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/boost/coerce/detail/reserve.hpp 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
@@ -0,0 +1,81 @@
+// Copyright Adam Merz 2010.
+// Copyright Jeroen Habraken 2010 - 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_RESERVE_HPP
+#define BOOST_COERCE_DETAIL_RESERVE_HPP
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#include <boost/config.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/type_traits/detail/yes_no_type.hpp>
+
+#include <cstddef> // std::size_t
+
+namespace boost { namespace coerce { namespace detail {
+
+ template <typename Sequence>
+ class has_reserve {
+ template <typename U, void (U::*)(typename U::size_type) = &U::reserve>
+ struct impl { };
+
+ template <typename U>
+ static type_traits::yes_type test(U*, impl<U>* = 0);
+
+ template <typename U>
+ static type_traits::no_type test(...);
+
+ public:
+ BOOST_STATIC_CONSTANT(bool, value =
+ sizeof(test<Sequence>(0)) == sizeof(type_traits::yes_type));
+ typedef mpl::bool_<value> type;
+ };
+
+ template <typename Sequence>
+ inline void
+ call_reserve_impl(
+ Sequence & sequence,
+ typename Sequence::size_type const size,
+ mpl::true_ const
+ ) {
+ sequence.reserve(size);
+ }
+
+ template <typename Sequence>
+ inline void
+ call_reserve_impl(
+ Sequence const &,
+ typename Sequence::size_type const,
+ mpl::false_ const
+ ) {
+ // Missing .reserve()
+ }
+
+ template <typename Sequence>
+ inline void
+ call_reserve(
+ Sequence & sequence,
+ typename Sequence::size_type const size
+ ) {
+ call_reserve_impl(
+ sequence, size, typename has_reserve<Sequence>::type());
+ }
+
+ template <typename Sequence>
+ inline void
+ call_reserve(
+ Sequence const &,
+ std::size_t const
+ ) {
+ // Missing size_type
+ }
+
+} } } // namespace boost::coerce::detail
+
+#endif // BOOST_COERCE_DETAIL_RESERVE_HPP

Added: sandbox/coerce/boost/coerce/domain.hpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/boost/coerce/domain.hpp 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
@@ -0,0 +1,51 @@
+// 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_DOMAIN_HPP
+#define BOOST_COERCE_DOMAIN_HPP
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#include <boost/coerce/detail/push_back.hpp>
+
+#include <boost/mpl/bool.hpp>
+#include <boost/range/has_range_iterator.hpp>
+#include <boost/spirit/home/karma/domain.hpp>
+#include <boost/spirit/home/qi/domain.hpp>
+#include <boost/static_assert.hpp>
+
+namespace boost { namespace coerce { namespace traits {
+
+ template <typename U, typename V>
+ struct domain_impl {
+ BOOST_STATIC_ASSERT(sizeof(U) == 0);
+ };
+
+ template <typename U>
+ struct domain_impl<U, mpl::true_> {
+ typedef spirit::qi::domain type;
+ };
+
+ template <>
+ struct domain_impl<mpl::true_, mpl::false_> {
+ typedef spirit::karma::domain type;
+ };
+
+ template <typename Target, typename Source, typename Enable = void>
+ struct domain
+ : domain_impl<
+ typename detail::has_push_back<Target>::type,
+ typename has_range_const_iterator<Source>::type
+ > { };
+
+ template <typename Domain, typename Target, typename Source>
+ struct as;
+
+} } } // namespace boost::coerce::traits
+
+#endif // BOOST_COERCE_DOMAIN_HPP

Added: sandbox/coerce/boost/coerce/karma.hpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/boost/coerce/karma.hpp 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
@@ -0,0 +1,46 @@
+// Copyright Jeroen Habraken 2010 - 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_KARMA_HPP
+#define BOOST_COERCE_KARMA_HPP
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#include <boost/coerce/domain.hpp>
+#include <boost/coerce/reserve.hpp>
+
+#include <boost/spirit/home/karma/auto.hpp>
+#include <boost/spirit/home/karma/char.hpp>
+#include <boost/spirit/home/karma/numeric.hpp>
+#include <boost/spirit/home/karma/operator/optional.hpp>
+#include <boost/spirit/include/version.hpp>
+
+namespace boost { namespace coerce { namespace traits {
+
+ template <typename Target, typename Source>
+ struct as<spirit::karma::domain, Target, Source> {
+ static inline bool
+ call(Target & target, Source const & source) {
+ detail::call_reserve(
+ target,
+ traits::reserve_size<Source>::call(source));
+
+ bool result = spirit::karma::generate(
+ std::back_inserter(target),
+#if SPIRIT_VERSION <= 0x2030
+ spirit::karma::auto_,
+#endif
+ source);
+
+ return result;
+ }
+ };
+
+} } } // namespace boost::coerce::traits
+
+#endif // BOOST_COERCE_KARMA_HPP

Deleted: sandbox/coerce/boost/coerce/push_back.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/push_back.hpp 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
+++ (empty file)
@@ -1,38 +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_PUSH_BACK_HPP
-#define BOOST_COERCE_PUSH_BACK_HPP
-
-#ifdef _MSC_VER
-#pragma once
-#endif
-
-#include <boost/mpl/bool.hpp>
-#include <boost/type_traits/detail/yes_no_type.hpp>
-
-namespace boost { namespace coerce { namespace detail {
-
- template <typename Sequence>
- class has_push_back {
- template <typename U, void (U::*)(typename U::value_type) = &U::push_back>
- struct impl { };
-
- template <typename U>
- static type_traits::yes_type test(U*, impl<U>* = 0);
-
- template <typename U>
- static type_traits::no_type test(...);
-
- public:
- BOOST_STATIC_CONSTANT(bool, value =
- sizeof(test<Sequence>(0)) == sizeof(type_traits::yes_type));
- typedef mpl::bool_<value> type;
- };
-
-} } } // namespace boost::coerce::detail
-
-#endif // BOOST_COERCE_PUSH_BACK_HPP

Added: sandbox/coerce/boost/coerce/qi.hpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/boost/coerce/qi.hpp 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
@@ -0,0 +1,54 @@
+// Copyright Jeroen Habraken 2010 - 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_QI_HPP
+#define BOOST_COERCE_QI_HPP
+
+#ifdef _MSC_VER
+#pragma once
+#endif
+
+#include <boost/coerce/detail/reserve.hpp>
+#include <boost/coerce/domain.hpp>
+
+#include <boost/range/begin.hpp>
+#include <boost/range/const_iterator.hpp>
+#include <boost/range/end.hpp>
+#include <boost/range/has_range_iterator.hpp>
+#include <boost/range/size.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>
+
+namespace boost { namespace coerce { namespace traits {
+
+ template <typename Target, typename Source>
+ struct as<spirit::qi::domain, Target, Source> {
+ static inline bool
+ call(Target & target, Source const & source) {
+ typename range_difference<Source>::type size =
+ boost::size(source);
+ detail::call_reserve(target, size);
+
+ typedef typename range_const_iterator<Source>::type iterator_type;
+ iterator_type begin = boost::const_begin(source),
+ iterator = begin;
+ iterator_type end = boost::const_end(source);
+
+ bool result = spirit::qi::parse(
+ iterator, end, target);
+
+ if (!result || !((begin <= iterator && iterator < end && *iterator == 0) || iterator == end))
+ return false;
+
+ return true;
+ }
+ };
+
+} } } // namespace boost::coerce::traits
+
+#endif // BOOST_COERCE_QI_HPP

Modified: sandbox/coerce/boost/coerce/reserve.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/reserve.hpp (original)
+++ sandbox/coerce/boost/coerce/reserve.hpp 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
@@ -1,4 +1,3 @@
-// Copyright Adam Merz 2010.
 // Copyright Jeroen Habraken 2010 - 2011.
 //
 // Distributed under the Boost Software License, Version 1.0.
@@ -12,11 +11,11 @@
 #pragma once
 #endif
 
+#include <boost/coerce/detail/reserve.hpp>
+
 #include <boost/config.hpp>
 #include <boost/limits.hpp>
-#include <boost/mpl/bool.hpp>
 #include <boost/optional.hpp>
-#include <boost/type_traits/detail/yes_no_type.hpp>
 
 #include <cstddef> // std::size_t
 
@@ -123,64 +122,4 @@
 
 } } } // namespace boost::coerce::traits
 
-namespace boost { namespace coerce { namespace detail {
-
- template <typename Sequence>
- class has_reserve {
- template <typename U, void (U::*)(typename U::size_type) = &U::reserve>
- struct impl { };
-
- template <typename U>
- static type_traits::yes_type test(U*, impl<U>* = 0);
-
- template <typename U>
- static type_traits::no_type test(...);
-
- public:
- BOOST_STATIC_CONSTANT(bool, value =
- sizeof(test<Sequence>(0)) == sizeof(type_traits::yes_type));
- typedef mpl::bool_<value> type;
- };
-
- template <typename Sequence>
- inline void
- call_reserve_impl(
- Sequence & sequence,
- typename Sequence::size_type const size,
- mpl::true_ const
- ) {
- sequence.reserve(size);
- }
-
- template <typename Sequence>
- inline void
- call_reserve_impl(
- Sequence const &,
- typename Sequence::size_type const,
- mpl::false_ const
- ) {
- // Missing .reserve()
- }
-
- template <typename Sequence>
- inline void
- call_reserve(
- Sequence & sequence,
- typename Sequence::size_type const size
- ) {
- call_reserve_impl(
- sequence, size, typename has_reserve<Sequence>::type());
- }
-
- template <typename Sequence>
- inline void
- call_reserve(
- Sequence const &,
- std::size_t const
- ) {
- // Missing size_type
- }
-
-} } } // namespace boost::coerce::detail
-
 #endif // BOOST_COERCE_RESERVE_HPP

Modified: sandbox/coerce/libs/coerce/example/Jamfile.v2
==============================================================================
--- sandbox/coerce/libs/coerce/example/Jamfile.v2 (original)
+++ sandbox/coerce/libs/coerce/example/Jamfile.v2 2011-05-06 19:37:58 EDT (Fri, 06 May 2011)
@@ -8,7 +8,6 @@
     requirements
         <dependency>/boost//headers
         <include>../../../
- <optimization>speed
     ;
 
 exe coerce :


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