Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:46

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 =============================================================================*/
0007 #ifndef BOOST_SPIRIT_QI_OPERATOR_PERMUTATION_HPP
0008 #define BOOST_SPIRIT_QI_OPERATOR_PERMUTATION_HPP
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/spirit/home/qi/meta_compiler.hpp>
0015 #include <boost/spirit/home/qi/detail/permute_function.hpp>
0016 #include <boost/spirit/home/qi/detail/attributes.hpp>
0017 #include <boost/spirit/home/support/algorithm/any_if_ns.hpp>
0018 #include <boost/spirit/home/support/detail/what_function.hpp>
0019 #include <boost/spirit/home/support/has_semantic_action.hpp>
0020 #include <boost/spirit/home/support/handles_container.hpp>
0021 #include <boost/spirit/home/support/info.hpp>
0022 #include <boost/fusion/include/size.hpp>
0023 #include <boost/optional.hpp>
0024 #include <boost/array.hpp>
0025 #include <boost/proto/operators.hpp>
0026 #include <boost/proto/tags.hpp>
0027 
0028 namespace boost { namespace spirit
0029 {
0030     ///////////////////////////////////////////////////////////////////////////
0031     // Enablers
0032     ///////////////////////////////////////////////////////////////////////////
0033     template <>
0034     struct use_operator<qi::domain, proto::tag::bitwise_xor> // enables ^
0035       : mpl::true_ {};
0036 
0037     template <>
0038     struct flatten_tree<qi::domain, proto::tag::bitwise_xor> // flattens ^
0039       : mpl::true_ {};
0040 }}
0041 
0042 namespace boost { namespace spirit { namespace qi
0043 {
0044     template <typename Elements>
0045     struct permutation : nary_parser<permutation<Elements> >
0046     {
0047         template <typename Context, typename Iterator>
0048         struct attribute
0049         {
0050             // Put all the element attributes in a tuple,
0051             // wrapping each element in a boost::optional
0052             typedef typename traits::build_attribute_sequence<
0053                 Elements, Context, traits::permutation_attribute_transform
0054               , Iterator, qi::domain
0055             >::type all_attributes;
0056 
0057             // Now, build a fusion vector over the attributes. Note
0058             // that build_fusion_vector 1) removes all unused attributes
0059             // and 2) may return unused_type if all elements have
0060             // unused_type(s).
0061             typedef typename
0062                 traits::build_fusion_vector<all_attributes>::type
0063             type;
0064         };
0065 
0066         permutation(Elements const& elements_)
0067           : elements(elements_) {}
0068 
0069         template <typename Iterator, typename Context
0070           , typename Skipper, typename Attribute>
0071         bool parse(Iterator& first, Iterator const& last
0072           , Context& context, Skipper const& skipper
0073           , Attribute& attr_) const
0074         {
0075             typedef traits::attribute_not_unused<Context, Iterator> predicate;
0076             detail::permute_function<Iterator, Context, Skipper>
0077                 f(first, last, context, skipper);
0078 
0079             boost::array<bool, fusion::result_of::size<Elements>::value> flags;
0080             flags.fill(false);
0081 
0082             // wrap the attribute in a tuple if it is not a tuple
0083             typename traits::wrap_if_not_tuple<Attribute>::type attr_local(attr_);
0084 
0085             // We have a bool array 'flags' with one flag for each parser.
0086             // permute_function sets the slot to true when the corresponding
0087             // parser successful matches. We loop until there are no more
0088             // successful parsers.
0089 
0090             bool result = false;
0091             f.taken = flags.begin();
0092             while (spirit::any_if_ns(elements, attr_local, f, predicate()))
0093             {
0094                 f.taken = flags.begin();
0095                 result = true;
0096             }
0097             return result;
0098         }
0099 
0100         template <typename Context>
0101         info what(Context& context) const
0102         {
0103             info result("permutation");
0104             fusion::for_each(elements,
0105                 spirit::detail::what_function<Context>(result, context));
0106             return result;
0107         }
0108 
0109         Elements elements;
0110     };
0111 
0112     ///////////////////////////////////////////////////////////////////////////
0113     // Parser generators: make_xxx function (objects)
0114     ///////////////////////////////////////////////////////////////////////////
0115     template <typename Elements, typename Modifiers>
0116     struct make_composite<proto::tag::bitwise_xor, Elements, Modifiers>
0117       : make_nary_composite<Elements, permutation>
0118     {};
0119 }}}
0120 
0121 namespace boost { namespace spirit { namespace traits
0122 {
0123     ///////////////////////////////////////////////////////////////////////////
0124     // We specialize this for permutation (see support/attributes.hpp).
0125     // For permutation, we only wrap the attribute in a tuple IFF
0126     // it is not already a fusion tuple.
0127     template <typename Elements, typename Attribute>
0128     struct pass_attribute<qi::permutation<Elements>, Attribute>
0129       : wrap_if_not_tuple<Attribute> {};
0130 
0131     ///////////////////////////////////////////////////////////////////////////
0132     template <typename Elements>
0133     struct has_semantic_action<qi::permutation<Elements> >
0134       : nary_has_semantic_action<Elements> {};
0135 
0136     ///////////////////////////////////////////////////////////////////////////
0137     template <typename Elements, typename Attribute, typename Context
0138       , typename Iterator>
0139     struct handles_container<qi::permutation<Elements>, Attribute, Context
0140       , Iterator>
0141       : nary_handles_container<Elements, Attribute, Context, Iterator> {};
0142 }}}
0143 
0144 #endif