annotate DEPENDENCIES/generic/include/boost/spirit/home/karma/action/action.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(BOOST_SPIRIT_KARMA_ACTION_MAR_07_2007_0851AM)
Chris@16 7 #define BOOST_SPIRIT_KARMA_ACTION_MAR_07_2007_0851AM
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/detail/attributes.hpp>
Chris@16 14 #include <boost/spirit/home/support/argument.hpp>
Chris@16 15 #include <boost/spirit/home/support/context.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/action_dispatch.hpp>
Chris@16 19 #include <boost/spirit/home/support/has_semantic_action.hpp>
Chris@16 20 #include <boost/spirit/home/support/handles_container.hpp>
Chris@16 21 #include <boost/spirit/home/karma/domain.hpp>
Chris@16 22 #include <boost/spirit/home/karma/meta_compiler.hpp>
Chris@16 23 #include <boost/spirit/home/karma/generator.hpp>
Chris@16 24
Chris@16 25 #include <boost/mpl/bool.hpp>
Chris@16 26 #include <boost/mpl/if.hpp>
Chris@16 27 #include <boost/type_traits/remove_const.hpp>
Chris@16 28 #include <boost/type_traits/is_same.hpp>
Chris@16 29
Chris@16 30 namespace boost { namespace spirit { namespace karma
Chris@16 31 {
Chris@16 32 ///////////////////////////////////////////////////////////////////////////
Chris@16 33 BOOST_PP_REPEAT(SPIRIT_ARGUMENTS_LIMIT, SPIRIT_USING_ARGUMENT, _)
Chris@16 34
Chris@16 35 template <typename Subject, typename Action>
Chris@16 36 struct action : unary_generator<action<Subject, Action> >
Chris@16 37 {
Chris@16 38 typedef Subject subject_type;
Chris@16 39 typedef typename subject_type::properties properties;
Chris@16 40
Chris@16 41 template <typename Context, typename Iterator>
Chris@16 42 struct attribute
Chris@16 43 : traits::attribute_of<Subject, Context, Iterator>
Chris@16 44 {};
Chris@16 45
Chris@16 46 action(Subject const& subject, Action f)
Chris@16 47 : subject(subject), f(f) {}
Chris@16 48
Chris@16 49 template <
Chris@16 50 typename OutputIterator, typename Context, typename Delimiter
Chris@16 51 , typename Attribute>
Chris@16 52 bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
Chris@16 53 , Attribute const& attr_) const
Chris@16 54 {
Chris@16 55 typedef typename attribute<Context, unused_type>::type attr_type;
Chris@16 56 typedef traits::make_attribute<attr_type, Attribute> make_attribute;
Chris@16 57
Chris@16 58 // create a attribute if none is supplied
Chris@16 59 // this creates a _copy_ of the attribute because the semantic
Chris@16 60 // action will likely change parts of this
Chris@16 61 typedef traits::transform_attribute<
Chris@16 62 typename make_attribute::type, attr_type, domain> transform;
Chris@16 63
Chris@16 64 typename transform::type attr =
Chris@16 65 traits::pre_transform<domain, attr_type>(make_attribute::call(attr_));
Chris@16 66
Chris@16 67 // call the function, passing the attribute, the context and a bool
Chris@16 68 // flag that the client can set to false to fail generating.
Chris@16 69 return traits::action_dispatch<Subject>()(f, attr, ctx) &&
Chris@16 70 subject.generate(sink, ctx, d, attr);
Chris@16 71 }
Chris@16 72
Chris@16 73 template <typename Context>
Chris@16 74 info what(Context& context) const
Chris@16 75 {
Chris@16 76 // the action is transparent (does not add any info)
Chris@16 77 return subject.what(context);
Chris@16 78 }
Chris@16 79
Chris@16 80 subject_type subject;
Chris@16 81 Action f;
Chris@16 82 };
Chris@16 83
Chris@16 84 }}}
Chris@16 85
Chris@16 86 ///////////////////////////////////////////////////////////////////////////////
Chris@16 87 namespace boost { namespace spirit
Chris@16 88 {
Chris@16 89 ///////////////////////////////////////////////////////////////////////////
Chris@16 90 // Karma action meta-compiler
Chris@16 91 template <>
Chris@16 92 struct make_component<karma::domain, tag::action>
Chris@16 93 {
Chris@16 94 template <typename Sig>
Chris@16 95 struct result;
Chris@16 96
Chris@16 97 template <typename This, typename Elements, typename Modifiers>
Chris@16 98 struct result<This(Elements, Modifiers)>
Chris@16 99 {
Chris@16 100 typedef typename
Chris@16 101 remove_const<typename Elements::car_type>::type
Chris@16 102 subject_type;
Chris@16 103
Chris@16 104 typedef typename
Chris@16 105 remove_const<typename Elements::cdr_type::car_type>::type
Chris@16 106 action_type;
Chris@16 107
Chris@16 108 typedef karma::action<subject_type, action_type> type;
Chris@16 109 };
Chris@16 110
Chris@16 111 template <typename Elements>
Chris@16 112 typename result<make_component(Elements, unused_type)>::type
Chris@16 113 operator()(Elements const& elements, unused_type) const
Chris@16 114 {
Chris@16 115 typename result<make_component(Elements, unused_type)>::type
Chris@16 116 result(elements.car, elements.cdr.car);
Chris@16 117 return result;
Chris@16 118 }
Chris@16 119 };
Chris@16 120 }}
Chris@16 121
Chris@16 122 namespace boost { namespace spirit { namespace traits
Chris@16 123 {
Chris@16 124 ///////////////////////////////////////////////////////////////////////////
Chris@16 125 template <typename Subject, typename Action>
Chris@16 126 struct has_semantic_action<karma::action<Subject, Action> >
Chris@16 127 : mpl::true_ {};
Chris@16 128
Chris@16 129 ///////////////////////////////////////////////////////////////////////////
Chris@16 130 template <typename Subject, typename Action, typename Attribute
Chris@16 131 , typename Context, typename Iterator>
Chris@16 132 struct handles_container<karma::action<Subject, Action>, Attribute
Chris@16 133 , Context, Iterator>
Chris@16 134 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
Chris@16 135 }}}
Chris@16 136
Chris@16 137 #endif