Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*=============================================================================
0002     Copyright (c) 2009  Hartmut Kaiser
0003     Copyright (c) 2014  Joel de Guzman
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 #ifndef BOOST_SPIRIT_X3_NUMERIC_BOOL_HPP
0009 #define BOOST_SPIRIT_X3_NUMERIC_BOOL_HPP
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/numeric/bool_policies.hpp>
0014 
0015 namespace boost { namespace spirit { namespace x3
0016 {
0017     template <typename T, typename Encoding, typename BoolPolicies = bool_policies<T>>
0018     struct bool_parser : parser<bool_parser<T, Encoding, BoolPolicies>>
0019     {
0020         typedef Encoding encoding;
0021         typedef T attribute_type;
0022         static bool const has_attribute = true;
0023 
0024         constexpr bool_parser()
0025             : policies() {}
0026 
0027         constexpr bool_parser(BoolPolicies const& policies)
0028             : policies(policies) {}
0029 
0030         template <typename Iterator, typename Context>
0031         bool parse(Iterator& first, Iterator const& last
0032           , Context const& context, unused_type, T& attr) const
0033         {
0034             x3::skip_over(first, last, context);
0035             return policies.parse_true(first, last, attr, get_case_compare<encoding>(context))
0036                 || policies.parse_false(first, last, attr, get_case_compare<encoding>(context));
0037         }
0038 
0039         template <typename Iterator, typename Context, typename Attribute>
0040         bool parse(Iterator& first, Iterator const& last
0041           , Context const& context, unused_type, Attribute& attr_param) const
0042         {
0043             // this case is called when Attribute is not T
0044             T attr_;
0045             if (parse(first, last, context, unused, attr_))
0046             {
0047                 traits::move_to(attr_, attr_param);
0048                 return true;
0049             }
0050             return false;
0051         }
0052 
0053         BoolPolicies policies;
0054     };
0055 
0056     template <typename T, typename Encoding, typename BoolPolicies = bool_policies<T>>
0057     struct literal_bool_parser : parser<bool_parser<T, Encoding, BoolPolicies>>
0058     {
0059         typedef Encoding encoding;
0060         typedef T attribute_type;
0061         static bool const has_attribute = true;
0062 
0063         template <typename Value>
0064         constexpr literal_bool_parser(Value const& n)
0065             : policies(), n_(n) {}
0066 
0067         template <typename Value>
0068         constexpr literal_bool_parser(Value const& n, BoolPolicies const& policies)
0069             : policies(policies), n_(n) {}
0070 
0071         template <typename Iterator, typename Context>
0072         bool parse_main(Iterator& first, Iterator const& last
0073           , Context const& context, T& attr) const
0074         {
0075             x3::skip_over(first, last, context);
0076             return (n_ && policies.parse_true(first, last, attr, get_case_compare<encoding>(context)))
0077                 || (!n_ && policies.parse_false(first, last, attr, get_case_compare<encoding>(context)));
0078         }
0079 
0080         template <typename Iterator, typename Context>
0081         bool parse(Iterator& first, Iterator const& last
0082           , Context const& context, unused_type, T& attr) const
0083         {
0084             return parse_main(first, last, context, attr);
0085         }
0086 
0087         template <typename Iterator, typename Context, typename Attribute>
0088         bool parse(Iterator& first, Iterator const& last
0089           , Context const& context, unused_type, Attribute& attr_param) const
0090         {
0091             // this case is called when Attribute is not T
0092             T attr_;
0093             if (parse_main(first, last, context, attr_))
0094             {
0095                 traits::move_to(attr_, attr_param);
0096                 return true;
0097             }
0098             return false;
0099         }
0100 
0101         BoolPolicies policies;
0102         T n_;
0103     };
0104 
0105     namespace standard
0106     {
0107         typedef bool_parser<bool, char_encoding::standard> bool_type;
0108         constexpr bool_type bool_ = {};
0109 
0110         typedef literal_bool_parser<bool, char_encoding::standard> true_type;
0111         constexpr true_type true_ = { true };
0112 
0113         typedef literal_bool_parser<bool, char_encoding::standard> false_type;
0114         constexpr false_type false_ = { false };
0115     }
0116 
0117 #ifndef BOOST_SPIRIT_NO_STANDARD_WIDE
0118     namespace standard_wide
0119     {
0120         typedef bool_parser<bool, char_encoding::standard_wide> bool_type;
0121         constexpr bool_type bool_ = {};
0122 
0123         typedef literal_bool_parser<bool, char_encoding::standard_wide> true_type;
0124         constexpr true_type true_ = { true };
0125 
0126         typedef literal_bool_parser<bool, char_encoding::standard_wide> false_type;
0127         constexpr false_type false_ = { false };
0128     }
0129 #endif
0130 
0131     namespace ascii
0132     {
0133         typedef bool_parser<bool, char_encoding::ascii> bool_type;
0134         constexpr bool_type bool_ = {};
0135 
0136         typedef literal_bool_parser<bool, char_encoding::ascii> true_type;
0137         constexpr true_type true_ = { true };
0138 
0139         typedef literal_bool_parser<bool, char_encoding::ascii> false_type;
0140         constexpr false_type false_ = { false };
0141     }
0142 
0143     namespace iso8859_1
0144     {
0145         typedef bool_parser<bool, char_encoding::iso8859_1> bool_type;
0146         constexpr bool_type bool_ = {};
0147 
0148         typedef literal_bool_parser<bool, char_encoding::iso8859_1> true_type;
0149         constexpr true_type true_ = { true };
0150 
0151         typedef literal_bool_parser<bool, char_encoding::iso8859_1> false_type;
0152         constexpr false_type false_ = { false };
0153     }
0154 
0155     using standard::bool_;
0156     using standard::true_;
0157     using standard::false_;
0158 
0159     }}}
0160 
0161 #endif