Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73097 - in sandbox/coerce/boost/coerce: . detail
From: vexocide_at_[hidden]
Date: 2011-07-14 06:43:41


Author: vexocide
Date: 2011-07-14 06:43:40 EDT (Thu, 14 Jul 2011)
New Revision: 73097
URL: http://svn.boost.org/trac/boost/changeset/73097

Log:
Added tags for bases, bin, oct, hex and base<T>
Added:
   sandbox/coerce/boost/coerce/detail/tag.hpp (contents, props changed)
Text files modified:
   sandbox/coerce/boost/coerce/tag.hpp | 60 ++++++++++++++++++++++++++-------------
   1 files changed, 40 insertions(+), 20 deletions(-)

Added: sandbox/coerce/boost/coerce/detail/tag.hpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/boost/coerce/detail/tag.hpp 2011-07-14 06:43:40 EDT (Thu, 14 Jul 2011)
@@ -0,0 +1,46 @@
+// 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

Modified: sandbox/coerce/boost/coerce/tag.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/tag.hpp (original)
+++ sandbox/coerce/boost/coerce/tag.hpp 2011-07-14 06:43:40 EDT (Thu, 14 Jul 2011)
@@ -11,28 +11,26 @@
 #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/coerce/detail/tag.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>
 
 namespace boost { namespace coerce { namespace tag {
 
     struct none { };
 
- struct bin {
+ template <unsigned Radix>
+ struct base {
         template <typename Target>
         struct parser {
- BOOST_STATIC_ASSERT(is_integral<Target>::value);
-
- typedef typename mpl::if_<
- is_signed<Target>,
- spirit::qi::int_parser<Target, 2>,
- spirit::qi::uint_parser<Target, 2>
+ typedef typename detail::integer_parser<
+ Target, Radix
>::type type;
-
+
             static inline type const
             call() {
                 return type();
@@ -41,12 +39,8 @@
 
         template <typename Source>
         struct generator {
- BOOST_STATIC_ASSERT(is_integral<Source>::value);
-
- typedef typename mpl::if_<
- is_signed<Source>,
- spirit::karma::int_generator<Source, 2>,
- spirit::karma::uint_generator<Source, 2>
+ typedef typename detail::integer_generator<
+ Source, Radix
>::type type;
 
             static inline type const
@@ -56,6 +50,32 @@
         };
     };
 
+ struct bin
+ : base<2> { };
+
+ struct oct
+ : 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());
+ }
+ };
+ };
+
 } } } // namespace boost::coerce::tag
 
 #endif // BOOST_COERCE_TAG_HPP


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