Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 //
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_SPIRIT_KARMA_AUXILIARY_ATTR_CAST_HPP
0007 #define BOOST_SPIRIT_KARMA_AUXILIARY_ATTR_CAST_HPP
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/spirit/home/karma/meta_compiler.hpp>
0014 #include <boost/spirit/home/karma/generator.hpp>
0015 #include <boost/spirit/home/karma/domain.hpp>
0016 #include <boost/spirit/home/support/unused.hpp>
0017 #include <boost/spirit/home/support/info.hpp>
0018 #include <boost/spirit/home/support/common_terminals.hpp>
0019 #include <boost/spirit/home/karma/detail/attributes.hpp>
0020 #include <boost/spirit/home/support/auxiliary/attr_cast.hpp>
0021 
0022 namespace boost { namespace spirit
0023 {
0024     ///////////////////////////////////////////////////////////////////////////
0025     // enables attr_cast<>() pseudo generator
0026     template <typename Expr, typename Exposed, typename Transformed>
0027     struct use_terminal<karma::domain
0028           , tag::stateful_tag<Expr, tag::attr_cast, Exposed, Transformed> >
0029       : mpl::true_ {};
0030 }}
0031 
0032 namespace boost { namespace spirit { namespace karma
0033 {
0034     using spirit::attr_cast;
0035 
0036     ///////////////////////////////////////////////////////////////////////////
0037     // attr_cast_generator consumes the attribute of subject generator without
0038     // generating anything
0039     ///////////////////////////////////////////////////////////////////////////
0040     template <typename Exposed, typename Transformed, typename Subject>
0041     struct attr_cast_generator
0042       : unary_generator<attr_cast_generator<Exposed, Transformed, Subject> >
0043     {
0044         typedef typename result_of::compile<karma::domain, Subject>::type
0045             subject_type;
0046 
0047         typedef mpl::int_<subject_type::properties::value> properties;
0048 
0049         typedef typename mpl::eval_if<
0050             traits::not_is_unused<Transformed>
0051           , mpl::identity<Transformed>
0052           , traits::attribute_of<subject_type> >::type 
0053         transformed_attribute_type;
0054 
0055         attr_cast_generator(Subject const& subject)
0056           : subject(subject) 
0057         {
0058             // If you got an error_invalid_expression error message here,
0059             // then the expression (Subject) is not a valid spirit karma
0060             // expression.
0061             BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Subject);
0062         }
0063 
0064         // If Exposed is given, we use the given type, otherwise all we can do
0065         // is to guess, so we expose our inner type as an attribute and
0066         // deal with the passed attribute inside the parse function.
0067         template <typename Context, typename Unused>
0068         struct attribute
0069           : mpl::if_<traits::not_is_unused<Exposed>, Exposed
0070               , transformed_attribute_type>
0071         {};
0072 
0073         template <typename OutputIterator, typename Context, typename Delimiter
0074           , typename Attribute>
0075         bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
0076           , Attribute const& attr) const
0077         {
0078             typedef traits::transform_attribute<
0079                 Attribute const, transformed_attribute_type, domain> 
0080             transform;
0081 
0082             return compile<karma::domain>(subject).generate(
0083                 sink, ctx, d, transform::pre(attr));
0084         }
0085 
0086         template <typename Context>
0087         info what(Context& context) const
0088         {
0089             return info("attr_cast"
0090               , compile<karma::domain>(subject).what(context));
0091         }
0092 
0093         Subject subject;
0094     };
0095 
0096     ///////////////////////////////////////////////////////////////////////////
0097     // Generator generator: make_xxx function (objects)
0098     ///////////////////////////////////////////////////////////////////////////
0099     template <typename Expr, typename Exposed, typename Transformed
0100       , typename Modifiers>
0101     struct make_primitive<
0102         tag::stateful_tag<Expr, tag::attr_cast, Exposed, Transformed>, Modifiers>
0103     {
0104         typedef attr_cast_generator<Exposed, Transformed, Expr> result_type;
0105 
0106         template <typename Terminal>
0107         result_type operator()(Terminal const& term, unused_type) const
0108         {
0109             typedef tag::stateful_tag<
0110                 Expr, tag::attr_cast, Exposed, Transformed> tag_type;
0111             using spirit::detail::get_stateful_data;
0112             return result_type(get_stateful_data<tag_type>::call(term));
0113         }
0114     };
0115 
0116 }}}
0117 
0118 #endif