Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:09:14

0001 //  Copyright (c) 2001-2011 Joel de Guzman
0002 //  Copyright (c) 2001-2011 Hartmut Kaiser
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 #if !defined(BOOST_SPIRIT_GENERATOR_BINDER_APR_17_2009_0952PM)
0008 #define BOOST_SPIRIT_GENERATOR_BINDER_APR_17_2009_0952PM
0009 
0010 #if defined(_MSC_VER)
0011 #pragma once
0012 #endif
0013 
0014 #include <boost/fusion/include/at.hpp>
0015 #include <boost/mpl/bool.hpp>
0016 #include <boost/spirit/home/support/has_semantic_action.hpp>
0017 
0018 namespace boost { namespace spirit { namespace karma { namespace detail
0019 {
0020     // generator_binder for plain rules
0021     template <typename Generator, typename Auto>
0022     struct generator_binder
0023     {
0024         generator_binder(Generator const& g)
0025           : g(g) {}
0026 
0027         template <typename OutputIterator, typename Delimiter, typename Context>
0028         bool call(OutputIterator& sink, Context& context
0029           , Delimiter const& delim, mpl::true_) const
0030         {
0031             // If DeducedAuto is false (semantic actions is present), the 
0032             // component's attribute is unused.
0033             return g.generate(sink, context, delim, unused);
0034         }
0035 
0036         template <typename OutputIterator, typename Delimiter, typename Context>
0037         bool call(OutputIterator& sink, Context& context
0038           , Delimiter const& delim, mpl::false_) const
0039         {
0040             // If DeducedAuto is true (no semantic action), we pass the rule's 
0041             // attribute on to the component.
0042             return g.generate(sink, context, delim
0043                 , fusion::at_c<0>(context.attributes));
0044         }
0045 
0046         template <typename OutputIterator, typename Delimiter, typename Context>
0047         bool operator()(OutputIterator& sink, Context& context
0048           , Delimiter const& delim) const
0049         {
0050             // If Auto is false, we need to deduce whether to apply auto rule
0051             typedef typename traits::has_semantic_action<Generator>::type auto_rule;
0052             return call(sink, context, delim, auto_rule());
0053         }
0054 
0055         Generator g;
0056     };
0057 
0058     // generator_binder for auto rules
0059     template <typename Generator>
0060     struct generator_binder<Generator, mpl::true_>
0061     {
0062         generator_binder(Generator const& g)
0063           : g(g) {}
0064 
0065         template <typename OutputIterator, typename Delimiter, typename Context>
0066         bool operator()(OutputIterator& sink, Context& context
0067           , Delimiter const& delim) const
0068         {
0069             // If Auto is true, the component's attribute is unused.
0070             return g.generate(sink, context, delim
0071                 , fusion::at_c<0>(context.attributes));
0072         }
0073 
0074         Generator g;
0075     };
0076 
0077     template <typename Auto, typename Generator>
0078     inline generator_binder<Generator, Auto>
0079     bind_generator(Generator const& g)
0080     {
0081         return generator_binder<Generator, Auto>(g);
0082     }
0083 
0084 }}}}
0085 
0086 #endif