Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:02:36

0001 /*=============================================================================
0002     Copyright (c) 2001-2014 Joel de Guzman
0003     Copyright (c) 2011 Jan Frederick Eick
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 ==============================================================================*/
0008 #if !defined(BOOST_SPIRIT_X3_UINT_APR_17_2006_0901AM)
0009 #define BOOST_SPIRIT_X3_UINT_APR_17_2006_0901AM
0010 
0011 #include <boost/spirit/home/x3/core/parser.hpp>
0012 #include <boost/spirit/home/x3/core/skip_over.hpp>
0013 #include <boost/spirit/home/x3/support/numeric_utils/extract_int.hpp>
0014 #include <cstdint>
0015 
0016 namespace boost { namespace spirit { namespace x3
0017 {
0018     ///////////////////////////////////////////////////////////////////////////
0019     template <
0020         typename T
0021       , unsigned Radix = 10
0022       , unsigned MinDigits = 1
0023       , int MaxDigits = -1>
0024     struct uint_parser : parser<uint_parser<T, Radix, MinDigits, MaxDigits>>
0025     {
0026         // check template parameter 'Radix' for validity
0027         static_assert(
0028             (Radix >= 2 && Radix <= 36),
0029             "Error Unsupported Radix");
0030 
0031         typedef T attribute_type;
0032         static bool const has_attribute = true;
0033 
0034         template <typename Iterator, typename Context, typename Attribute>
0035         bool parse(Iterator& first, Iterator const& last
0036           , Context const& context, unused_type, Attribute& attr) const
0037         {
0038             typedef extract_uint<T, Radix, MinDigits, MaxDigits> extract;
0039             x3::skip_over(first, last, context);
0040             return extract::call(first, last, attr);
0041         }
0042     };
0043 
0044 #define BOOST_SPIRIT_X3_UINT_PARSER(uint_type, name)                            \
0045     typedef uint_parser<uint_type> name##type;                                  \
0046     constexpr name##type name = {};                                             \
0047     /***/
0048 
0049     BOOST_SPIRIT_X3_UINT_PARSER(unsigned long, ulong_)
0050     BOOST_SPIRIT_X3_UINT_PARSER(unsigned short, ushort_)
0051     BOOST_SPIRIT_X3_UINT_PARSER(unsigned int, uint_)
0052     BOOST_SPIRIT_X3_UINT_PARSER(unsigned long long, ulong_long)
0053 
0054     BOOST_SPIRIT_X3_UINT_PARSER(uint8_t, uint8)
0055     BOOST_SPIRIT_X3_UINT_PARSER(uint16_t, uint16)
0056     BOOST_SPIRIT_X3_UINT_PARSER(uint32_t, uint32)
0057     BOOST_SPIRIT_X3_UINT_PARSER(uint64_t, uint64)
0058 
0059 #undef BOOST_SPIRIT_X3_UINT_PARSER
0060 
0061 #define BOOST_SPIRIT_X3_UINT_PARSER(uint_type, radix, name)                     \
0062     typedef uint_parser<uint_type, radix> name##type;                           \
0063     constexpr name##type name = name##type();                                   \
0064     /***/
0065 
0066     BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 2, bin)
0067     BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 8, oct)
0068     BOOST_SPIRIT_X3_UINT_PARSER(unsigned, 16, hex)
0069 
0070 #undef BOOST_SPIRIT_X3_UINT_PARSER
0071 
0072 
0073 }}}
0074 
0075 #endif