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