Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71234 - in trunk/boost/spirit/home: qi/numeric qi/numeric/detail support
From: joel_at_[hidden]
Date: 2011-04-13 20:34:23


Author: djowel
Date: 2011-04-13 20:34:22 EDT (Wed, 13 Apr 2011)
New Revision: 71234
URL: http://svn.boost.org/trac/boost/changeset/71234

Log:
Arbitrary radix feature for uints
Text files modified:
   trunk/boost/spirit/home/qi/numeric/detail/numeric_utils.hpp | 29 ++++++++++++++++++++++++++++-
   trunk/boost/spirit/home/qi/numeric/numeric_utils.hpp | 2 +-
   trunk/boost/spirit/home/qi/numeric/uint.hpp | 2 +-
   trunk/boost/spirit/home/support/container.hpp | 36 ++++++++++++++++++------------------
   4 files changed, 48 insertions(+), 21 deletions(-)

Modified: trunk/boost/spirit/home/qi/numeric/detail/numeric_utils.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/numeric/detail/numeric_utils.hpp (original)
+++ trunk/boost/spirit/home/qi/numeric/detail/numeric_utils.hpp 2011-04-13 20:34:22 EDT (Wed, 13 Apr 2011)
@@ -155,6 +155,32 @@
         };
     };
 
+ // arbitrary Radix
+ template <unsigned Radix>
+ struct radix_traits
+ {
+ template<typename Char>
+ inline static bool is_valid(Char ch)
+ {
+ return (ch >= '0' && ch <= ('0' + Radix - 1));
+ }
+
+ template<typename Char>
+ inline static unsigned digit(Char ch)
+ {
+ return ch - '0';
+ }
+
+ template<typename T>
+ struct digits
+ {
+ typedef std::numeric_limits<T> numeric_limits_;
+ BOOST_STATIC_CONSTANT(int, value = numeric_limits_::digits10);
+ // TODO(j.f.eick_at_[hidden]): this is the min number of digits which
+ // can be safely parsed if the radix is < 10 - this is not optimal?
+ };
+ };
+
     ///////////////////////////////////////////////////////////////////////////
     // positive_accumulator/negative_accumulator: Accumulator policies for
     // extracting integers. Use positive_accumulator if number is positive.
@@ -175,7 +201,8 @@
         {
             // Ensure n *= Radix will not overflow
             static T const max = (std::numeric_limits<T>::max)();
- static T const val = (max - 1) / Radix;
+ //static T const val = (max - 1) / Radix;
+ static T const val = max / Radix;
             if (n > val)
                 return false;
 

Modified: trunk/boost/spirit/home/qi/numeric/numeric_utils.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/numeric/numeric_utils.hpp (original)
+++ trunk/boost/spirit/home/qi/numeric/numeric_utils.hpp 2011-04-13 20:34:22 EDT (Wed, 13 Apr 2011)
@@ -48,7 +48,7 @@
     {
         // check template parameter 'Radix' for validity
         BOOST_SPIRIT_ASSERT_MSG(
- Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16,
+ Radix >= 2 || Radix <= 10 || Radix == 16,
             not_supported_radix, ());
 
         template <typename Iterator>

Modified: trunk/boost/spirit/home/qi/numeric/uint.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/numeric/uint.hpp (original)
+++ trunk/boost/spirit/home/qi/numeric/uint.hpp 2011-04-13 20:34:22 EDT (Wed, 13 Apr 2011)
@@ -221,7 +221,7 @@
     {
         // check template parameter 'Radix' for validity
         BOOST_SPIRIT_ASSERT_MSG(
- Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16,
+ Radix >= 2 || Radix <= 10 || Radix == 16,
             not_supported_radix, ());
 
         template <typename Context, typename Iterator>

Modified: trunk/boost/spirit/home/support/container.hpp
==============================================================================
--- trunk/boost/spirit/home/support/container.hpp (original)
+++ trunk/boost/spirit/home/support/container.hpp 2011-04-13 20:34:22 EDT (Wed, 13 Apr 2011)
@@ -41,7 +41,7 @@
     }
 
     template <typename T, typename Enable/* = void*/>
- struct is_container
+ struct is_container
       : mpl::bool_<
             detail::has_value_type<T>::value &&
             detail::has_iterator<T>::value &&
@@ -50,13 +50,13 @@
     {};
 
     template <typename T>
- struct is_container<T&>
- : is_container<T>
+ struct is_container<T&>
+ : is_container<T>
     {};
 
     template <typename T>
- struct is_container<boost::optional<T> >
- : is_container<T>
+ struct is_container<boost::optional<T> >
+ : is_container<T>
     {};
 
 #define BOOST_SPIRIT_IS_CONTAINER(z, N, data) \
@@ -70,9 +70,9 @@
     {};
 
     template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
- struct is_container<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+ struct is_container<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
        : mpl::bool_<BOOST_PP_REPEAT(BOOST_VARIANT_LIMIT_TYPES
- , BOOST_SPIRIT_IS_CONTAINER, _) false>
+ , BOOST_SPIRIT_IS_CONTAINER, _) false>
     {};
 
 #undef BOOST_SPIRIT_IS_CONTAINER
@@ -97,7 +97,7 @@
         };
 
         template <typename T>
- struct remove_value_const<T const>
+ struct remove_value_const<T const>
           : remove_value_const<T>
         {};
 
@@ -119,25 +119,25 @@
     //]
 
     template <typename T>
- struct container_value<T&>
- : container_value<T>
+ struct container_value<T&>
+ : container_value<T>
     {};
 
     // this will be instantiated if the optional holds a container
     template <typename T>
- struct container_value<boost::optional<T> >
- : container_value<T>
+ struct container_value<boost::optional<T> >
+ : container_value<T>
     {};
 
     // this will be instantiated if the variant holds a container
     template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
     struct container_value<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
     {
- typedef typename
- variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types
+ typedef typename
+ variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types
         types;
- typedef typename
- mpl::find_if<types, is_container<mpl::_1> >::type
+ typedef typename
+ mpl::find_if<types, is_container<mpl::_1> >::type
         iter;
 
         typedef typename container_value<
@@ -393,7 +393,7 @@
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename Container, typename Enable/* = void*/>
- struct begin_container
+ struct begin_container
     {
         static typename container_iterator<Container>::type call(Container& c)
         {
@@ -540,7 +540,7 @@
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename Container>
- struct begin
+ struct begin
       : traits::container_iterator<Container>
     {};
 


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