/*============================================================================= Copyright (c) 2001-2010 Joel de Guzman 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(SPIRIT_UINT_APR_17_2006_0901AM) #define SPIRIT_UINT_APR_17_2006_0901AM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #include namespace boost { namespace spirit { /////////////////////////////////////////////////////////////////////////// // Enablers /////////////////////////////////////////////////////////////////////////// template <> struct use_terminal // enables bin : mpl::true_ {}; template <> struct use_terminal // enables oct : mpl::true_ {}; template <> struct use_terminal // enables hex : mpl::true_ {}; template <> struct use_terminal // enables ushort_ : mpl::true_ {}; template <> struct use_terminal // enables ulong_ : mpl::true_ {}; template <> struct use_terminal // enables uint_ : mpl::true_ {}; #ifdef BOOST_HAS_LONG_LONG template <> struct use_terminal // enables ulong_long : mpl::true_ {}; #endif }} namespace boost { namespace spirit { namespace qi { using spirit::bin; using spirit::bin_type; using spirit::oct; using spirit::oct_type; using spirit::hex; using spirit::hex_type; using spirit::ushort_; using spirit::ushort__type; using spirit::ulong_; using spirit::ulong__type; using spirit::uint_; using spirit::uint__type; #ifdef BOOST_HAS_LONG_LONG using spirit::ulong_long; using spirit::ulong_long_type; #endif /////////////////////////////////////////////////////////////////////////// // This actual unsigned int parser /////////////////////////////////////////////////////////////////////////// template < typename T , unsigned Radix = 10 , unsigned MinDigits = 1 , int MaxDigits = -1> struct uint_parser_impl : primitive_parser > { // check template parameter 'Radix' for validity BOOST_SPIRIT_ASSERT_MSG( Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16, not_supported_radix, ()); template struct attribute { typedef T type; }; template bool parse(Iterator& first, Iterator const& last , Context& /*context*/, Skipper const& skipper , Attribute& attr) const { qi::skip_over(first, last, skipper); return extract_uint ::call(first, last, attr); } template info what(Context& /*context*/) const { return info("unsigned-integer"); } }; /////////////////////////////////////////////////////////////////////////// // uint_parser is the class that the user can instantiate directly /////////////////////////////////////////////////////////////////////////// template < typename T , unsigned Radix = 10 , unsigned MinDigits = 1 , int MaxDigits = -1> struct uint_parser : proto::terminal >::type { }; /////////////////////////////////////////////////////////////////////////// // Parser generators: make_xxx function (objects) /////////////////////////////////////////////////////////////////////////// template < typename T , unsigned Radix = 10 , unsigned MinDigits = 1 , int MaxDigits = -1> struct make_uint { typedef uint_parser_impl result_type; result_type operator()(unused_type, unused_type) const { return result_type(); } }; template struct make_primitive : make_uint {}; template struct make_primitive : make_uint {}; template struct make_primitive : make_uint {}; template struct make_primitive : make_uint {}; template struct make_primitive : make_uint {}; template struct make_primitive : make_uint {}; #ifdef BOOST_HAS_LONG_LONG template struct make_primitive : make_uint {}; #endif }}} #endif