Chris@16: // Copyright (c) 2001-2011 Hartmut Kaiser Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #if !defined(SPIRIT_KARMA_ATTR_CAST_SEP_26_2009_0348PM) Chris@16: #define SPIRIT_KARMA_ATTR_CAST_SEP_26_2009_0348PM Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace spirit Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // enables attr_cast<>() pseudo generator Chris@16: template Chris@16: struct use_terminal > Chris@16: : mpl::true_ {}; Chris@16: }} Chris@16: Chris@16: namespace boost { namespace spirit { namespace karma Chris@16: { Chris@16: #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS Chris@16: using spirit::attr_cast; Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // attr_cast_generator consumes the attribute of subject generator without Chris@16: // generating anything Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: struct attr_cast_generator Chris@16: : unary_generator > Chris@16: { Chris@16: typedef typename result_of::compile::type Chris@16: subject_type; Chris@16: Chris@16: typedef mpl::int_ properties; Chris@16: Chris@16: typedef typename mpl::eval_if< Chris@16: traits::not_is_unused Chris@16: , mpl::identity Chris@16: , traits::attribute_of >::type Chris@16: transformed_attribute_type; Chris@16: Chris@16: attr_cast_generator(Subject const& subject) Chris@16: : subject(subject) Chris@16: { Chris@16: // If you got an error_invalid_expression error message here, Chris@16: // then the expression (Subject) is not a valid spirit karma Chris@16: // expression. Chris@16: BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Subject); Chris@16: } Chris@16: Chris@16: // If Exposed is given, we use the given type, otherwise all we can do Chris@16: // is to guess, so we expose our inner type as an attribute and Chris@16: // deal with the passed attribute inside the parse function. Chris@16: template Chris@16: struct attribute Chris@16: : mpl::if_, Exposed Chris@16: , transformed_attribute_type> Chris@16: {}; Chris@16: Chris@16: template Chris@16: bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d Chris@16: , Attribute const& attr) const Chris@16: { Chris@16: typedef traits::transform_attribute< Chris@16: Attribute const, transformed_attribute_type, domain> Chris@16: transform; Chris@16: Chris@16: return compile(subject).generate( Chris@16: sink, ctx, d, transform::pre(attr)); Chris@16: } Chris@16: Chris@16: template Chris@16: info what(Context& context) const Chris@16: { Chris@16: return info("attr_cast" Chris@16: , compile(subject).what(context)); Chris@16: } Chris@16: Chris@16: Subject subject; Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Generator generator: make_xxx function (objects) Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: struct make_primitive< Chris@16: tag::stateful_tag, Modifiers> Chris@16: { Chris@16: typedef attr_cast_generator result_type; Chris@16: Chris@16: template Chris@16: result_type operator()(Terminal const& term, unused_type) const Chris@16: { Chris@16: typedef tag::stateful_tag< Chris@16: Expr, tag::attr_cast, Exposed, Transformed> tag_type; Chris@16: using spirit::detail::get_stateful_data; Chris@16: return result_type(get_stateful_data::call(term)); Chris@16: } Chris@16: }; Chris@16: Chris@16: }}} Chris@16: Chris@16: #endif