File indexing completed on 2025-01-19 09:47:34
0001
0002
0003
0004
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
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
0038
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
0059
0060
0061 BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Subject);
0062 }
0063
0064
0065
0066
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
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