annotate DEPENDENCIES/generic/include/boost/spirit/home/karma/auxiliary/attr_cast.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (c) 2001-2011 Hartmut Kaiser
Chris@16 2 //
Chris@16 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5
Chris@16 6 #if !defined(SPIRIT_KARMA_ATTR_CAST_SEP_26_2009_0348PM)
Chris@16 7 #define SPIRIT_KARMA_ATTR_CAST_SEP_26_2009_0348PM
Chris@16 8
Chris@16 9 #if defined(_MSC_VER)
Chris@16 10 #pragma once
Chris@16 11 #endif
Chris@16 12
Chris@16 13 #include <boost/spirit/home/karma/meta_compiler.hpp>
Chris@16 14 #include <boost/spirit/home/karma/generator.hpp>
Chris@16 15 #include <boost/spirit/home/karma/domain.hpp>
Chris@16 16 #include <boost/spirit/home/support/unused.hpp>
Chris@16 17 #include <boost/spirit/home/support/info.hpp>
Chris@16 18 #include <boost/spirit/home/support/common_terminals.hpp>
Chris@16 19 #include <boost/spirit/home/karma/detail/attributes.hpp>
Chris@16 20 #include <boost/spirit/home/support/auxiliary/attr_cast.hpp>
Chris@16 21
Chris@16 22 namespace boost { namespace spirit
Chris@16 23 {
Chris@16 24 ///////////////////////////////////////////////////////////////////////////
Chris@16 25 // enables attr_cast<>() pseudo generator
Chris@16 26 template <typename Expr, typename Exposed, typename Transformed>
Chris@16 27 struct use_terminal<karma::domain
Chris@16 28 , tag::stateful_tag<Expr, tag::attr_cast, Exposed, Transformed> >
Chris@16 29 : mpl::true_ {};
Chris@16 30 }}
Chris@16 31
Chris@16 32 namespace boost { namespace spirit { namespace karma
Chris@16 33 {
Chris@16 34 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
Chris@16 35 using spirit::attr_cast;
Chris@16 36 #endif
Chris@16 37
Chris@16 38 ///////////////////////////////////////////////////////////////////////////
Chris@16 39 // attr_cast_generator consumes the attribute of subject generator without
Chris@16 40 // generating anything
Chris@16 41 ///////////////////////////////////////////////////////////////////////////
Chris@16 42 template <typename Exposed, typename Transformed, typename Subject>
Chris@16 43 struct attr_cast_generator
Chris@16 44 : unary_generator<attr_cast_generator<Exposed, Transformed, Subject> >
Chris@16 45 {
Chris@16 46 typedef typename result_of::compile<karma::domain, Subject>::type
Chris@16 47 subject_type;
Chris@16 48
Chris@16 49 typedef mpl::int_<subject_type::properties::value> properties;
Chris@16 50
Chris@16 51 typedef typename mpl::eval_if<
Chris@16 52 traits::not_is_unused<Transformed>
Chris@16 53 , mpl::identity<Transformed>
Chris@16 54 , traits::attribute_of<subject_type> >::type
Chris@16 55 transformed_attribute_type;
Chris@16 56
Chris@16 57 attr_cast_generator(Subject const& subject)
Chris@16 58 : subject(subject)
Chris@16 59 {
Chris@16 60 // If you got an error_invalid_expression error message here,
Chris@16 61 // then the expression (Subject) is not a valid spirit karma
Chris@16 62 // expression.
Chris@16 63 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Subject);
Chris@16 64 }
Chris@16 65
Chris@16 66 // If Exposed is given, we use the given type, otherwise all we can do
Chris@16 67 // is to guess, so we expose our inner type as an attribute and
Chris@16 68 // deal with the passed attribute inside the parse function.
Chris@16 69 template <typename Context, typename Unused>
Chris@16 70 struct attribute
Chris@16 71 : mpl::if_<traits::not_is_unused<Exposed>, Exposed
Chris@16 72 , transformed_attribute_type>
Chris@16 73 {};
Chris@16 74
Chris@16 75 template <typename OutputIterator, typename Context, typename Delimiter
Chris@16 76 , typename Attribute>
Chris@16 77 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
Chris@16 78 , Attribute const& attr) const
Chris@16 79 {
Chris@16 80 typedef traits::transform_attribute<
Chris@16 81 Attribute const, transformed_attribute_type, domain>
Chris@16 82 transform;
Chris@16 83
Chris@16 84 return compile<karma::domain>(subject).generate(
Chris@16 85 sink, ctx, d, transform::pre(attr));
Chris@16 86 }
Chris@16 87
Chris@16 88 template <typename Context>
Chris@16 89 info what(Context& context) const
Chris@16 90 {
Chris@16 91 return info("attr_cast"
Chris@16 92 , compile<karma::domain>(subject).what(context));
Chris@16 93 }
Chris@16 94
Chris@16 95 Subject subject;
Chris@16 96 };
Chris@16 97
Chris@16 98 ///////////////////////////////////////////////////////////////////////////
Chris@16 99 // Generator generator: make_xxx function (objects)
Chris@16 100 ///////////////////////////////////////////////////////////////////////////
Chris@16 101 template <typename Expr, typename Exposed, typename Transformed
Chris@16 102 , typename Modifiers>
Chris@16 103 struct make_primitive<
Chris@16 104 tag::stateful_tag<Expr, tag::attr_cast, Exposed, Transformed>, Modifiers>
Chris@16 105 {
Chris@16 106 typedef attr_cast_generator<Exposed, Transformed, Expr> result_type;
Chris@16 107
Chris@16 108 template <typename Terminal>
Chris@16 109 result_type operator()(Terminal const& term, unused_type) const
Chris@16 110 {
Chris@16 111 typedef tag::stateful_tag<
Chris@16 112 Expr, tag::attr_cast, Exposed, Transformed> tag_type;
Chris@16 113 using spirit::detail::get_stateful_data;
Chris@16 114 return result_type(get_stateful_data<tag_type>::call(term));
Chris@16 115 }
Chris@16 116 };
Chris@16 117
Chris@16 118 }}}
Chris@16 119
Chris@16 120 #endif